| | | 1 | | @* Renders an icon - handles Font Awesome classes, emojis, or falls back to default *@ |
| | | 2 | | |
| | 28 | 3 | | @if (IsEmoji(Icon)) |
| | | 4 | | { |
| | 20 | 5 | | <span class="@CssClass" style="@Style">@Icon</span> |
| | | 6 | | } |
| | 8 | 7 | | else if (IsFontAwesome(Icon)) |
| | | 8 | | { |
| | | 9 | | <i class="@Icon @CssClass" style="@Style"></i> |
| | | 10 | | } |
| | 4 | 11 | | else if (!string.IsNullOrEmpty(DefaultIcon)) |
| | | 12 | | { |
| | 4 | 13 | | @if (IsFontAwesome(DefaultIcon)) |
| | | 14 | | { |
| | | 15 | | <i class="@DefaultIcon @CssClass" style="@Style"></i> |
| | | 16 | | } |
| | | 17 | | else |
| | | 18 | | { |
| | 3 | 19 | | <span class="@CssClass" style="@Style">@DefaultIcon</span> |
| | | 20 | | } |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | @code { |
| | | 24 | | /// <summary> |
| | | 25 | | /// The icon to render (Font Awesome class like "fa-solid fa-dragon" or emoji like "🐉") |
| | | 26 | | /// </summary> |
| | | 27 | | [Parameter] |
| | 88 | 28 | | public string? Icon { get; set; } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Fallback icon if Icon is null or empty |
| | | 32 | | /// </summary> |
| | | 33 | | [Parameter] |
| | 57 | 34 | | public string? DefaultIcon { get; set; } = "👤"; |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Additional CSS classes |
| | | 38 | | /// </summary> |
| | | 39 | | [Parameter] |
| | 30 | 40 | | public string? CssClass { get; set; } |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Inline styles |
| | | 44 | | /// </summary> |
| | | 45 | | [Parameter] |
| | 29 | 46 | | public string? Style { get; set; } |
| | | 47 | | |
| | | 48 | | private bool IsEmoji(string? value) |
| | | 49 | | { |
| | 32 | 50 | | if (string.IsNullOrEmpty(value)) return false; |
| | | 51 | | // Emojis don't start with "fa-" |
| | 24 | 52 | | return !value.StartsWith("fa-"); |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | private bool IsFontAwesome(string? value) |
| | | 56 | | { |
| | 16 | 57 | | if (string.IsNullOrEmpty(value)) return false; |
| | 8 | 58 | | return value.StartsWith("fa-"); |
| | | 59 | | } |
| | | 60 | | } |