mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-02 20:17:58 +08:00
9351a35072
* docs: add cli for building demo structured file * docs: cli improvement * docs: generate demo page * fix: style of components page * docs: add prism to mack source code highlight * feat: add menu2json command for cli * fix: markdown highlight * feat: fetch menu data from cli output files * fix: cli * docs: add avatar demo * docs: add button demos * docs: add component-scope style * docs: fix style * docs: add badge demos * fix: rebase conflict * docs: refactor layout * docs: fix navigation * docs: fix rebase conflict * docs: add AntAffix for sider menu * docs: fix affix error * docs: fix rebase confilct
119 lines
3.4 KiB
C#
119 lines
3.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
|
|
namespace AntBlazor
|
|
{
|
|
public partial class AntButton : AntDomComponentBase
|
|
{
|
|
[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]
|
|
public string Type { get; set; } = AntButtonType.Default;
|
|
|
|
[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; }
|
|
|
|
[Parameter]
|
|
public bool Danger { get; set; }
|
|
|
|
[Parameter]
|
|
public RenderFragment ChildContent { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<MouseEventArgs> Onclick { get; set; }
|
|
|
|
[Inject] private NavigationManager NavigationManger { get; set; }
|
|
|
|
public IList<AntIcon> Icons { get; set; } = new List<AntIcon>();
|
|
|
|
//public AntNavLink Link { get; set; }
|
|
|
|
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))
|
|
.If($"{prefixName}-danger", () => Danger)
|
|
.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();
|
|
//if (Link != null && string.IsNullOrEmpty(this.Type))
|
|
//{
|
|
// this.Type = AntButtonType.Link;
|
|
//}
|
|
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")}";
|
|
}
|
|
|
|
protected async Task OnClick(MouseEventArgs args)
|
|
{
|
|
//if (Link != null)
|
|
//{
|
|
// NavigationManger.NavigateTo(Link.Href);
|
|
//}
|
|
|
|
if (Onclick.HasDelegate)
|
|
{
|
|
await Onclick.InvokeAsync(args);
|
|
}
|
|
}
|
|
}
|
|
}
|