ant-design-blazor/components/checkbox/CheckboxGroup.razor.cs
Alsein 82ef62b7a7 feat: add simple table component (#86)
* fix: add @commitlint/config-conventional to devDependencies

* feat: add basic table implementation

* feat: continue adding definitions

* feat: end of work in 20200414

* fix: add readonly to csssizelength

* fix: warnings from table

* fix: add ignorecase to csssizelength

* feat: refactor table

* feat: add simple table

Co-authored-by: ElderJames <shunjiey@hotmail.com>
2020-05-30 01:46:41 +08:00

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 AntDesign
{
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();
}
}
}