2021-06-09 17:51:24 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Text.Json;
|
2021-06-02 10:46:58 +08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using AntDesign.JsInterop;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
2020-05-09 11:09:07 +08:00
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2020-05-09 11:09:07 +08:00
|
|
|
|
{
|
2020-05-18 14:46:42 +08:00
|
|
|
|
public class DropdownButton : Dropdown
|
2020-05-09 11:09:07 +08:00
|
|
|
|
{
|
2021-06-02 10:46:58 +08:00
|
|
|
|
/// <summary>
|
2021-06-09 17:51:24 +08:00
|
|
|
|
/// Option to fit button width to its parent width
|
2021-06-02 10:46:58 +08:00
|
|
|
|
/// </summary>
|
2021-06-09 17:51:24 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public new bool Block
|
2021-06-02 10:46:58 +08:00
|
|
|
|
{
|
2021-06-09 17:51:24 +08:00
|
|
|
|
get => base.Block;
|
|
|
|
|
set => base.Block = value;
|
2021-06-02 10:46:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 17:51:24 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fully customizable button.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public new Func<RenderFragment, RenderFragment, RenderFragment> ButtonsRender
|
2021-06-02 10:46:58 +08:00
|
|
|
|
{
|
2021-06-09 17:51:24 +08:00
|
|
|
|
get => base.ButtonsRender;
|
|
|
|
|
set => base.ButtonsRender = value;
|
2021-06-02 10:46:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 17:51:24 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Set the danger status of button
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Danger
|
2021-06-02 10:46:58 +08:00
|
|
|
|
{
|
2021-06-09 17:51:24 +08:00
|
|
|
|
get => _danger;
|
|
|
|
|
set
|
2021-06-02 10:46:58 +08:00
|
|
|
|
{
|
2021-06-09 17:51:24 +08:00
|
|
|
|
_danger = value;
|
|
|
|
|
ChangeButtonDanger(value);
|
2021-06-02 10:46:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 17:51:24 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used in situations with complex background, home pages usually.
|
|
|
|
|
/// </summary>
|
2020-05-09 11:09:07 +08:00
|
|
|
|
[Parameter]
|
2021-06-09 17:51:24 +08:00
|
|
|
|
public bool Ghost
|
2020-05-09 11:09:07 +08:00
|
|
|
|
{
|
2021-06-09 17:51:24 +08:00
|
|
|
|
get => _ghost;
|
2021-06-02 10:46:58 +08:00
|
|
|
|
set
|
2020-05-09 11:09:07 +08:00
|
|
|
|
{
|
2021-06-09 17:51:24 +08:00
|
|
|
|
_ghost = value;
|
|
|
|
|
ChangeButtonGhost(value);
|
2020-05-09 11:09:07 +08:00
|
|
|
|
}
|
2021-06-02 10:46:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string _icon = "ellipsis";
|
2021-06-09 17:51:24 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Icon that will be rendered in the right
|
|
|
|
|
/// button.
|
|
|
|
|
/// </summary>
|
2021-06-02 10:46:58 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string Icon
|
|
|
|
|
{
|
|
|
|
|
get => _icon;
|
2020-05-09 11:09:07 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2021-06-09 17:51:24 +08:00
|
|
|
|
_icon = value;
|
|
|
|
|
ChangeRightButtonIcon(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates if loading icon is going to be included.
|
|
|
|
|
/// If set to true, then dropdown will not be active.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Loading
|
|
|
|
|
{
|
|
|
|
|
get => _loading;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_loading = value;
|
|
|
|
|
ChangeButtonLoading(value);
|
2020-05-09 11:09:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string _size = AntSizeLDSType.Default;
|
2021-06-09 17:51:24 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Button size.
|
|
|
|
|
/// </summary>
|
2020-05-09 11:09:07 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string Size
|
|
|
|
|
{
|
2021-06-02 10:46:58 +08:00
|
|
|
|
get => _size;
|
2020-05-09 11:09:07 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_size = value;
|
|
|
|
|
ChangeButtonSize(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 17:51:24 +08:00
|
|
|
|
private (string LeftButton, string RightButton) _type = (ButtonType.Default, ButtonType.Default);
|
2021-06-02 10:46:58 +08:00
|
|
|
|
private bool _loading;
|
2021-06-09 17:51:24 +08:00
|
|
|
|
private bool _danger;
|
|
|
|
|
private bool _ghost = false;
|
2021-06-02 10:46:58 +08:00
|
|
|
|
|
2021-06-09 17:51:24 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Button type is a tuple where first item refers to LeftButton type
|
|
|
|
|
/// and second item refers to RightButton type.
|
|
|
|
|
/// </summary>
|
2020-05-09 11:09:07 +08:00
|
|
|
|
[Parameter]
|
2021-06-09 17:51:24 +08:00
|
|
|
|
public (string LeftButton, string RightButton) Type
|
2020-05-09 11:09:07 +08:00
|
|
|
|
{
|
2021-06-02 10:46:58 +08:00
|
|
|
|
get => _type;
|
2020-05-09 11:09:07 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_type = value;
|
|
|
|
|
ChangeButtonType(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-02 10:46:58 +08:00
|
|
|
|
public DropdownButton() => IsButton = true;
|
2021-06-09 17:51:24 +08:00
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
string prefixCls = "ant-btn";
|
|
|
|
|
ClassMapper.Clear();
|
|
|
|
|
Placement = PlacementType.BottomRight;
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
ClassMapper.If($"{prefixCls}-block", () => Block);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Force overlay trigger to be attached to wrapping element of
|
|
|
|
|
/// the right button. Right button has to be wrapped,
|
|
|
|
|
/// because overlay will be looking for first child
|
|
|
|
|
/// element of the overlay trigger to calculate the overlay position.
|
|
|
|
|
/// If the right button was the trigger, then its first child
|
|
|
|
|
/// would be the icon/ellipsis and the overlay would have been
|
|
|
|
|
/// rendered too high.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="firstRender"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected override Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
{
|
|
|
|
|
if (firstRender)
|
|
|
|
|
{
|
|
|
|
|
Ref = RefBack.Current;
|
|
|
|
|
DomEventService.AddEventListener(Ref, "click", OnUnboundClick, true);
|
|
|
|
|
DomEventService.AddEventListener(Ref, "mouseover", OnUnboundMouseEnter, true);
|
|
|
|
|
DomEventService.AddEventListener(Ref, "mouseout", OnUnboundMouseLeave, true);
|
|
|
|
|
DomEventService.AddEventListener(Ref, "focusin", OnUnboundFocusIn, true);
|
|
|
|
|
DomEventService.AddEventListener(Ref, "focusout", OnUnboundFocusOut, true);
|
|
|
|
|
DomEventService.AddEventListener(Ref, "contextmenu", OnContextMenu, true, true);
|
|
|
|
|
}
|
|
|
|
|
return base.OnAfterRenderAsync(firstRender);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
DomEventService.RemoveEventListerner<JsonElement>(Ref, "click", OnUnboundClick);
|
|
|
|
|
DomEventService.RemoveEventListerner<JsonElement>(Ref, "mouseover", OnUnboundMouseEnter);
|
|
|
|
|
DomEventService.RemoveEventListerner<JsonElement>(Ref, "mouseout", OnUnboundMouseLeave);
|
|
|
|
|
DomEventService.RemoveEventListerner<JsonElement>(Ref, "focusin", OnUnboundFocusIn);
|
|
|
|
|
DomEventService.RemoveEventListerner<JsonElement>(Ref, "focusout", OnUnboundFocusOut);
|
|
|
|
|
DomEventService.RemoveEventListerner<JsonElement>(Ref, "contextmenu", OnContextMenu);
|
|
|
|
|
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal override async Task Show(int? overlayLeft = null, int? overlayTop = null)
|
|
|
|
|
{
|
|
|
|
|
if (!Loading)
|
|
|
|
|
{
|
|
|
|
|
await _overlay.Show(overlayLeft, overlayTop);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-09 11:09:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|