2021-04-06 14:20:29 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using OneOf;
|
2020-05-15 19:19:49 +08:00
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2020-05-15 19:19:49 +08:00
|
|
|
|
{
|
|
|
|
|
public partial class Space : AntDomComponentBase
|
|
|
|
|
{
|
2021-04-06 14:20:29 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// start | end |center |baseline
|
|
|
|
|
/// </summary>
|
2020-05-15 19:19:49 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string Align { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
2021-04-06 14:20:29 +08:00
|
|
|
|
public DirectionVHType Direction { get; set; } = DirectionVHType.Horizontal;
|
2020-05-15 19:19:49 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2021-04-06 14:20:29 +08:00
|
|
|
|
public OneOf<string, (string, string)> Size
|
|
|
|
|
{
|
|
|
|
|
get { return _size; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_size = value;
|
|
|
|
|
_items.ForEach(x => x.ChangeSize());
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Wrap { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment Split { get; set; }
|
2020-05-15 19:19:49 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment ChildContent { get; set; }
|
|
|
|
|
|
2021-04-06 14:20:29 +08:00
|
|
|
|
internal int SpaceItemCount => _items.Count;
|
|
|
|
|
|
|
|
|
|
private IList<SpaceItem> _items = new List<SpaceItem>();
|
|
|
|
|
|
2020-05-15 19:19:49 +08:00
|
|
|
|
private bool HasAlign => Align.IsIn("start", "end", "center", "baseline");
|
|
|
|
|
|
|
|
|
|
private const string PrefixCls = "ant-space";
|
2021-04-06 14:20:29 +08:00
|
|
|
|
private OneOf<string, (string, string)> _size = "small";
|
|
|
|
|
|
|
|
|
|
private string InnerStyle => Wrap && Direction == DirectionVHType.Horizontal ? "flex-wrap: wrap;" : "";
|
2020-05-15 19:19:49 +08:00
|
|
|
|
|
|
|
|
|
public void SetClass()
|
|
|
|
|
{
|
|
|
|
|
ClassMapper
|
|
|
|
|
.Add(PrefixCls)
|
2021-04-06 14:20:29 +08:00
|
|
|
|
.GetIf(() => $"{PrefixCls}-{Direction.Name.ToLowerInvariant()}", () => Direction.IsIn(DirectionVHType.Horizontal, DirectionVHType.Vertical))
|
2021-03-12 17:02:11 +08:00
|
|
|
|
.GetIf(() => $"{PrefixCls}-align-{Align}", () => HasAlign)
|
2021-04-06 14:20:29 +08:00
|
|
|
|
.If($"{PrefixCls}-align-center", () => !HasAlign && Direction == DirectionVHType.Horizontal)
|
2021-03-12 17:02:11 +08:00
|
|
|
|
.If($"{PrefixCls}-rtl", () => RTL);
|
2020-05-15 19:19:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
SetClass();
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
}
|
2021-04-06 14:20:29 +08:00
|
|
|
|
|
|
|
|
|
internal void AddSpaceItem(SpaceItem item)
|
|
|
|
|
{
|
|
|
|
|
_items.Add(item);
|
|
|
|
|
item.SetIndex(_items.Count - 1);
|
|
|
|
|
_items.ForEach(x => x.ChangeSize());
|
|
|
|
|
}
|
2020-05-15 19:19:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|