2020-01-11 01:10:05 +08:00
|
|
|
|
using System;
|
2020-04-10 16:05:39 +08:00
|
|
|
|
using System.Collections.Generic;
|
2020-04-24 18:32:50 +08:00
|
|
|
|
using System.Collections.ObjectModel;
|
2020-04-10 16:05:39 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-01-11 01:10:05 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2020-01-11 01:10:05 +08:00
|
|
|
|
{
|
2020-05-28 16:56:52 +08:00
|
|
|
|
public partial class CheckboxGroup : AntDomComponentBase
|
2020-01-11 01:10:05 +08:00
|
|
|
|
{
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment ChildContent { get; set; }
|
|
|
|
|
|
2020-04-24 18:32:50 +08:00
|
|
|
|
[Parameter]
|
2020-05-28 16:56:52 +08:00
|
|
|
|
public IList<Checkbox> CheckboxItems { get; set; } = new List<Checkbox>();
|
2020-01-11 01:10:05 +08:00
|
|
|
|
|
2020-04-24 18:32:50 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<string[]> ValueChanged { get; set; }
|
2020-01-11 01:10:05 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-24 18:32:50 +08:00
|
|
|
|
#pragma warning disable CA1819 // 属性不应返回数组
|
2020-05-30 01:46:41 +08:00
|
|
|
|
public CheckboxOption[] Options { get; set; }
|
2020-04-24 18:32:50 +08:00
|
|
|
|
|
|
|
|
|
#pragma warning restore CA1819 // 属性不应返回数组
|
2020-01-11 01:10:05 +08:00
|
|
|
|
|
2020-04-10 16:05:39 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public IList<string> Value { get; set; } = Array.Empty<string>();
|
|
|
|
|
|
2020-04-24 18:32:50 +08:00
|
|
|
|
protected override void OnParametersSet()
|
2020-04-10 16:05:39 +08:00
|
|
|
|
{
|
2020-04-24 18:32:50 +08:00
|
|
|
|
foreach (string item in Value)
|
2020-04-10 16:05:39 +08:00
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
Options.Where(o => o.Value == item).ForEach(o => o.Checked = true);
|
2020-04-10 16:05:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-11 01:10:05 +08:00
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public bool Disabled { get; set; }
|
2020-01-11 01:10:05 +08:00
|
|
|
|
|
2020-05-28 16:56:52 +08:00
|
|
|
|
public CheckboxGroup()
|
2020-01-11 01:10:05 +08:00
|
|
|
|
{
|
|
|
|
|
ClassMapper.Add("ant-checkbox-group");
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-24 18:32:50 +08:00
|
|
|
|
public async void OnOptionChange()
|
2020-04-10 16:05:39 +08:00
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
await this.ValueChanged.InvokeAsync(this.Options.Where(x => x.Checked).Select(x => x.Value).ToArray());
|
2020-04-10 16:05:39 +08:00
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:56:52 +08:00
|
|
|
|
internal void OnCheckboxChange(Checkbox checkboxBase)
|
2020-01-11 01:10:05 +08:00
|
|
|
|
{
|
2020-05-28 16:56:52 +08:00
|
|
|
|
if (checkboxBase is Checkbox checkbox)
|
2020-04-10 16:05:39 +08:00
|
|
|
|
{
|
|
|
|
|
int index = CheckboxItems.IndexOf(checkbox);
|
2020-04-23 17:13:56 +08:00
|
|
|
|
if (Options[index] != null)
|
2020-04-10 16:05:39 +08:00
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
Options[index].Checked = checkbox.Checked;
|
2020-04-10 16:05:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-23 17:13:56 +08:00
|
|
|
|
|
2020-04-10 16:05:39 +08:00
|
|
|
|
StateHasChanged();
|
2020-01-11 01:10:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-23 17:13:56 +08:00
|
|
|
|
}
|