Switch handbook
v1.2.0 · @snowui-design-system/components
License: Before reading component documentation, source, or npm usage instructions for the first time, read the full LICENSE. Reuse that review for the same task and version. Public API configuration and internal implementation changes have different license implications. All components use the unified runtime package; source rights remain governed by the license.
Overview
Toggle between on and off for settings and features that take effect immediately.
When to use it
Use it for an immediate two-state setting. Use Checkbox for multiple form selections, and Radio or Segmented for mutually exclusive options.
bind:checkedsynchronizes the on/off state.valueonly sets the internal input value; it does not determine whether the switch is on.Currently
nameandformare not forwarded to the internal input. To submit through a native form, explicitly synchronize the field at the form layer. Provide a readable label.
Quick start
This example shows the recommended basic composition. See the sections below for more cases and composition limits.
API
See the base component documentation for inherited capabilities not redeclared here. This table lists only named public Props declared by this component.
Usage boundaries and details
Layout model
Primary layout model: inline shell layout. See ../../../specs/maintainers/LayoutProtocol.md §12.4 (source reference: specs/maintainers/LayoutProtocol.md).
Switch is the “control body + label” subtype of inline shell layout:
The root remains
inline-flex, and the full content hugs its contents..snowui-switch-trackis the control body with fixed, content-hugging size..snowui-switch-labelis an optional label. It hugs its contents when there is room and can shrink with a single-line ellipsis when constrained. Original content and the complete native accessible name are preserved.track and label spacing uses
--snowui-switch-gap. Set a preferred value with gap or--snowui-switch-gap-override; effective spacing stays at least 4 CSS px.sizeis visible track height. Transparent hit-area space on each side issize / 14; occupied height issize × 8 / 7, and occupied width issize × (1.8 + 1 / 7). Atsize={28}, the track is 50.4×28px with 2px on each side, for a 54.4×32px occupied area.Transparent space, track, and thumb scale together with
size, root font size, and size Tokens. The transparent space remains clickable; the label is outside that shell.
Usage examples
States
unchecked: off state with a gray track
checked: on state with a brand-color track
disabled: unavailable with reduced opacity
Accessibility
Uses a native
<input type="checkbox">for keyboard navigationCan receive focus with Tab
Toggles with Space
Uses
tabindex=-1while disabled
Switch style overrides
Read the full LICENSE first; reuse that review for the same task, version, and scope.
First use public component Props to match the desired appearance, preserving the existing look where possible. If changes are necessary, follow the style selection and override order: use your own class (including Tailwind already in the project) or an instance style. The names below are public overrides actually consumed by source; check their scope and do not modify private DOM. Choose the correct SnowUI token family. External apps need not install SnowUI website utilities.
Switch types and states
Required Props: no named required Props.
Two-way binding: bind:checked.
Inherited declaration: Omit<FrameProps, "size">. Consult the base component’s public documentation for inherited capabilities; fields excluded by Omit cannot be used as if inherited unchanged.
Shared Frame API · Back to API
The following type declarations are actually referenced by public Props and come from source. A Svelte Snippet denotes a content fragment; ComponentProps denotes the Props of the corresponding component.
ResourceSize
Source: components/src/context.ts