mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-06 05:57:39 +08:00
826df9d055
* feat: new demo for switch, radio, slider and inputnumber * fix: remove some blank in demo doc api section * fix: format the code in demo * fix: checkbox and switch Co-authored-by: ElderJames <shunjiey@hotmail.com>
67 lines
1.8 KiB
C#
67 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace AntBlazor
|
|
{
|
|
public partial class CheckboxGroup : AntDomComponentBase
|
|
{
|
|
[Parameter]
|
|
public RenderFragment ChildContent { get; set; }
|
|
|
|
[Parameter]
|
|
public IList<Checkbox> CheckboxItems { get; set; } = new List<Checkbox>();
|
|
|
|
[Parameter]
|
|
public EventCallback<string[]> ValueChanged { get; set; }
|
|
|
|
[Parameter]
|
|
#pragma warning disable CA1819 // 属性不应返回数组
|
|
public CheckBoxOption[] Options { get; set; }
|
|
|
|
#pragma warning restore CA1819 // 属性不应返回数组
|
|
|
|
[Parameter]
|
|
public IList<string> Value { get; set; } = Array.Empty<string>();
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
foreach (string item in Value)
|
|
{
|
|
Options.Where(o => o.Value == item).ForEach(o => o.Checked = true);
|
|
}
|
|
}
|
|
|
|
[Parameter]
|
|
public bool Disabled { get; set; }
|
|
|
|
public CheckboxGroup()
|
|
{
|
|
ClassMapper.Add("ant-checkbox-group");
|
|
}
|
|
|
|
public async void OnOptionChange()
|
|
{
|
|
await this.ValueChanged.InvokeAsync(this.Options.Where(x => x.Checked).Select(x => x.Value).ToArray());
|
|
StateHasChanged();
|
|
}
|
|
|
|
internal void OnCheckboxChange(Checkbox checkboxBase)
|
|
{
|
|
if (checkboxBase is Checkbox checkbox)
|
|
{
|
|
int index = CheckboxItems.IndexOf(checkbox);
|
|
if (Options[index] != null)
|
|
{
|
|
Options[index].Checked = checkbox.Checked;
|
|
}
|
|
}
|
|
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
}
|