2020-06-19 22:35:49 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using OneOf;
|
|
|
|
|
|
|
|
|
|
namespace AntDesign
|
|
|
|
|
{
|
|
|
|
|
public partial class SkeletonElement : AntDomComponentBase
|
|
|
|
|
{
|
|
|
|
|
#region Parameters
|
2021-03-12 17:02:11 +08:00
|
|
|
|
|
2020-06-19 22:35:49 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Active { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Type { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public OneOf<int?, string> Size { get; set; } = "default";
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Shape { get; set; } = SkeletonButtonShape.Default;
|
|
|
|
|
|
|
|
|
|
#endregion Parameters
|
|
|
|
|
|
2021-03-12 17:02:11 +08:00
|
|
|
|
private ClassMapper _spanClassMapper = new ClassMapper();
|
2020-06-19 22:35:49 +08:00
|
|
|
|
|
2021-03-12 17:02:11 +08:00
|
|
|
|
private string _spanStyle = "";
|
2020-06-19 22:35:49 +08:00
|
|
|
|
|
|
|
|
|
private void SetClassMap()
|
|
|
|
|
{
|
2021-03-12 17:02:11 +08:00
|
|
|
|
ClassMapper
|
|
|
|
|
.Add("ant-skeleton")
|
2020-06-19 22:35:49 +08:00
|
|
|
|
.If("ant-skeleton-element", () => true)
|
2021-03-12 17:02:11 +08:00
|
|
|
|
.If("ant-skeleton-active", () => Active)
|
|
|
|
|
.If("ant-skeleton-rtl", () => RTL);
|
2020-06-19 22:35:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
SetClassMap();
|
|
|
|
|
|
|
|
|
|
if (Type == SkeletonElementType.Button)
|
|
|
|
|
SetButtonMap();
|
|
|
|
|
else if (Type == SkeletonElementType.Avatar)
|
|
|
|
|
SetAvatarMap();
|
|
|
|
|
else if (Type == SkeletonElementType.Input)
|
|
|
|
|
SetInputMap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetButtonMap()
|
|
|
|
|
{
|
|
|
|
|
_spanClassMapper.Clear().If("ant-skeleton-button", () => true)
|
|
|
|
|
.If("ant-skeleton-button-round", () => Shape == SkeletonButtonShape.Round)
|
|
|
|
|
.If("ant-skeleton-button-circle", () => Shape == SkeletonButtonShape.Circle)
|
|
|
|
|
.If("ant-skeleton-button-lg", () => Size.AsT1 == SkeletonElementSize.Large)
|
|
|
|
|
.If("ant-skeleton-button-sm", () => Size.AsT1 == SkeletonElementSize.Small);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetAvatarMap()
|
|
|
|
|
{
|
|
|
|
|
_spanClassMapper.Clear().If("ant-skeleton-avatar", () => true)
|
2022-08-30 20:03:35 +08:00
|
|
|
|
.If("ant-skeleton-avatar-square", () => Shape == AvatarShape.Square)
|
|
|
|
|
.If("ant-skeleton-avatar-circle", () => Shape == AvatarShape.Circle)
|
2020-06-19 22:35:49 +08:00
|
|
|
|
.If("ant-skeleton-avatar-lg", () => Size.AsT1 == SkeletonElementSize.Large)
|
|
|
|
|
.If("ant-skeleton-avatar-sm", () => Size.AsT1 == SkeletonElementSize.Small);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetInputMap()
|
|
|
|
|
{
|
|
|
|
|
_spanClassMapper.Clear().If("ant-skeleton-input", () => true)
|
|
|
|
|
.If("ant-skeleton-input-lg", () => Size.AsT1 == SkeletonElementSize.Large)
|
|
|
|
|
.If("ant-skeleton-input-sm", () => Size.AsT1 == SkeletonElementSize.Small);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
|
|
|
|
if (Type == SkeletonElementType.Avatar)
|
|
|
|
|
{
|
|
|
|
|
if (Size.IsT0 == true)
|
|
|
|
|
{
|
|
|
|
|
var sideLength = $"{Size.IsT0}px";
|
|
|
|
|
Style = $"width: {sideLength}, height: {sideLength}, 'line-height': {sideLength} ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
base.OnParametersSet();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|