ant-design-blazor/components/menu/AntMenuItemBase.cs

88 lines
2.2 KiB
C#
Raw Normal View History

using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
2019-12-09 00:25:22 +08:00
namespace AntBlazor
{
public class AntMenuItemBase : AntDomComponentBase
{
[Parameter]
public RenderFragment ChildContent { get; set; }
[Parameter]
public bool nzDisabled { get; set; } = false;
[Parameter]
public bool nzSelected { get; set; } = false;
[Parameter]
public int? nzPaddingLeft { get; set; }
[Parameter]
public bool nzMatchRouterExact { get; set; } = false;
[Parameter]
public bool nzMatchRouter { get; set; } = false;
[CascadingParameter]
public AntMenu Menu { get; set; }
[CascadingParameter]
public AntSubMenu SubMenu { get; set; }
private int originalPadding;
private void SetClassMap()
{
string prefixName = Menu.isInDropDown ? "ant-dropdown-menu-item" : "ant-menu-item";
ClassMapper.Clear()
.Add(prefixName)
2019-12-09 00:25:22 +08:00
.If($"{prefixName}-selected", () => nzSelected)
.If($"{prefixName}-disabled", () => nzDisabled);
}
internal void SelectedChanged(bool value)
{
this.nzSelected = value;
}
2019-12-09 00:25:22 +08:00
protected override void OnInitialized()
{
base.OnInitialized();
if (this is AntMenuItem item)
{
2019-12-12 00:14:13 +08:00
Menu?.MenuItems.Add(item);
SubMenu?.Items.Add(item);
}
if (Attributes?.TryGetValue("style", out var style) == true)
{
}
2019-12-09 00:25:22 +08:00
int? padding = null;
if (Menu.nzMode == NzDirectionVHIType.inline)
{
if (nzPaddingLeft != null)
{
padding = nzPaddingLeft;
}
else
{
int level = SubMenu?.Level + 1 ?? 1;
padding = level * this.Menu.nzInlineIndent;
}
}
else
{
padding = originalPadding;
}
if (padding != null)
{
Style += $"padding-left:{padding}px;";
}
SetClassMap();
}
}
}