Rime

Switch

An on/off setting that takes effect immediately, with a loading state while it saves.

Switch is role="switch" on a button. Use it for settings that apply at once; use Checkbox inside forms that are submitted.

Installation

npx shadcn@latest add KezLahd/rime/switch

Also installs: base, spinner.

Usage

import { Switch } from "@/components/ui";

<Switch label="Email me when an invoice is paid" checked={on} onChange={setOn} />

Examples

States

A request is in flight.

API

Generated from the component's TypeScript types and JSDoc (scripts/gen-ui-registry.mjs), so it always matches the source.

Switch

Switch props
PropTypeDefaultDescription
checkedRequiredboolean
onChangeRequired(checked: boolean) => void
labelRequiredReactNode
descriptionReactNode
disabledboolean
loadingbooleanThe change is saving. Blocks input and shows a spinner in the thumb.
idstring
labelPosition"start" | "end""end"Label on the left, switch pushed right: for settings rows.
classNamestring

Theme tokens

Per-component tokens are undeclared by default, so the default shown is the fallback the CSS uses. Set one at :root (or in theme.css) to restyle every instance. Live values are read from this page, so they follow the Rime Studio.

Switch per-component tokens
TokenDefaultLive value
--r-flat5px…

System tokens it reads

Switch system tokens
TokenDefaultLive value
--brand-gradienttokens.css…
--durtokens.css…
--easetokens.css…
--focus-ringtokens.css…
--glow-mdtokens.css…
--glow-smtokens.css…
--ink-bodytokens.css…
--ink-disabledtokens.css…
--ink-mutedtokens.css…
--r-smtokens.css…
--rgb-brand-deeptokens.css…
--rgb-contacttokens.css…
--shadow-speculartokens.css…
--surface-solidtokens.css…
--text-bodytokens.css…
--text-captiontokens.css…

Accessibility

  • aria-checked reflects state; loading sets aria-busy and blocks toggling.

Do and don't

Do

  • Say what is on, not what pressing does: "Email notifications".

Don't

  • Don't use a Switch inside a form that has a submit button.

For AI agents

This page as markdown, rendered from the same registry entry. Point an agent at it (or add .md to this page's URL), or at /llms.txt for the index.

Open switch.md