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