| | 1 | | @inject NavigationManager navManager; |
| | 2 | |
|
| | 3 | | <div class="menu-item @((Children.Any()) ? "has-sub" : null) @((IsExpanded) ? "active" : null)"> |
| | 4 | |
|
| 0 | 5 | | <a class="menu-link" style="cursor: pointer;" @onclick="() => NavigateOrExpand()"> |
| 0 | 6 | | @if (!string.IsNullOrEmpty(this.IconName)) |
| 0 | 7 | | { |
| | 8 | | <div class="menu-icon"> |
| | 9 | | <i class="oi @IconName"></i> |
| | 10 | | </div> |
| 0 | 11 | | } |
| | 12 | |
|
| | 13 | | <div class="menu-text"> |
| 0 | 14 | | @Title |
| 0 | 15 | | @if (!string.IsNullOrEmpty(Badge)) |
| 0 | 16 | | { |
| 0 | 17 | | <span class="menu-label">@Badge</span> |
| 0 | 18 | | } |
| | 19 | | </div> |
| 0 | 20 | | @if (Children.Any()) |
| 0 | 21 | | { |
| | 22 | | <div class="menu-caret"></div> |
| 0 | 23 | | } |
| | 24 | | </a> |
| | 25 | | <div class="menu-submenu"> |
| | 26 | | <CascadingValue Value="this"> |
| 0 | 27 | | @ChildContent |
| | 28 | | </CascadingValue> |
| | 29 | | </div> |
| | 30 | |
|
| | 31 | | </div> |
| | 32 | |
|
| | 33 | |
|
| | 34 | |
|
| | 35 | | @code { |
| 0 | 36 | | [Parameter] public RenderFragment ChildContent { get; set; } |
| | 37 | |
|
| 0 | 38 | | [CascadingParameter] public MenuItem Parent { get; set; } |
| | 39 | |
|
| 0 | 40 | | [Parameter] public string Title { get; set; } |
| | 41 | |
|
| 0 | 42 | | [Parameter] public string Url { get; set; } |
| | 43 | |
|
| 0 | 44 | | [Parameter] public string IconName { get; set; } |
| | 45 | |
|
| 0 | 46 | | [Parameter] public string Badge{ get; set; } |
| | 47 | |
|
| 0 | 48 | | public bool IsExpanded { get; set; } |
| | 49 | |
|
| 0 | 50 | | private List<MenuItem> Children { get; set; } = new(); |
| | 51 | |
|
| | 52 | | private void NavigateOrExpand() |
| 0 | 53 | | { |
| 0 | 54 | | if (Children.Any()) |
| 0 | 55 | | { |
| 0 | 56 | | IsExpanded = !IsExpanded; |
| 0 | 57 | | } |
| | 58 | | else |
| 0 | 59 | | { |
| 0 | 60 | | navManager.NavigateTo(Url); |
| 0 | 61 | | } |
| 0 | 62 | | } |
| | 63 | |
|
| | 64 | | public void AddSubItem(MenuItem item) |
| 0 | 65 | | { |
| 0 | 66 | | if (!Children.Contains(item)) |
| 0 | 67 | | { |
| 0 | 68 | | Children.Add(item); |
| 0 | 69 | | this.StateHasChanged(); |
| 0 | 70 | | } |
| 0 | 71 | | } |
| | 72 | |
|
| | 73 | | protected override void OnInitialized() |
| 0 | 74 | | { |
| | 75 | |
|
| 0 | 76 | | if (Parent != null) |
| 0 | 77 | | Parent.AddSubItem(this); |
| 0 | 78 | | } |
| | 79 | | } |