Latest
This commit is contained in:
42
Prefab.Web.Client/Components/Catalog/ProductDocs.razor
Normal file
42
Prefab.Web.Client/Components/Catalog/ProductDocs.razor
Normal file
@@ -0,0 +1,42 @@
|
||||
@using System.Text.Json
|
||||
|
||||
@if (_documents.Count > 0)
|
||||
{
|
||||
<div class="product-docs mt-4">
|
||||
<h5 class="mb-3">Documents</h5>
|
||||
<ul class="list-unstyled mb-0">
|
||||
@foreach (var doc in _documents)
|
||||
{
|
||||
<li class="mb-2">
|
||||
<a href="@doc.Url" target="_blank" rel="noopener noreferrer">@doc.Title</a>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string Json { get; set; } = "[]";
|
||||
|
||||
private static readonly JsonSerializerOptions SerializerOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
private List<DocumentLink> _documents { get; set; } = new();
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
try
|
||||
{
|
||||
_documents = JsonSerializer.Deserialize<List<DocumentLink>>(Json, SerializerOptions) ?? new List<DocumentLink>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
_documents = new List<DocumentLink>();
|
||||
}
|
||||
}
|
||||
|
||||
private sealed record DocumentLink(string Title, string Url);
|
||||
}
|
||||
Reference in New Issue
Block a user