Skip to content

Components

Switch

An on/off toggle whose knob swells into a clear lens while it crosses the track.

Markdown
switch.tsx

Use it for

  • A setting that takes effect at once: Wi-Fi, notifications, dark mode.

Not for

  • A choice that is saved later with a form: use Checkbox.
  • More than two states: use Tabs.

Installation

Coming soon
npm install @vitrumui/react
No dependencies

Usage

app.tsx
import { Switch } from '@vitrumui/react/controls/switch'

const [on, setOn] = useState(false)

<Switch label="Notifications" description="Banners and sounds" checked={on} onChange={setOn} />

Tap to flip, or hold the knob and drag it across. Needs three, like Slider.

Examples

Coming soon

API reference

PropTypeDefault
checked

On or off.

booleanfalse
onChange

Called with the new state.

(checked: boolean) => void—
label

Text beside the switch; an empty string leaves the switch alone.

string'Notifications'
description

A second, quieter line under the label.

string—
labelSide

Which side the label sits on.

'left' | 'right''right'
size

Track height 22, 28 or 36 px.

'sm' | 'md' | 'lg''md'
color

The track while on: a hex, rgb() or named colour, not a CSS variable.

string'#3291FF'
theme

Overrides the page theme for this switch.

'light' | 'dark'—
disabled

Dimmed and not interactive.

booleanfalse
lensScale

Size of the travelling lens relative to the resting knob.

number1.55
refraction / knobBounce

How far the lens bends the track; how much the knob overshoots.

number26 / 0.3

Accessibility

  • A <button role="switch"> with aria-checked: Space and Enter flip it.
  • The label is a real <label> tied to the button.
  • With reduced motion the knob simply jumps.