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-21 23:48:43 +08:00
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
2020-11-12 15:39:58 +08:00
|
|
|
|
Button?.Icons.Remove(this);
|
|
|
|
|
|
2020-07-21 23:48:43 +08:00
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
|
|
|
|
|
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-11-12 15:39:58 +08:00
|
|
|
|
Button?.Icons.Add(this);
|
2019-12-16 15:33:29 +08:00
|
|
|
|
|
2020-11-12 15:39:58 +08:00
|
|
|
|
ClassMapper.Add($"anticon")
|
|
|
|
|
.GetIf(() => $"anticon-{Type}", () => !string.IsNullOrWhiteSpace(Type));
|
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
|
|
|
|
|
2020-11-12 15:39:58 +08:00
|
|
|
|
string svgClass = Spin ? "anticon-spin" : null;
|
|
|
|
|
|
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-11-12 15:39:58 +08:00
|
|
|
|
_svgImg = IconService.GetStyledSvg(svg, svgClass, Width, Height, Fill, Rotate);
|
2020-08-14 07:13:28 +08:00
|
|
|
|
|
|
|
|
|
StateHasChanged();
|
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-12-08 10:01:43 +08:00
|
|
|
|
var svg = IconService.GetIconImg(Type.ToLowerInvariant(), Theme.ToLowerInvariant());
|
|
|
|
|
_svgImg = IconService.GetStyledSvg(svg, svgClass, Width, Height, Fill, Rotate);
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
2019-12-16 18:45:02 +08:00
|
|
|
|
}
|
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
|
|
|
|
}
|