mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-16 01:41:14 +08:00
2d801c6c53
* feat: add component radio * feat: add radio-group
100 lines
2.5 KiB
Plaintext
100 lines
2.5 KiB
Plaintext
@namespace AntBlazor
|
|
@inherits AntDomComponentBase
|
|
|
|
<CascadingValue Value="this">
|
|
<div class="@ClassMapper.Class" style="@Style" @attributes="Attributes" Id="@Id" @ref="Ref">
|
|
@ChildContent
|
|
</div>
|
|
</CascadingValue>
|
|
|
|
@code {
|
|
|
|
[Parameter] public RenderFragment ChildContent { get; set; }
|
|
|
|
[Parameter] public bool Disabled { get; set; }
|
|
|
|
[Parameter] public string ButtonStyle { get; set; } = "outline";
|
|
|
|
[Parameter] public string Size { get; set; } = "default";
|
|
|
|
[Parameter] public string Name { get; set; }
|
|
|
|
[Parameter] public EventCallback<string> OnChange { get; set; }
|
|
|
|
[Parameter] public string Value { get; set; }
|
|
|
|
[Parameter] public EventCallback<string > ValueChanged { get; set; }
|
|
|
|
internal List<AntRadio> RadioItems { get; set; } = new List<AntRadio>();
|
|
|
|
string _currentValue => Value;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
string prefixCls = "ant-radio-group";
|
|
ClassMapper.Add(prefixCls)
|
|
.If($"{prefixCls}-large", () => Size == "large")
|
|
.If($"{prefixCls}-small", () => Size == "small")
|
|
.If($"{prefixCls}-solid", () => ButtonStyle == "solid");
|
|
|
|
|
|
await base.OnInitializedAsync();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
foreach (var radio in RadioItems)
|
|
{
|
|
if (radio.Value == this._currentValue)
|
|
{
|
|
await radio.Select();
|
|
}
|
|
else
|
|
{
|
|
await radio.UnSelect();
|
|
}
|
|
}
|
|
StateHasChanged();
|
|
await base.OnParametersSetAsync();
|
|
}
|
|
|
|
internal async Task AddRadio(AntRadio radio)
|
|
{
|
|
if (this.Name != null)
|
|
{
|
|
radio.name = Name;
|
|
}
|
|
RadioItems.Add(radio);
|
|
if (this._currentValue == radio.Value)
|
|
{
|
|
await radio.Select();
|
|
}
|
|
StateHasChanged();
|
|
}
|
|
|
|
internal async Task OnRadioChange(string value)
|
|
{
|
|
if (this._currentValue != value)
|
|
{
|
|
this.Value = value;
|
|
await this.ValueChanged.InvokeAsync(value);
|
|
|
|
foreach (var radio in RadioItems)
|
|
{
|
|
if (radio.Value != this._currentValue)
|
|
{
|
|
await radio.UnSelect();
|
|
}
|
|
}
|
|
|
|
if (this.OnChange.HasDelegate)
|
|
{
|
|
await this.OnChange.InvokeAsync(value);
|
|
}
|
|
}
|
|
StateHasChanged();
|
|
|
|
}
|
|
|
|
}
|