2020-07-07 22:45:13 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
2020-04-23 17:13:56 +08:00
|
|
|
|
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]
|
2020-07-02 23:20:16 +08:00
|
|
|
|
public bool Loading
|
|
|
|
|
{
|
|
|
|
|
get => _loading;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_loading != value)
|
|
|
|
|
{
|
|
|
|
|
_loading = value;
|
|
|
|
|
UpdateIconDisplay(_loading);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-23 17:13:56 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-05-29 12:55:15 +08:00
|
|
|
|
public string Type { get; set; } = ButtonType.Default;
|
2020-04-23 17:13:56 +08:00
|
|
|
|
|
2020-06-01 14:09:28 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string HtmlType { get; set; } = "button";
|
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string Shape { get; set; } = null;
|
|
|
|
|
|
2020-07-07 22:45:13 +08:00
|
|
|
|
private bool _animating = false;
|
|
|
|
|
|
|
|
|
|
private string _btnWave = "--antd-wave-shadow-color: rgb(255, 120, 117);";
|
|
|
|
|
|
2020-06-07 00:47:18 +08:00
|
|
|
|
private string _formSize;
|
2020-07-02 23:20:16 +08:00
|
|
|
|
|
2020-06-07 00:47:18 +08:00
|
|
|
|
[CascadingParameter(Name = "FormSize")]
|
|
|
|
|
public string FormSize
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _formSize;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_formSize = value;
|
|
|
|
|
|
|
|
|
|
Size = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[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; }
|
|
|
|
|
|
2020-06-07 19:41:00 +08:00
|
|
|
|
public IList<Icon> Icons { get; set; } = new List<Icon>();
|
2020-04-23 17:13:56 +08:00
|
|
|
|
|
|
|
|
|
protected string IconStyle { get; set; }
|
|
|
|
|
|
2020-07-02 23:20:16 +08:00
|
|
|
|
private bool _loading = false;
|
2020-04-23 17:13:56 +08:00
|
|
|
|
|
|
|
|
|
protected void SetClassMap()
|
|
|
|
|
{
|
|
|
|
|
string prefixName = "ant-btn";
|
|
|
|
|
|
|
|
|
|
ClassMapper.Clear()
|
|
|
|
|
.Add("ant-btn")
|
|
|
|
|
.If($"{prefixName}-{this.Type}", () => !string.IsNullOrEmpty(Type))
|
2020-06-07 00:47:18 +08:00
|
|
|
|
.If($"{prefixName}-dangerous", () => Danger)
|
2020-04-23 17:13:56 +08:00
|
|
|
|
.If($"{prefixName}-{Shape}", () => !string.IsNullOrEmpty(Shape))
|
2020-07-02 23:20:16 +08:00
|
|
|
|
.If($"{prefixName}-lg", () => Size == "large")
|
|
|
|
|
.If($"{prefixName}-sm", () => Size == "small")
|
2020-04-23 17:13:56 +08:00
|
|
|
|
.If($"{prefixName}-loading", () => Loading)
|
2020-07-02 23:20:16 +08:00
|
|
|
|
.If($"{prefixName}-icon-only", () => !string.IsNullOrEmpty(this.Icon) && !this.Search && this.ChildContent == null)
|
2020-04-23 17:13:56 +08:00
|
|
|
|
.If($"{prefixName}-background-ghost", () => Ghost)
|
|
|
|
|
.If($"{prefixName}-block", () => this.Block)
|
|
|
|
|
.If($"ant-input-search-button", () => this.Search)
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
SetClassMap();
|
2020-07-02 23:20:16 +08:00
|
|
|
|
UpdateIconDisplay(_loading);
|
2020-04-23 17:13:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-02 23:20:16 +08:00
|
|
|
|
private void UpdateIconDisplay(bool loading)
|
2020-04-23 17:13:56 +08:00
|
|
|
|
{
|
2020-07-02 23:20:16 +08:00
|
|
|
|
IconStyle = $"display:{(loading ? "none" : "inline-block")}";
|
2020-04-23 17:13:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-02 23:20:16 +08:00
|
|
|
|
private 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
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-07 22:45:13 +08:00
|
|
|
|
|
|
|
|
|
private async Task OnMouseUp(MouseEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Button != 0 || this.Type == ButtonType.Link) return; //remove animating from Link Button
|
|
|
|
|
this._animating = true;
|
|
|
|
|
|
|
|
|
|
await Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(500);
|
|
|
|
|
this._animating = false;
|
|
|
|
|
|
|
|
|
|
InvokeAsync(StateHasChanged);
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-04-23 17:13:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|