You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Components/src/Connected.Components/Components/CheckBox.razor.cs

43 lines
949 B

using Connected.Models;
using Microsoft.AspNetCore.Components;
namespace Connected.Components;
public partial class CheckBox : InputBase
{
[CascadingParameter]
public CheckBoxGroup? ParentCheckBoxGroup { get; set; }
private bool _checked { get; set; }
[Parameter]
public bool? Checked
{
get => _checked;
set => _checked = (bool)value;
}
[Parameter, EditorRequired]
public string Id { get; set; }
[Parameter]
public EventCallback<bool> CheckedChanged { get; set; }
public async Task OnChange()
{
Checked = !Checked;
CheckedChanged.InvokeAsync((bool)Checked);
}
protected override async Task OnParametersSetAsync()
{
await base.OnInitializedAsync();
if (ParentCheckBoxGroup.Disabled) Disabled = true;
if (!InputAttributes.ContainsKey("disabled"))
InputAttributes.Add("disabled", Disabled);
if (!InputAttributes.ContainsKey("checked"))
InputAttributes.Add("checked", Checked);
StateHasChanged();
}
}