@using System @namespace Sandbox.UI @inherits BaseControl @attribute [CustomEditor( typeof(bool) )]
@if ( Label != null ) {
@Label
}
@code { public RenderFragment Label { get; set; } public Action OnValueChanged { get; set; } string StateClass => Value ? "active" : "inactive"; bool _value; public bool Value { get => Property?.As.Bool ?? _value; set { if ( Property is not null ) { Property.As.Bool = value; StateHasChanged(); return; } if (_value == value) return; _value = value; StateHasChanged(); } } public SwitchControl() { } protected override void OnMouseDown( MousePanelEvent e ) { base.OnMouseDown( e ); Value = !Value; OnValueChanged?.Invoke( Value ); e.StopPropagation(); } }