|
| 1 | +@namespace ShellDocs.Components.Content |
| 2 | + |
| 3 | +@{ |
| 4 | + var isLink = !string.IsNullOrEmpty(Href); |
| 5 | + var tag = isLink ? "a" : "div"; |
| 6 | +} |
| 7 | + |
| 8 | +@if (isLink) |
| 9 | +{ |
| 10 | + <a class="doc-card" href="@Href" target="@(External ? "_blank" : null)" rel="@(External ? "noopener" : null)"> |
| 11 | + @Body |
| 12 | + </a> |
| 13 | +} |
| 14 | +else |
| 15 | +{ |
| 16 | + <div class="doc-card"> |
| 17 | + @Body |
| 18 | + </div> |
| 19 | +} |
| 20 | + |
| 21 | +@code { |
| 22 | + [Parameter] public string? Title { get; set; } |
| 23 | + [Parameter] public string? Description { get; set; } |
| 24 | + [Parameter] public string? Href { get; set; } |
| 25 | + [Parameter] public string? IconSvg { get; set; } |
| 26 | + [Parameter] public bool External { get; set; } |
| 27 | + [Parameter] public RenderFragment? ChildContent { get; set; } |
| 28 | + |
| 29 | + private RenderFragment Body => __b => |
| 30 | + { |
| 31 | + if (!string.IsNullOrEmpty(IconSvg)) |
| 32 | + { |
| 33 | + __b.OpenElement(0, "span"); |
| 34 | + __b.AddAttribute(1, "class", "doc-card-icon"); |
| 35 | + __b.AddMarkupContent(2, IconSvg); |
| 36 | + __b.CloseElement(); |
| 37 | + } |
| 38 | + __b.OpenElement(3, "div"); |
| 39 | + __b.AddAttribute(4, "class", "doc-card-body"); |
| 40 | + if (!string.IsNullOrEmpty(Title)) |
| 41 | + { |
| 42 | + __b.OpenElement(5, "div"); |
| 43 | + __b.AddAttribute(6, "class", "doc-card-title"); |
| 44 | + __b.AddContent(7, Title); |
| 45 | + __b.CloseElement(); |
| 46 | + } |
| 47 | + if (!string.IsNullOrEmpty(Description)) |
| 48 | + { |
| 49 | + __b.OpenElement(8, "div"); |
| 50 | + __b.AddAttribute(9, "class", "doc-card-description"); |
| 51 | + __b.AddContent(10, Description); |
| 52 | + __b.CloseElement(); |
| 53 | + } |
| 54 | + if (ChildContent is not null) |
| 55 | + { |
| 56 | + __b.OpenElement(11, "div"); |
| 57 | + __b.AddAttribute(12, "class", "doc-card-content"); |
| 58 | + __b.AddContent(13, ChildContent); |
| 59 | + __b.CloseElement(); |
| 60 | + } |
| 61 | + __b.CloseElement(); |
| 62 | + }; |
| 63 | +} |
0 commit comments