mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-15 01:11:52 +08:00
059491d749
* Replaced IdGeneratorHelper with DI service that can be replaced by user * removed license comments and unnecessary usings * check Id null before assigning autogenerated id * fix: unit test Co-authored-by: ElderJames <shunjiey@hotmail.com>
82 lines
1.9 KiB
C#
82 lines
1.9 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace AntDesign
|
|
{
|
|
public abstract class AntDomComponentBase : AntComponentBase
|
|
{
|
|
[Inject]
|
|
private IComponentIdGenerator ComponentIdGenerator { get; set; }
|
|
|
|
[Parameter]
|
|
public string Id { get; set; }
|
|
|
|
//[Parameter(CaptureUnmatchedValues = true)]
|
|
//public Dictionary<string, object> Attributes { get; set; } = new Dictionary<string, object>();
|
|
|
|
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
|
|
.Get(() => this.Class);
|
|
}
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
Id ??= ComponentIdGenerator.Generate(this);
|
|
base.OnInitialized();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Specifies one or more class names for an DOM element.
|
|
/// </summary>
|
|
[Parameter]
|
|
public string Class
|
|
{
|
|
get => _class;
|
|
set
|
|
{
|
|
_class = value;
|
|
ClassMapper.OriginalClass = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Specifies an inline style for an DOM element.
|
|
/// </summary>
|
|
[Parameter]
|
|
public string Style
|
|
{
|
|
get => _style;
|
|
set
|
|
{
|
|
_style = value;
|
|
this.StateHasChanged();
|
|
}
|
|
}
|
|
|
|
protected virtual string GenerateStyle()
|
|
{
|
|
return Style;
|
|
}
|
|
|
|
private string _class;
|
|
private string _style;
|
|
}
|
|
}
|