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

63 lines
1.8 KiB
C#
Raw Normal View History

2020-05-15 19:19:49 +08:00
using System.Collections;
using System.Collections.Generic;
2020-05-15 19:19:49 +08:00
using Microsoft.AspNetCore.Components;
namespace AntDesign
2020-05-15 19:19:49 +08:00
{
public partial class SpaceItem : AntDomComponentBase
2020-05-15 19:19:49 +08:00
{
[CascadingParameter]
public Space Parent { get; set; }
[Parameter]
public RenderFragment ChildContent { get; set; }
private static readonly Dictionary<string, string> _spaceSize = new()
2020-05-15 19:19:49 +08:00
{
["small"] = "8",
["middle"] = "16",
["large"] = "24"
2020-05-15 19:19:49 +08:00
};
private string _marginStyle = "";
private int _index;
2020-05-15 19:19:49 +08:00
protected override void OnInitialized()
2020-05-15 19:19:49 +08:00
{
base.OnInitialized();
Parent?.AddSpaceItem(this);
ClassMapper.Add("ant-space-item");
}
2020-05-15 19:19:49 +08:00
internal void SetIndex(int index) => _index = index;
2020-05-15 19:19:49 +08:00
internal void ChangeSize()
{
2020-05-15 19:19:49 +08:00
var size = Parent.Size;
var direction = Parent.Direction;
size.Switch(sigleSize =>
{
_marginStyle = direction == DirectionVHType.Horizontal ? (_index != Parent.SpaceItemCount - 1 ? $"margin-right:{GetSize(sigleSize)};" : "") : $"margin-bottom:{GetSize(sigleSize)};";
},
arraySize =>
{
_marginStyle = (_index != Parent.SpaceItemCount - 1 ? $"margin-right:{GetSize(arraySize.Item1)};" : "") + $"margin-bottom:{GetSize(arraySize.Item2)};";
});
}
private CssSizeLength GetSize(string size)
{
var originalSize = size.IsIn(_spaceSize.Keys) ? _spaceSize[size] : size;
if (Parent?.Split != null)
{
return ((CssSizeLength)originalSize).Value / 2;
}
2020-05-15 19:19:49 +08:00
return originalSize;
2020-05-15 19:19:49 +08:00
}
}
}