2020-06-10 21:44:21 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2019-12-11 00:23:10 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2019-12-11 00:23:10 +08:00
|
|
|
|
{
|
2020-06-07 19:41:00 +08:00
|
|
|
|
public partial class Icon : AntDomComponentBase
|
2019-12-11 00:23:10 +08:00
|
|
|
|
{
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public bool Spin { get; set; }
|
2019-12-11 00:23:10 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-06-10 21:44:21 +08:00
|
|
|
|
public int Rotate { get; set; } = 0;
|
2019-12-11 00:23:10 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public string Type { get; set; }
|
2019-12-11 00:23:10 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 'fill' | 'outline' | 'twotone';
|
|
|
|
|
/// </summary>
|
2019-12-11 00:23:10 +08:00
|
|
|
|
[Parameter]
|
2020-06-07 19:41:00 +08:00
|
|
|
|
public string Theme { get; set; } = IconThemeType.Outline;
|
2019-12-11 00:23:10 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public string TwotoneColor { get; set; }
|
2019-12-11 00:23:10 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public string IconFont { get; set; }
|
2019-12-11 00:23:10 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public string Width { get; set; } = "1em";
|
2019-12-11 00:23:10 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public string Height { get; set; } = "1em";
|
2019-12-11 00:23:10 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public string Fill { get; set; } = "currentColor";
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string TabIndex { get; set; }
|
2019-12-11 00:23:10 +08:00
|
|
|
|
|
2020-06-29 13:30:44 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public bool StopPropagation { get; set; }
|
|
|
|
|
|
2019-12-16 15:33:29 +08:00
|
|
|
|
[CascadingParameter]
|
2020-05-29 12:55:15 +08:00
|
|
|
|
public Button Button { get; set; }
|
2019-12-16 15:33:29 +08:00
|
|
|
|
|
2019-12-11 00:23:10 +08:00
|
|
|
|
[Parameter]
|
2020-05-18 18:42:22 +08:00
|
|
|
|
public EventCallback<MouseEventArgs> OnClick { get; set; }
|
2019-12-11 00:23:10 +08:00
|
|
|
|
|
|
|
|
|
[Inject]
|
2020-06-10 21:44:21 +08:00
|
|
|
|
public IconService IconService { get; set; }
|
2019-12-11 00:23:10 +08:00
|
|
|
|
|
2020-06-10 21:44:21 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment Component { get; set; }
|
2019-12-11 00:23:10 +08:00
|
|
|
|
|
2020-06-16 16:25:22 +08:00
|
|
|
|
protected string _svgImg;
|
2019-12-11 00:23:10 +08:00
|
|
|
|
|
2020-07-16 18:26:39 +08:00
|
|
|
|
protected string IconStyle => Rotate == 0 ? "" : $"transform: rotate({Rotate}deg);";
|
|
|
|
|
|
2019-12-11 00:23:10 +08:00
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
2020-06-13 00:23:03 +08:00
|
|
|
|
if (Type == "loading")
|
|
|
|
|
{
|
|
|
|
|
Spin = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-10 21:44:21 +08:00
|
|
|
|
await SetupSvgImg();
|
2019-12-16 15:33:29 +08:00
|
|
|
|
|
2020-06-07 19:41:00 +08:00
|
|
|
|
if (this is Icon icon)
|
2019-12-16 15:33:29 +08:00
|
|
|
|
{
|
|
|
|
|
Button?.Icons.Add(icon);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-16 18:26:39 +08:00
|
|
|
|
ClassMapper.Add($"anticon anticon-{Type}")
|
|
|
|
|
.If("anticon-spin", () => Spin);
|
2020-06-10 21:44:21 +08:00
|
|
|
|
|
2019-12-11 17:17:58 +08:00
|
|
|
|
await base.OnInitializedAsync();
|
2019-12-11 00:23:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-16 18:45:02 +08:00
|
|
|
|
protected override async Task OnParametersSetAsync()
|
2019-12-11 00:23:10 +08:00
|
|
|
|
{
|
2019-12-16 18:45:02 +08:00
|
|
|
|
await SetupSvgImg();
|
|
|
|
|
await base.OnParametersSetAsync();
|
2019-12-11 00:23:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-16 16:25:22 +08:00
|
|
|
|
protected virtual async Task SetupSvgImg()
|
2019-12-11 00:23:10 +08:00
|
|
|
|
{
|
2020-06-10 21:44:21 +08:00
|
|
|
|
if (Component != null)
|
2019-12-16 18:45:02 +08:00
|
|
|
|
{
|
2020-06-10 21:44:21 +08:00
|
|
|
|
return;
|
2020-04-24 18:32:50 +08:00
|
|
|
|
}
|
2020-06-10 21:44:21 +08:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(IconFont))
|
2020-04-24 18:32:50 +08:00
|
|
|
|
{
|
2020-06-10 21:44:21 +08:00
|
|
|
|
var svg = $"<svg><use xlink:href=#{IconFont} /></svg>";
|
2020-07-16 18:26:39 +08:00
|
|
|
|
_svgImg = IconService.GetStyledSvg(svg, Width, Height, Fill);
|
2019-12-16 18:45:02 +08:00
|
|
|
|
}
|
2020-06-10 21:44:21 +08:00
|
|
|
|
else
|
2019-12-16 18:45:02 +08:00
|
|
|
|
{
|
2020-06-13 00:23:03 +08:00
|
|
|
|
var svg = await IconService.GetIconImg(Type.ToLowerInvariant(), Theme.ToLowerInvariant());
|
2020-07-16 18:26:39 +08:00
|
|
|
|
_svgImg = IconService.GetStyledSvg(svg, Width, Height, Fill);
|
2019-12-16 18:45:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-18 16:57:00 +08:00
|
|
|
|
StateHasChanged();
|
2019-12-11 00:23:10 +08:00
|
|
|
|
}
|
2019-12-16 15:33:29 +08:00
|
|
|
|
|
2020-05-18 18:42:22 +08:00
|
|
|
|
private async Task HandleOnClick(MouseEventArgs args)
|
2019-12-16 15:33:29 +08:00
|
|
|
|
{
|
2020-05-18 18:42:22 +08:00
|
|
|
|
if (OnClick.HasDelegate)
|
2019-12-16 15:33:29 +08:00
|
|
|
|
{
|
2020-05-18 18:42:22 +08:00
|
|
|
|
await OnClick.InvokeAsync(args);
|
2019-12-16 15:33:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-11 00:23:10 +08:00
|
|
|
|
}
|
2020-04-23 17:13:56 +08:00
|
|
|
|
}
|