Switch

Toggle switch for boolean settings. Uses native input[type=checkbox] under the hood.

With label and description

import { useState } from 'react'
import { Switch } from '@canarist/ui'

function Example() {
  const [enabled, setEnabled] = useState(true)
  return (
    <Switch
      label="Email notifications"
      description="Receive digest emails every morning."
      checked={enabled}
      onChange={(e) => setEnabled(e.target.checked)}
    />
  )
}

Sizes

<Switch label="Small" size="sm" checked={on} onChange={(e) => setOn(e.target.checked)} />
<Switch label="Medium" size="md" checked={on} onChange={(e) => setOn(e.target.checked)} />

Disabled

<Switch label="Disabled" checked disabled />

Reference

PropTypeDefaultDescription
labelstringLabel shown next to the toggle.
descriptionstringSecondary text below the label.
size'sm' | 'md''md'Physical size of the toggle.
checkedbooleanControlled checked state.
onChangeReact.ChangeEventHandler<HTMLInputElement>Called when the switch is toggled. Use e.target.checked to read the new value.
disabledbooleanDisable the switch.