ant-design-blazor/components/core/Base/AntDomComponentBase.cs

87 lines
2.1 KiB
C#
Raw Normal View History

using Microsoft.AspNetCore.Components;
2019-12-08 00:51:07 +08:00
namespace AntDesign
2019-12-08 00:51:07 +08:00
{
public abstract class AntDomComponentBase : AntComponentBase
{
[Inject]
private IComponentIdGenerator ComponentIdGenerator { get; set; }
2019-12-08 00:51:07 +08:00
[Parameter]
public string Id { get; set; }
2019-12-08 00:51:07 +08:00
[CascadingParameter]
public ConfigProvider ConfigProvider { get; set; }
protected bool RTL => ConfigProvider?.Direction == "RTL";
//[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
}
protected override void OnInitialized()
{
Id ??= ComponentIdGenerator.Generate(this);
base.OnInitialized();
}
2019-12-08 00:51:07 +08:00
/// <summary>
/// Specifies one or more class names for an DOM element.
2019-12-08 00:51:07 +08:00
/// </summary>
[Parameter]
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>
/// 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;
this.StateHasChanged();
}
}
protected virtual string GenerateStyle()
{
return Style;
}
private string _class;
private string _style;
}
}