# SbSwitch A toggle switch component for boolean on/off states. More visually distinct than a checkbox for settings and preferences. ## Parameters | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | Value | bool | false | Switch on/off state (two-way bindable) | | ValueChanged | EventCallback\ | - | Callback when value changes | | Label | string? | null | Switch label text | | Disabled | bool | false | Whether the switch is disabled | | Color | SbColor | SbColor.Primary | Switch accent color when on | | Size | SbSize | SbSize.Md | Switch size (Sm, Md, Lg) | | HelperText | string? | null | Helper text shown below the label | | Id | string? | null | Element ID for the input | | Class | string? | null | Additional CSS classes | | Style | string? | null | Inline styles | | AdditionalAttributes | Dictionary\? | null | Additional HTML attributes (CaptureUnmatchedValues) | ## Events | Event | Type | Description | |-------|------|-------------| | ValueChanged | EventCallback\ | Fired when the switch value changes | ## Templates / Slots (RenderFragments) | Slot | Type | Description | |------|------|-------------| | ChildContent | RenderFragment | Custom label content (takes precedence over Label parameter) | ### Template Usage Examples #### Custom Label ```razor Dark Mode ``` ## CSS Classes - `sb-switch` - Base class - `sb-switch--{color}` - Color variant (primary, success, warning, danger, etc.) - `sb-switch--{size}` - Size variant (sm, md, lg) - `sb-switch--checked` - On state - `sb-switch--disabled` - Disabled state - `sb-switch__input-wrapper` - Wrapper around input - `sb-switch__input` - Native input - `sb-switch__track` - Background track - `sb-switch__thumb` - Sliding thumb - `sb-switch__text` - Wrapper for label and helper - `sb-switch__label` - Label text - `sb-switch__helper` - Helper text ## Accessibility - Uses native `` with `role="switch"` - `aria-checked` indicates current state - Keyboard accessible (Space to toggle) - Label wraps input for expanded click area ## Examples ### Basic Usage ```razor ``` ### Color Variants ```razor ``` ### Settings Panel ```razor
Notifications
``` ### Disabled States ```razor ``` ### With Rich Label ```razor
Auto-save Automatically save changes every 5 minutes
``` ### Controlled Switch ```razor @code { private bool isPublic; private async Task OnPublicChanged(bool value) { if (value) { var confirmed = await DialogService.Confirm( "Making your profile public will allow anyone to view it."); if (confirmed) { isPublic = true; } } else { isPublic = false; } } } ```