2020-05-15 19:19:49 +08:00
|
|
|
|
using System.Collections;
|
2021-01-25 02:05:18 +08:00
|
|
|
|
using System.Collections.Generic;
|
2020-05-15 19:19:49 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2020-05-15 19:19:49 +08:00
|
|
|
|
{
|
2021-04-06 14:20:29 +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; }
|
|
|
|
|
|
2021-04-06 14:20:29 +08:00
|
|
|
|
private static readonly Dictionary<string, string> _spaceSize = new()
|
2020-05-15 19:19:49 +08:00
|
|
|
|
{
|
2021-01-25 02:05:18 +08:00
|
|
|
|
["small"] = "8",
|
|
|
|
|
["middle"] = "16",
|
|
|
|
|
["large"] = "24"
|
2020-05-15 19:19:49 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private string _marginStyle = "";
|
2021-04-06 14:20:29 +08:00
|
|
|
|
private int _index;
|
2020-05-15 19:19:49 +08:00
|
|
|
|
|
2021-04-06 14:20:29 +08:00
|
|
|
|
protected override void OnInitialized()
|
2020-05-15 19:19:49 +08:00
|
|
|
|
{
|
2021-04-06 14:20:29 +08:00
|
|
|
|
base.OnInitialized();
|
|
|
|
|
|
|
|
|
|
ClassMapper.Add("ant-space-item");
|
|
|
|
|
}
|
2020-05-15 19:19:49 +08:00
|
|
|
|
|
2021-06-30 13:41:38 +08:00
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
|
|
|
|
_index = Parent.SpaceItemCount++;
|
|
|
|
|
base.OnParametersSet();
|
|
|
|
|
}
|
2020-05-15 19:19:49 +08:00
|
|
|
|
|
2021-06-30 13:41:38 +08:00
|
|
|
|
private void ChangeSize()
|
2021-04-06 14:20:29 +08:00
|
|
|
|
{
|
2020-05-15 19:19:49 +08:00
|
|
|
|
var size = Parent.Size;
|
|
|
|
|
var direction = Parent.Direction;
|
|
|
|
|
|
2021-04-06 14:20:29 +08:00
|
|
|
|
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
|
|
|
|
|
2021-04-06 14:20:29 +08:00
|
|
|
|
return originalSize;
|
2020-05-15 19:19:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|