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

VariantUse for
switchSettings that apply immediately (default)
checkboxForms that are submitted together, or multiple selection

States

StateAppearance
offBackground bg, one-dot shadow
onBackground primary (switch knob on the right / check mark)
pressedShadow removed, body shifts down by one dot
focusedOne-dot focus ring
disabledDisabled colors

React API

PropDescription
variant="switch""switch" (default, role="switch") or "checkbox"
checked / onChange(checked, event)onChange receives the new boolean first, so onChange={setWifi} works
childrenThe label. Clicking it toggles too. Without a visible label, pass aria-label
…input propsAny checkbox <input> attribute (name, value, disabled, defaultChecked, …)

SwiftUI API

APIDescription
.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.