Skip to main content
Version: Next

Switch

A toggle switch for boolean settings. Uses a composed pattern — Switch.Description renders helper text below the label via the description slot.

Import

import { Switch } from '@editora/ui-react';
// or subpath
import { Switch } from '@editora/ui-react/Switch';

Basic Usage

<Switch onChange={(detail) => console.log(detail.checked)}>
Enable alerts
</Switch>

With Description

Use Switch.Description instead of a raw <span slot="description">.

<Switch checked onChange={(detail) => console.log(detail.checked)}>
Enable workspace automations
<Switch.Description>Run triggers when publishing or archiving content.</Switch.Description>
</Switch>

Controlled

const [checked, setChecked] = useState(false);

<Switch checked={checked} onChange={(detail) => setChecked(detail.checked)}>
Auto deploy
<Switch.Description>Deploys on every push to main.</Switch.Description>
</Switch>

Variants

<Switch checked variant="default">Default</Switch>
<Switch checked variant="soft">Soft</Switch>
<Switch checked variant="outline">Outline</Switch>
<Switch checked variant="contrast">Contrast</Switch>
<Switch checked variant="minimal">Minimal</Switch>

Tones

<Switch checked tone="success">Healthy sync</Switch>
<Switch checked tone="warning">Pending approvals</Switch>
<Switch checked tone="danger">Destructive action</Switch>

States

<Switch loading checked>Syncing…</Switch>
<Switch disabled checked>Disabled</Switch>

Props

Switch (root)

PropTypeDefaultDescription
checkedbooleanfalseControlled checked state
disabledbooleanfalseDisables interaction
loadingbooleanfalseShows spinner, disables interaction
requiredbooleanfalseMarks field as required
headlessbooleanfalseHides the track/thumb, renders label only
size'sm' | 'md' | 'lg''md'Switch size
variant'default' | 'soft' | 'outline' | 'contrast' | 'minimal''default'Visual style
tone'brand' | 'success' | 'warning' | 'danger''brand'Accent color
shape'pill' | 'rounded' | 'square''pill'Track border radius
elevation'none' | 'low' | 'high''low'Box shadow depth
labelstringShorthand label (alternative to children)
descriptionstringShorthand description (alternative to Switch.Description)
namestringForm field name
valuestring'on'Form field value
onInput(detail: SwitchDetail) => voidFires on every toggle
onChange(detail: SwitchDetail) => voidFires on committed toggle

Switch.Description

Renders helper text below the label row via slot="description".

PropTypeDescription
childrenReact.ReactNodeDescription content
...restReact.HTMLAttributes<HTMLElement>Passed to inner <span>

Event Detail

type SwitchDetail = {
checked: boolean;
value: string;
name: string;
required: boolean;
};

Notes

  • The description string prop and Switch.Description sub-component are equivalent — use whichever fits your pattern.
  • Elements inside Switch.Description with data-ui-switch-no-toggle (e.g. links) will not trigger the toggle on click.
  • Keyboard: Space/Enter toggles, ArrowLeft/ArrowRight sets off/on, Home/End forces off/on.