Switch
Turns something on or off right now. There is no Save button: moving it is the action.
import { Switch, SwitchSkeleton } from '@sypnia/ui/react'
Applies at once
Turn it off: the status in the corner changes with it.
Realtime
Sending changesCode
import { useState } from 'react';
import { Panel, Status, Switch } from '@sypnia/ui/react';
// No Save button: turning it on is the action.
export default function AppliesAtOnce() {
const [on, setOn] = useState(true);
return (
<Panel title="Realtime" actions={<Status tone={on ? 'ok' : 'neutral'} live={on}>{on ? 'Sending changes' : 'Off'}</Status>}>
<Switch label="Send changes of orders to connected apps" description="Apps see a new order the moment it is saved." checked={on} onChange={(e) => setOn(e.target.checked)} />
</Panel>
);
} A list of settings
Labels at the start, switches lined up at the end.
Email me when
Code
import { Panel, Switch } from '@sypnia/ui/react';
export default function List() {
return (
<Panel title="Email me when">
<div className="sy-stack">
<Switch label="A backup fails" defaultChecked />
<Switch label="The project reaches 80% of its storage" defaultChecked />
<Switch label="Someone joins the team" />
</div>
</Panel>
);
} Disabled
On and off, each with the reason in its description.
Code
import { Switch } from '@sypnia/ui/react';
export default function States() {
return (
<div className="sy-stack">
<Switch label="Daily backups" description="Included in every plan. They cannot be turned off." disabled defaultChecked />
<Switch label="Point-in-time recovery" description="Available on the Pro plan." disabled />
</div>
);
} Skeleton
The real piece and its skeleton: the same box, so nothing moves when the data arrives.
Code
import { Switch, SwitchSkeleton } from '@sypnia/ui/react';
// A setting whose value is still loading. The skeleton has the same box as the real one, so nothing moves when the data arrives.
export default function Skeleton() {
return (
<div className="sy-stack">
<Switch label="Backups every night" description="Kept for 7 days." defaultChecked />
<SwitchSkeleton description />
</div>
);
} When to use it
Use it when
- A setting that applies at once: a feature, a notification, a connection.
- The label names the thing that is on or off, and stays the same in both positions.
Do not use it when
- The change is saved later with a form: that is a Checkbox.
- Turning it on starts something that cannot be undone or costs money: use a Button and a ConfirmDialog.
- It chooses between two different things (table or cards): SegmentedControl.
For everyone
- It is announced as a switch, «on» or «off». Space toggles it, and pressing the label does too.
- The light and the position both show the state: colour is never the only sign.
- If the change can fail, say so with a toast or an Alert and move the switch back.
Props
| Switch | Type | Default |
|---|---|---|
labelrequired | ReactNode | |
description | ReactNode |
| SwitchSkeleton | Type | Default |
|---|---|---|
description | boolean |