mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-04 04:58:05 +08:00
95 lines
2.8 KiB
C#
95 lines
2.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace AntBlazor
|
|
{
|
|
public class AntMenuBase : AntDomComponentBase
|
|
{
|
|
[Parameter]
|
|
public RenderFragment ChildContent { get; set; }
|
|
|
|
[Parameter]
|
|
public int nzInlineIndent { get; set; } = 24;
|
|
|
|
[Parameter]
|
|
public string nzTheme { get; set; } = "light";//'light' | 'dark' = 'light';
|
|
|
|
[Parameter]
|
|
public NzDirectionVHIType nzMode { get; set; } = NzDirectionVHIType.vertical;
|
|
|
|
[Parameter]
|
|
public bool nzInDropDown { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public bool nzInlineCollapsed { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public bool nzSelectable { get; set; } //= !this.nzMenuService.isInDropDown;
|
|
|
|
[Parameter]
|
|
public EventCallback<AntMenuItem> nzClick { get; set; }
|
|
|
|
public IList<AntMenuItem> MenuItems = new List<AntMenuItem>();
|
|
|
|
public IList<AntSubMenu> SubMenus = new List<AntSubMenu>();
|
|
|
|
public IList<AntSubMenu> openedSubMenus = new List<AntSubMenu>();
|
|
|
|
public bool isInDropDown { get; set; }
|
|
|
|
private NzDirectionVHIType cacheMode;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
base.OnInitialized();
|
|
SetClassMap();
|
|
isInDropDown = nzInDropDown;
|
|
cacheMode = nzMode;
|
|
}
|
|
|
|
private void SetClassMap()
|
|
{
|
|
string prefixName = isInDropDown ? "ant-dropdown-menu" : "ant-menu";
|
|
ClassMapper.Add(prefixName)
|
|
.Add($"{prefixName}-root")
|
|
.Add($"{prefixName}-{nzTheme}")
|
|
.Add($"{prefixName}-{nzMode}")
|
|
.If($"{prefixName}-inline-collapsed", () => nzInlineCollapsed);
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
base.OnParametersSet();
|
|
await updateInLineCollapse();
|
|
}
|
|
|
|
private async Task updateInLineCollapse()
|
|
{
|
|
if (MenuItems.Any())
|
|
{
|
|
if (nzInlineCollapsed)
|
|
{
|
|
openedSubMenus = this.SubMenus.Where(x => x.nzOpen).ToList();
|
|
foreach (var antSubMenu in this.SubMenus)
|
|
{
|
|
await antSubMenu.SetOpenState(false);
|
|
}
|
|
|
|
this.nzMode = NzDirectionVHIType.vertical;
|
|
}
|
|
else
|
|
{
|
|
foreach (var subMenu in openedSubMenus)
|
|
{
|
|
await subMenu.SetOpenState(false);
|
|
}
|
|
openedSubMenus.Clear();
|
|
this.nzMode = this.cacheMode;
|
|
}
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
}
|
|
} |