2020-05-18 14:46:42 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-05-29 00:33:49 +08:00
|
|
|
|
using AntDesign.Internal;
|
2020-05-18 14:46:42 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
|
|
|
using OneOf;
|
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2020-05-18 14:46:42 +08:00
|
|
|
|
{
|
|
|
|
|
public partial class SubMenu : AntDomComponentBase
|
|
|
|
|
{
|
|
|
|
|
[CascadingParameter]
|
|
|
|
|
public Menu RootMenu { get; set; }
|
|
|
|
|
|
|
|
|
|
[CascadingParameter]
|
|
|
|
|
public SubMenu Parent { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public OneOf<string, RenderFragment> Title { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment ChildContent { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Key
|
|
|
|
|
{
|
|
|
|
|
get => _key ?? Id;
|
|
|
|
|
set => _key = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Disabled { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool IsOpen { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<MouseEventArgs> OnTitleClicked { get; set; }
|
|
|
|
|
|
|
|
|
|
private ClassMapper SubMenuMapper { get; } = new ClassMapper();
|
|
|
|
|
|
2020-05-19 20:35:48 +08:00
|
|
|
|
private bool _isSelected;
|
|
|
|
|
|
2020-05-18 14:46:42 +08:00
|
|
|
|
private string _key;
|
|
|
|
|
|
2020-05-19 20:35:48 +08:00
|
|
|
|
private string _popupMinWidthStyle = "";
|
2020-05-18 14:46:42 +08:00
|
|
|
|
private OverlayTrigger _overlayTrigger;
|
|
|
|
|
|
|
|
|
|
private void SetClass()
|
|
|
|
|
{
|
|
|
|
|
string prefixCls = $"{RootMenu.PrefixCls}-submenu";
|
|
|
|
|
|
|
|
|
|
ClassMapper
|
|
|
|
|
.Clear()
|
|
|
|
|
.Add(prefixCls)
|
2020-06-03 23:11:02 +08:00
|
|
|
|
.Add($"{prefixCls}-{RootMenu?.InternalMode}")
|
2020-05-18 14:46:42 +08:00
|
|
|
|
.If($"{prefixCls}-disabled", () => Disabled)
|
2020-05-19 20:35:48 +08:00
|
|
|
|
.If($"{prefixCls}-selected", () => _isSelected)
|
2020-06-03 23:11:02 +08:00
|
|
|
|
.If($"{prefixCls}-open", () => RootMenu?.InternalMode == MenuMode.Inline && IsOpen)
|
2020-05-18 14:46:42 +08:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
SubMenuMapper
|
|
|
|
|
.Clear()
|
2020-05-19 20:35:48 +08:00
|
|
|
|
.Add(RootMenu.PrefixCls)
|
|
|
|
|
.Add($"{RootMenu.PrefixCls}-sub")
|
|
|
|
|
.Add($"{RootMenu.PrefixCls}-{RootMenu.Theme}")
|
|
|
|
|
.Add($"{RootMenu.PrefixCls}-{(RootMenu.InternalMode == MenuMode.Horizontal ? MenuMode.Vertical : RootMenu.InternalMode)}")
|
|
|
|
|
//.If($"{RootMenu.PrefixCls}-submenu-popup", () => RootMenu.InternalMode != MenuMode.Inline)
|
|
|
|
|
.If($"{RootMenu.PrefixCls}-hidden", () => RootMenu.InternalMode == MenuMode.Inline && !IsOpen)
|
2020-05-18 14:46:42 +08:00
|
|
|
|
;
|
|
|
|
|
|
2020-05-19 20:35:48 +08:00
|
|
|
|
if (RootMenu.InternalMode != MenuMode.Inline && _overlayTrigger != null)
|
2020-05-18 14:46:42 +08:00
|
|
|
|
{
|
|
|
|
|
Overlay overlay = _overlayTrigger.GetOverlayComponent();
|
|
|
|
|
|
2020-05-19 20:35:48 +08:00
|
|
|
|
ClassMapper
|
|
|
|
|
.If($"{prefixCls}-selected", () => overlay.IsPopup());
|
|
|
|
|
|
2020-05-18 14:46:42 +08:00
|
|
|
|
SubMenuMapper
|
2020-05-19 20:35:48 +08:00
|
|
|
|
.If($"{RootMenu.PrefixCls}-hidden", () => overlay.IsHiding() == false && overlay.IsPopup() == false)
|
|
|
|
|
.If($"zoom-big zoom-big-enter zoom-big-enter-active", () => RootMenu.Mode == MenuMode.Vertical && overlay.IsPopup() && !overlay.IsHiding())
|
|
|
|
|
.If($"zoom-big zoom-big-leave zoom-big-leave-active", () => RootMenu.Mode == MenuMode.Vertical && overlay.IsHiding())
|
|
|
|
|
.If($"slide-up slide-up-enter slide-up-enter-active", () => RootMenu.Mode == MenuMode.Horizontal && overlay.IsPopup() && !overlay.IsHiding())
|
|
|
|
|
.If($"slide-up slide-up-leave slide-up-leave-active", () => RootMenu.Mode == MenuMode.Horizontal && overlay.IsHiding())
|
|
|
|
|
;
|
2020-05-18 14:46:42 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task HandleOnTitleClick(MouseEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
RootMenu.SelectSubmenu(this);
|
|
|
|
|
if (OnTitleClicked.HasDelegate)
|
|
|
|
|
await OnTitleClicked.InvokeAsync(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Collapse()
|
|
|
|
|
{
|
2020-05-19 20:35:48 +08:00
|
|
|
|
if (RootMenu.InternalMode == MenuMode.Inline)
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(300);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await _overlayTrigger.Hide(true);
|
|
|
|
|
}
|
2020-05-18 14:46:42 +08:00
|
|
|
|
IsOpen = false;
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
SetClass();
|
|
|
|
|
|
|
|
|
|
RootMenu.Submenus.Add(this);
|
|
|
|
|
|
|
|
|
|
if (RootMenu.DefaultOpenKeys.Contains(Key))
|
|
|
|
|
IsOpen = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
|
|
|
|
base.OnParametersSet();
|
|
|
|
|
SetClass();
|
|
|
|
|
|
|
|
|
|
if (RootMenu.OpenKeys.Contains(Key))
|
|
|
|
|
IsOpen = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-19 20:35:48 +08:00
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
{
|
|
|
|
|
if (RootMenu.InternalMode != MenuMode.Inline && _overlayTrigger != null)
|
|
|
|
|
{
|
|
|
|
|
var domInfo = await _overlayTrigger.GetTriggerDomInfo();
|
|
|
|
|
_popupMinWidthStyle = $"min-width: {domInfo.clientWidth}px";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await base.OnAfterRenderAsync(firstRender);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-18 14:46:42 +08:00
|
|
|
|
public void Close()
|
|
|
|
|
{
|
|
|
|
|
IsOpen = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Open()
|
|
|
|
|
{
|
|
|
|
|
if (Disabled)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IsOpen = true;
|
|
|
|
|
if (Parent != null)
|
|
|
|
|
{
|
|
|
|
|
Parent.Open();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OverlayTrigger GetOverlayTrigger()
|
|
|
|
|
{
|
|
|
|
|
return _overlayTrigger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnOverlayVisibleChange(bool visible)
|
|
|
|
|
{
|
|
|
|
|
if (visible)
|
|
|
|
|
{
|
|
|
|
|
SetClass();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnOverlayHiding(bool hiding)
|
|
|
|
|
{
|
|
|
|
|
SetClass();
|
|
|
|
|
}
|
2020-05-19 20:35:48 +08:00
|
|
|
|
|
|
|
|
|
public void Select()
|
|
|
|
|
{
|
|
|
|
|
Parent?.Select();
|
|
|
|
|
_isSelected = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Deselect()
|
|
|
|
|
{
|
|
|
|
|
Parent?.Deselect();
|
|
|
|
|
_isSelected = false;
|
|
|
|
|
}
|
2020-05-18 14:46:42 +08:00
|
|
|
|
}
|
|
|
|
|
}
|