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
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
private string _hostFlexStyle = null;
|
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)
|
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
GutterStyle = $"padding-left: {gutter.horizontalGutter / 2}px;padding-right: {gutter.horizontalGutter / 2}px;";
|
2020-03-15 23:54:48 +08:00
|
|
|
|
}
|
|
|
|
|
if (gutter.verticalGutter > 0)
|
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
GutterStyle += $"padding-top: {gutter.verticalGutter / 2}px;padding-bottom: {gutter.verticalGutter / 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)
|
2020-04-23 17:13:56 +08:00
|
|
|
|
.If($"{prefixCls}-{this.Span.Value}", () => this.Span.Value != null)
|
|
|
|
|
.If($"{prefixCls}-order-{this.Order.Value}", () => this.Order.Value != null)
|
|
|
|
|
.If($"{prefixCls}-offset-{this.Offset.Value}", () => this.Offset.Value != null)
|
|
|
|
|
.If($"{prefixCls}-pull-{this.Pull.Value}", () => this.Pull.Value != null)
|
|
|
|
|
.If($"{prefixCls}-push-{this.Push.Value}", () => this.Push.Value != null)
|
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
|
2020-07-10 17:35:07 +08:00
|
|
|
|
.If($"{prefixCls}-{sizeName}-{embedded.Span.Value}", () => embedded.Span.Value != null)
|
2020-06-30 22:41:00 +08:00
|
|
|
|
.If($"{prefixCls}-{sizeName}-order-{embedded.Order.Value}", () => embedded.Order.Value != null)
|
|
|
|
|
.If($"{prefixCls}-{sizeName}-offset-{embedded.Offset.Value}", () => embedded.Offset.Value != null)
|
|
|
|
|
.If($"{prefixCls}-{sizeName}-push-{embedded.Push.Value}", () => embedded.Push.Value != null)
|
|
|
|
|
.If($"{prefixCls}-{sizeName}-pull-{embedded.Pull.Value}", () => embedded.Pull.Value != null);
|
|
|
|
|
});
|
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)
|
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
return $"0 0 {Flex}";
|
2020-03-15 23:54:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
return Flex.AsT0;
|
2020-03-15 23:54:48 +08:00
|
|
|
|
},
|
2020-04-23 17:13:56 +08:00
|
|
|
|
num => $"{Flex} {Flex} auto");
|
2020-03-15 23:54:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
2020-06-30 22:41:00 +08:00
|
|
|
|
this.Row?.Cols.Add(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
|
|
|
|
{
|
2020-06-30 22:41:00 +08:00
|
|
|
|
this.Row?.Cols.Remove(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
|
|
|
|
}
|
2020-04-23 17:13:56 +08:00
|
|
|
|
}
|