Skip to content

Toggle

Toggle switch for binary on/off settings.

Also known as: switch, toggle switch, on/off switch

View in Storybook

When to use

  • Binary on/off settings where the effect is immediate (e.g. enable notifications). For form checkboxes that require submit, use Checkbox.
  • For card-style toggles, use ToggleCard. For grouping multiple toggles, use ToggleGroup.

Import

tsx
import { Toggle } from '@vacano/ui'

Usage

tsx
const [enabled, setEnabled] = useState(false)

<Toggle
  checked={enabled}
  onChange={(e) => setEnabled(e.target.checked)}
  label="Enable notifications"
/>

With Label

tsx
<Toggle checked={true} onChange={() => {}} label="Dark mode" />

Without Label

tsx
<Toggle checked={false} onChange={() => {}} />

Variants

tsx
<Toggle variant="normal" checked={true} onChange={() => {}} label="Normal" />
<Toggle variant="error" checked={true} onChange={() => {}} label="Error" />

Disabled

tsx
<Toggle disabled checked={true} onChange={() => {}} label="Disabled on" />
<Toggle disabled checked={false} onChange={() => {}} label="Disabled off" />

Props

PropTypeDefaultDescription
checkedbooleanrequiredToggle state
onChangeChangeEventHandler<HTMLInputElement>requiredChange handler
labelReactNode-Label content (text or any renderable node)
variant'normal' | 'error''normal'Visual variant
disabledbooleanfalseDisable toggle
classNamestring-CSS class name for the root element
classnamesToggleClassNames-Custom class names for inner elements
refRef<HTMLInputElement>-Ref to the underlying input element
data-test-idstring-Test identifier attribute

All standard HTML input attributes are also supported (except type, checked, onChange, and className which are controlled by the component).

ClassNames

KeyDescription
inputHidden input element
trackToggle track (background pill)
thumbToggle thumb (sliding circle)
labelLabel text

Released under the MIT License.