ant-design-blazor/components/space/Space.razor.cs

74 lines
2.1 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using Microsoft.AspNetCore.Components;
using OneOf;
2020-05-15 19:19:49 +08:00
namespace AntDesign
2020-05-15 19:19:49 +08:00
{
public partial class Space : AntDomComponentBase
{
/// <summary>
/// start | end |center |baseline
/// </summary>
2020-05-15 19:19:49 +08:00
[Parameter]
public string Align { get; set; }
[Parameter]
public DirectionVHType Direction { get; set; } = DirectionVHType.Horizontal;
2020-05-15 19:19:49 +08:00
[Parameter]
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; }
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";
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)
.GetIf(() => $"{PrefixCls}-{Direction.Name.ToLowerInvariant()}", () => Direction.IsIn(DirectionVHType.Horizontal, DirectionVHType.Vertical))
.GetIf(() => $"{PrefixCls}-align-{Align}", () => HasAlign)
.If($"{PrefixCls}-align-center", () => !HasAlign && Direction == DirectionVHType.Horizontal)
.If($"{PrefixCls}-rtl", () => RTL);
2020-05-15 19:19:49 +08:00
}
protected override void OnInitialized()
{
SetClass();
base.OnInitialized();
}
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
}
}