2019-12-10 15:03:50 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
2019-12-09 00:25:22 +08:00
|
|
|
|
|
|
|
|
|
namespace AntBlazor
|
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public partial class AntMenuItem : AntDomComponentBase
|
2019-12-09 00:25:22 +08:00
|
|
|
|
{
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment ChildContent { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public bool Disabled { get; set; } = false;
|
2019-12-09 00:25:22 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public bool Selected { get; set; } = false;
|
2019-12-09 00:25:22 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public int? PaddingLeft { get; set; }
|
2019-12-09 00:25:22 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public bool MatchRouterExact { get; set; } = false;
|
2019-12-09 00:25:22 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
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()
|
|
|
|
|
{
|
2020-05-09 11:09:07 +08:00
|
|
|
|
string prefixName = $"{Menu.PrefixCls}-item";
|
2019-12-10 15:03:50 +08:00
|
|
|
|
ClassMapper.Clear()
|
|
|
|
|
.Add(prefixName)
|
2020-04-23 17:13:56 +08:00
|
|
|
|
.If($"{prefixName}-selected", () => Selected)
|
|
|
|
|
.If($"{prefixName}-disabled", () => Disabled);
|
2019-12-09 00:25:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-10 15:03:50 +08:00
|
|
|
|
internal void SelectedChanged(bool value)
|
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
this.Selected = value;
|
2019-12-10 15:03:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-09 00:25:22 +08:00
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
base.OnInitialized();
|
2019-12-10 15:03:50 +08:00
|
|
|
|
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);
|
2019-12-10 15:03:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-09 11:09:07 +08:00
|
|
|
|
int? padding = null;
|
2020-04-23 17:13:56 +08:00
|
|
|
|
if (Menu.Mode == AntDirectionVHIType.inline)
|
2019-12-09 00:25:22 +08:00
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
if (PaddingLeft != null)
|
2019-12-09 00:25:22 +08:00
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
padding = PaddingLeft;
|
2019-12-09 00:25:22 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int level = SubMenu?.Level + 1 ?? 1;
|
2020-04-23 17:13:56 +08:00
|
|
|
|
padding = level * this.Menu.InlineIndent;
|
2019-12-09 00:25:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (padding != null)
|
|
|
|
|
{
|
|
|
|
|
Style += $"padding-left:{padding}px;";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetClassMap();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-23 17:13:56 +08:00
|
|
|
|
}
|