@inherits DInputBase @* daisyUI Toggle: https://daisyui.com/components/toggle/ . With CheckedIcon/UncheckedIcon the toggle class moves to a wrapper around the checkbox and the two icons (each must be a single element: daisyUI shows the wrapper's 2nd child while unchecked and its 3rd while checked). daisyUI colors such a wrapper only through aria-checked, which a label may not carry, so its color is a has-checked: variable instead. With LabelText all of it sits in a label.label. *@ @if (!HasIcons && LabelText is null) { @Checkbox(Cx("toggle", IsInvalid ? "toggle-error" : ColorClass, SizeClass, CssClass)) } else if (!HasIcons) { } else if (LabelText is null) { } else { } @code { [Parameter] public DColor Color { get; set; } [Parameter] public DSize Size { get; set; } [Parameter] public string LabelText { get; set; } [Parameter] public RenderFragment CheckedIcon { get; set; } [Parameter] public RenderFragment UncheckedIcon { get; set; } bool HasIcons => CheckedIcon is not null || UncheckedIcon is not null; string WrapperClass => Cx("toggle", IsInvalid ? "has-checked:[--input-color:var(--color-error)]" : WrapperColorClass, SizeClass, CssClass); RenderFragment Checkbox(string cssClass) => @; RenderFragment IconParts => @ @Checkbox(null) @if (UncheckedIcon is null) { } else { @UncheckedIcon } @if (CheckedIcon is null) { } else { @CheckedIcon } ; string ColorClass => Color switch { DColor.Neutral => "toggle-neutral", DColor.Primary => "toggle-primary", DColor.Secondary => "toggle-secondary", DColor.Accent => "toggle-accent", DColor.Info => "toggle-info", DColor.Success => "toggle-success", DColor.Warning => "toggle-warning", DColor.Error => "toggle-error", _ => null }; string WrapperColorClass => Color switch { DColor.Neutral => "has-checked:[--input-color:var(--color-neutral)]", DColor.Primary => "has-checked:[--input-color:var(--color-primary)]", DColor.Secondary => "has-checked:[--input-color:var(--color-secondary)]", DColor.Accent => "has-checked:[--input-color:var(--color-accent)]", DColor.Info => "has-checked:[--input-color:var(--color-info)]", DColor.Success => "has-checked:[--input-color:var(--color-success)]", DColor.Warning => "has-checked:[--input-color:var(--color-warning)]", DColor.Error => "has-checked:[--input-color:var(--color-error)]", _ => null }; string SizeClass => Size switch { DSize.Xs => "toggle-xs", DSize.Sm => "toggle-sm", DSize.Lg => "toggle-lg", DSize.Xl => "toggle-xl", _ => null }; void OnChange(ChangeEventArgs e) => CurrentValue = e.Value is true; }