ant-design-blazor/components/menu/AntMenuItem.razor.cs

81 lines
2.0 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 partial class AntMenuItem : AntDomComponentBase
2019-12-09 00:25:22 +08:00
{
[Parameter]
public RenderFragment ChildContent { get; set; }
[Parameter]
public bool Disabled { get; set; } = false;
2019-12-09 00:25:22 +08:00
[Parameter]
public bool Selected { get; set; } = false;
2019-12-09 00:25:22 +08:00
[Parameter]
public int? PaddingLeft { get; set; }
2019-12-09 00:25:22 +08:00
[Parameter]
public bool MatchRouterExact { get; set; } = false;
2019-12-09 00:25:22 +08:00
[Parameter]
public bool MatchRouter { get; set; } = false;
2019-12-09 00:25:22 +08:00
[CascadingParameter]
public AntMenu Menu { get; set; }
[CascadingParameter]
public AntSubMenu SubMenu { get; set; }
2020-04-24 18:32:50 +08:00
private readonly int _originalPadding = 0;
2019-12-09 00:25:22 +08:00
private void SetClassMap()
{
string prefixName = $"{Menu.PrefixCls}-item";
ClassMapper.Clear()
.Add(prefixName)
.If($"{prefixName}-selected", () => Selected)
.If($"{prefixName}-disabled", () => Disabled);
2019-12-09 00:25:22 +08:00
}
internal void SelectedChanged(bool value)
{
this.Selected = value;
}
2019-12-09 00:25:22 +08:00
protected override void OnInitialized()
{
base.OnInitialized();
if (this is AntMenuItem item)
{
2020-04-24 18:32:50 +08:00
Menu?.MenuItems.Add(item);
2019-12-12 00:14:13 +08:00
SubMenu?.Items.Add(item);
}
int? padding = null;
if (Menu.Mode == AntDirectionVHIType.inline)
2019-12-09 00:25:22 +08:00
{
if (PaddingLeft != null)
2019-12-09 00:25:22 +08:00
{
padding = PaddingLeft;
2019-12-09 00:25:22 +08:00
}
else
{
int level = SubMenu?.Level + 1 ?? 1;
padding = level * this.Menu.InlineIndent;
2019-12-09 00:25:22 +08:00
}
}
if (padding != null)
{
Style += $"padding-left:{padding}px;";
}
SetClassMap();
}
}
}