2020-06-30 22:41:00 +08:00
|
|
|
|
using System.Text.RegularExpressions;
|
2020-03-15 23:54:48 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using OneOf;
|
2020-03-05 12:17:50 +08:00
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2020-03-05 12:17:50 +08:00
|
|
|
|
{
|
2020-03-15 23:54:48 +08:00
|
|
|
|
using StringNumber = OneOf<string, int>;
|
|
|
|
|
|
|
|
|
|
public class EmbeddedProperty
|
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public StringNumber Span { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public StringNumber Pull { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public StringNumber Push { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public StringNumber Offset { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public StringNumber Order { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 00:20:28 +08:00
|
|
|
|
public partial class Col : AntDomComponentBase
|
2020-03-05 12:17:50 +08:00
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment ChildContent { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public StringNumber Flex { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public StringNumber Span { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public StringNumber Order { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public StringNumber Offset { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public StringNumber Push { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public StringNumber Pull { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public OneOf<int, EmbeddedProperty> Xs { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public OneOf<int, EmbeddedProperty> Sm { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public OneOf<int, EmbeddedProperty> Md { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public OneOf<int, EmbeddedProperty> Lg { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public OneOf<int, EmbeddedProperty> Xl { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public OneOf<int, EmbeddedProperty> Xxl { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[CascadingParameter]
|
2020-06-07 00:20:28 +08:00
|
|
|
|
public Row Row { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2021-04-03 23:36:46 +08:00
|
|
|
|
private string _hostFlexStyle;
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
private string GutterStyle { get; set; }
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
|
|
|
|
internal void RowGutterChanged((int horizontalGutter, int verticalGutter) gutter)
|
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
GutterStyle = "";
|
2020-03-15 23:54:48 +08:00
|
|
|
|
if (gutter.horizontalGutter > 0)
|
|
|
|
|
{
|
2021-02-23 13:38:05 +08:00
|
|
|
|
GutterStyle = $"padding-left: {gutter.horizontalGutter / 2}px; padding-right: {gutter.horizontalGutter / 2}px;";
|
2020-03-15 23:54:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetHostClassMap()
|
|
|
|
|
{
|
2020-04-24 18:32:50 +08:00
|
|
|
|
var prefixCls = "ant-col";
|
2020-03-15 23:54:48 +08:00
|
|
|
|
this.ClassMapper.Clear()
|
|
|
|
|
.Add(prefixCls)
|
2021-03-12 17:02:11 +08:00
|
|
|
|
.GetIf(() => $"{prefixCls}-{this.Span.Value}", () => this.Span.Value != null)
|
|
|
|
|
.GetIf(() => $"{prefixCls}-order-{this.Order.Value}", () => this.Order.Value != null)
|
|
|
|
|
.GetIf(() => $"{prefixCls}-offset-{this.Offset.Value}", () => this.Offset.Value != null)
|
|
|
|
|
.GetIf(() => $"{prefixCls}-pull-{this.Pull.Value}", () => this.Pull.Value != null)
|
|
|
|
|
.GetIf(() => $"{prefixCls}-push-{this.Push.Value}", () => this.Push.Value != null)
|
|
|
|
|
.If($"{prefixCls}-rtl", () => RTL)
|
2020-03-15 23:54:48 +08:00
|
|
|
|
;
|
|
|
|
|
|
2020-06-30 22:41:00 +08:00
|
|
|
|
SetSizeClassMapper(prefixCls, Xs, "xs");
|
|
|
|
|
SetSizeClassMapper(prefixCls, Sm, "sm");
|
|
|
|
|
SetSizeClassMapper(prefixCls, Md, "md");
|
|
|
|
|
SetSizeClassMapper(prefixCls, Lg, "lg");
|
|
|
|
|
SetSizeClassMapper(prefixCls, Xl, "xl");
|
|
|
|
|
SetSizeClassMapper(prefixCls, Xxl, "xxl");
|
|
|
|
|
}
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-06-30 22:41:00 +08:00
|
|
|
|
private void SetSizeClassMapper(string prefixCls, OneOf<int, EmbeddedProperty> parameter, string sizeName)
|
|
|
|
|
{
|
|
|
|
|
parameter.Switch(strNum =>
|
|
|
|
|
{
|
|
|
|
|
ClassMapper.If($"{prefixCls}-{sizeName}-{strNum}", () => strNum > 0);
|
|
|
|
|
}, embedded =>
|
|
|
|
|
{
|
|
|
|
|
ClassMapper
|
2021-04-03 23:36:46 +08:00
|
|
|
|
.GetIf(() => $"{prefixCls}-{sizeName}-{embedded.Span.Value}", () => embedded.Span.Value != null)
|
|
|
|
|
.GetIf(() => $"{prefixCls}-{sizeName}-order-{embedded.Order.Value}", () => embedded.Order.Value != null)
|
|
|
|
|
.GetIf(() => $"{prefixCls}-{sizeName}-offset-{embedded.Offset.Value}", () => embedded.Offset.Value != null)
|
|
|
|
|
.GetIf(() => $"{prefixCls}-{sizeName}-push-{embedded.Push.Value}", () => embedded.Push.Value != null)
|
|
|
|
|
.GetIf(() => $"{prefixCls}-{sizeName}-pull-{embedded.Pull.Value}", () => embedded.Pull.Value != null);
|
2020-06-30 22:41:00 +08:00
|
|
|
|
});
|
2020-03-15 23:54:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetHostFlexStyle()
|
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
if (this.Flex.Value == null)
|
2020-03-15 23:54:48 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
this._hostFlexStyle = this.Flex.Match(str =>
|
2020-03-15 23:54:48 +08:00
|
|
|
|
{
|
|
|
|
|
if (Regex.Match(str, "^\\d+(\\.\\d+)?(px|em|rem|%)$").Success)
|
|
|
|
|
{
|
2021-04-03 23:36:46 +08:00
|
|
|
|
return $"flex: 0 0 {str}";
|
2020-03-15 23:54:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-03 23:36:46 +08:00
|
|
|
|
return $"flex: {str}";
|
2020-03-15 23:54:48 +08:00
|
|
|
|
},
|
2021-04-03 23:36:46 +08:00
|
|
|
|
num => $"flex: {num} {num} auto");
|
2020-03-15 23:54:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
2021-06-18 18:49:18 +08:00
|
|
|
|
this.Row?.AddCol(this);
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
|
|
|
|
this.SetHostClassMap();
|
|
|
|
|
this.SetHostFlexStyle();
|
2020-06-30 22:41:00 +08:00
|
|
|
|
|
|
|
|
|
base.OnInitialized();
|
2020-03-15 23:54:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-24 18:32:50 +08:00
|
|
|
|
protected override void Dispose(bool disposing)
|
2020-03-15 23:54:48 +08:00
|
|
|
|
{
|
2021-06-18 18:49:18 +08:00
|
|
|
|
this.Row?.RemoveCol(this);
|
2020-03-15 23:54:48 +08:00
|
|
|
|
|
2020-04-24 18:32:50 +08:00
|
|
|
|
base.Dispose(disposing);
|
2020-03-15 23:54:48 +08:00
|
|
|
|
}
|
2020-03-05 12:17:50 +08:00
|
|
|
|
}
|
2021-06-18 18:49:18 +08:00
|
|
|
|
}
|