2020-04-23 17:13:56 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
2019-12-08 00:51:07 +08:00
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2019-12-08 00:51:07 +08:00
|
|
|
|
{
|
|
|
|
|
public abstract class AntDomComponentBase : AntComponentBase
|
|
|
|
|
{
|
2020-10-10 15:31:32 +08:00
|
|
|
|
[Inject]
|
|
|
|
|
private IComponentIdGenerator ComponentIdGenerator { get; set; }
|
|
|
|
|
|
2019-12-08 00:51:07 +08:00
|
|
|
|
[Parameter]
|
2020-10-10 15:31:32 +08:00
|
|
|
|
public string Id { get; set; }
|
2019-12-08 00:51:07 +08:00
|
|
|
|
|
2021-03-12 17:02:11 +08:00
|
|
|
|
[CascadingParameter]
|
|
|
|
|
public ConfigProvider ConfigProvider { get; set; }
|
|
|
|
|
|
|
|
|
|
protected bool RTL => ConfigProvider?.Direction == "RTL";
|
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
//[Parameter(CaptureUnmatchedValues = true)]
|
|
|
|
|
//public Dictionary<string, object> Attributes { get; set; } = new Dictionary<string, object>();
|
2019-12-08 00:51:07 +08:00
|
|
|
|
|
|
|
|
|
private ElementReference _ref;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returned ElementRef reference for DOM element.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual ElementReference Ref
|
|
|
|
|
{
|
|
|
|
|
get => _ref;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_ref = value;
|
|
|
|
|
RefBack?.Set(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected ClassMapper ClassMapper { get; } = new ClassMapper();
|
|
|
|
|
|
|
|
|
|
protected AntDomComponentBase()
|
|
|
|
|
{
|
|
|
|
|
ClassMapper
|
2020-04-24 18:32:50 +08:00
|
|
|
|
.Get(() => this.Class);
|
2019-12-08 00:51:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-10 15:31:32 +08:00
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
Id ??= ComponentIdGenerator.Generate(this);
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-08 00:51:07 +08:00
|
|
|
|
/// <summary>
|
2020-04-23 17:13:56 +08:00
|
|
|
|
/// Specifies one or more class names for an DOM element.
|
2019-12-08 00:51:07 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public string Class
|
2019-12-08 00:51:07 +08:00
|
|
|
|
{
|
|
|
|
|
get => _class;
|
2019-12-20 00:20:53 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_class = value;
|
|
|
|
|
ClassMapper.OriginalClass = value;
|
|
|
|
|
}
|
2019-12-08 00:51:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-05-27 18:13:26 +08:00
|
|
|
|
/// Specifies an inline style for a DOM element.
|
2019-12-08 00:51:07 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Style
|
|
|
|
|
{
|
|
|
|
|
get => _style;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_style = value;
|
2021-05-28 14:10:44 +08:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(_style) && !_style.EndsWith(";"))
|
|
|
|
|
{
|
|
|
|
|
_style += ";";
|
|
|
|
|
}
|
2019-12-08 00:51:07 +08:00
|
|
|
|
this.StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual string GenerateStyle()
|
|
|
|
|
{
|
|
|
|
|
return Style;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string _class;
|
|
|
|
|
private string _style;
|
|
|
|
|
}
|
2020-04-23 17:13:56 +08:00
|
|
|
|
}
|