Toggle
Switches something on or off. Two looks: switch and checkbox. Both are a standard toggle underneath.
Usage
Web (React)
const [wifi, setWifi] = useState(true);
const [agree, setAgree] = useState(false);
return (
<>
<DotwearToggle checked={wifi} onChange={setWifi}>
Wi-Fi
</DotwearToggle>
<DotwearToggle variant="checkbox" checked={agree} onChange={setAgree}>
I agree to the terms
</DotwearToggle>
</>
);
iOS (SwiftUI)
Toggle("Wi-Fi", isOn: $wifi)
.toggleStyle(.dotwear) // switch
Toggle("I agree to the terms", isOn: $agree)
.toggleStyle(.dotwear(.checkbox))
Variants
| Variant | Use for |
switch | Settings that apply immediately (default) |
checkbox | Forms that are submitted together, or multiple selection |
States
| State | Appearance |
| off | Background bg, one-dot shadow |
| on | Background primary (switch knob on the right / check mark) |
| pressed | Shadow removed, body shifts down by one dot |
| focused | One-dot focus ring |
| disabled | Disabled colors |
React API
| Prop | Description |
variant="switch" | "switch" (default, role="switch") or "checkbox" |
checked / onChange(checked, event) | onChange receives the new boolean first, so onChange={setWifi} works |
children | The label. Clicking it toggles too. Without a visible label, pass aria-label |
…input props | Any checkbox <input> attribute (name, value, disabled, defaultChecked, …) |
SwiftUI API
| API | Description |
.toggleStyle(.dotwear) | Switch |
.toggleStyle(.dotwear(.checkbox)) | Checkbox |
Accessibility
- Web: a standard checkbox <input> (role="switch" for the switch) wrapped in a <label>, so Space toggles it and clicking the label works.
- iOS: VoiceOver announces it exactly like a standard Toggle ("Switch, on"), for both looks.