Skip to content

Components

Switch

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

Markdown
Latest changeNewv1.0.0First release, in @vitrumui/react/controls/switch.All changes →
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

npm install @vitrumui/react
Peer: React 19

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

Colours
switch-colors.tsx

color is the track while on; without it the switch is the kit's blue. The knob stays white. Without onChange a switch keeps its own state, starting from checked.

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.