2020-04-23 17:13:56 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2020-04-23 17:13:56 +08:00
|
|
|
|
{
|
2020-05-29 12:55:15 +08:00
|
|
|
|
public partial class Button : AntDomComponentBase
|
2020-04-23 17:13:56 +08:00
|
|
|
|
{
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Block { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Ghost { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Search { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Loading { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-05-29 12:55:15 +08:00
|
|
|
|
public string Type { get; set; } = ButtonType.Default;
|
2020-04-23 17:13:56 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Shape { get; set; } = null;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Size { get; set; } = AntSizeLDSType.Default;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Icon { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Disabled { get; set; }
|
|
|
|
|
|
2020-05-10 15:42:02 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Danger { get; set; }
|
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment ChildContent { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-05-18 14:46:42 +08:00
|
|
|
|
public EventCallback<MouseEventArgs> OnClick { get; set; }
|
2020-04-23 17:13:56 +08:00
|
|
|
|
|
|
|
|
|
[Inject] private NavigationManager NavigationManger { get; set; }
|
|
|
|
|
|
|
|
|
|
public IList<AntIcon> Icons { get; set; } = new List<AntIcon>();
|
|
|
|
|
|
2020-05-10 15:42:02 +08:00
|
|
|
|
//public AntNavLink Link { get; set; }
|
2020-04-23 17:13:56 +08:00
|
|
|
|
|
|
|
|
|
protected string IconStyle { get; set; }
|
|
|
|
|
|
|
|
|
|
private readonly bool _isInDropdown = false;
|
|
|
|
|
|
|
|
|
|
protected void SetClassMap()
|
|
|
|
|
{
|
|
|
|
|
string prefixName = "ant-btn";
|
|
|
|
|
Hashtable sizeMap = new Hashtable()
|
|
|
|
|
{
|
|
|
|
|
["large"] = "lg",
|
|
|
|
|
["small"] = "sm"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ClassMapper.Clear()
|
|
|
|
|
.Add("ant-btn")
|
|
|
|
|
.If($"{prefixName}-{this.Type}", () => !string.IsNullOrEmpty(Type))
|
2020-05-20 17:06:15 +08:00
|
|
|
|
.If($"{prefixName}-dangerous", () => Danger)
|
2020-04-23 17:13:56 +08:00
|
|
|
|
.If($"{prefixName}-{Shape}", () => !string.IsNullOrEmpty(Shape))
|
|
|
|
|
.If($"{prefixName}-{sizeMap[this.Size]}", () => sizeMap.ContainsKey(Size))
|
|
|
|
|
.If($"{prefixName}-loading", () => Loading)
|
|
|
|
|
.If($"{prefixName}-icon-only", () => Icons.Count == 0 && !this.Search && !this._isInDropdown && this.ChildContent == null)
|
|
|
|
|
.If($"{prefixName}-background-ghost", () => Ghost)
|
|
|
|
|
.If($"{prefixName}-block", () => this.Block)
|
|
|
|
|
.If($"ant-input-search-button", () => this.Search)
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
base.OnInitialized();
|
2020-05-10 15:42:02 +08:00
|
|
|
|
//if (Link != null && string.IsNullOrEmpty(this.Type))
|
|
|
|
|
//{
|
2020-05-29 12:55:15 +08:00
|
|
|
|
// this.Type = ButtonType.Link;
|
2020-05-10 15:42:02 +08:00
|
|
|
|
//}
|
2020-04-23 17:13:56 +08:00
|
|
|
|
SetClassMap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
|
|
|
|
base.OnParametersSet();
|
|
|
|
|
SetClassMap();
|
|
|
|
|
UpdateIconDisplay(this.Loading);
|
|
|
|
|
if (Type == "link")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateIconDisplay(bool vlaue)
|
|
|
|
|
{
|
|
|
|
|
IconStyle = $"display:{(vlaue ? "none" : "inline-block")}";
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-18 14:46:42 +08:00
|
|
|
|
protected async Task HandleOnClick(MouseEventArgs args)
|
2020-04-23 17:13:56 +08:00
|
|
|
|
{
|
2020-05-18 14:46:42 +08:00
|
|
|
|
if (OnClick.HasDelegate)
|
2020-04-23 17:13:56 +08:00
|
|
|
|
{
|
2020-05-18 14:46:42 +08:00
|
|
|
|
await OnClick.InvokeAsync(args);
|
2020-04-23 17:13:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|