Rime

Toggle

A two-state button, pressed or not, for toolbar formatting and view options.

Toggle is a real <button> with aria-pressed: quiet at rest, washed in the accent with a hairline when pressed. ghost (the default) has no edge at rest, for toolbars; outline keeps a hairline box, for a lone option such as "Show archived".

Use Switch for a setting that applies at once and reads as on or off; use Checkbox inside a form that is submitted.

Installation

npx shadcn@latest add KezLahd/rime/toggle

Also installs: base.

Usage

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

<Toggle aria-label="Bold" icon={<Bold size={16} />} pressed={bold} onPressedChange={setBold} />

Examples

Icon, text and disabled

API

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

Toggle

Toggle props
PropTypeDefaultDescription
pressedbooleanControlled pressed state. Leave unset (with defaultPressed) for uncontrolled.
defaultPressedbooleanfalse
onPressedChange(pressed: boolean) => void
variant"ghost" | "outline""ghost"ghost (default) shows no edge at rest; outline keeps a hairline box.
size"sm" | "md""md"
iconReactNodeAn icon before the label. An icon-only toggle needs aria-label.

Also accepts the native attributes of AriaAttributes, ButtonHTMLAttributes, DOMAttributes, HTMLAttributes.

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.

Toggle per-component tokens
TokenDefaultLive value
--toggle-height-mdvar(--control-h-md)…
--toggle-height-smvar(--control-h-sm)…
--toggle-inkvar(--ink-muted)…
--toggle-on-bgvar(--wash-active) / var(--surface-solid)…
--toggle-on-inkvar(--ink-brand)…
--toggle-on-linevar(--line-brand-strong)…
--toggle-radiusvar(--r-md) / var(--r-sm)…

System tokens it reads

Toggle system tokens
TokenDefaultLive value
--border-wtokens.css…
--control-h-mdtokens.css…
--control-h-smtokens.css…
--densitytokens.css…
--durtokens.css…
--easetokens.css…
--focus-ringtokens.css…
--font-bodytokens.css…
--ink-brandtokens.css…
--ink-disabledtokens.css…
--ink-headingtokens.css…
--ink-mutedtokens.css…
--linetokens.css…
--line-brand-strongtokens.css…
--line-inputtokens.css…
--r-mdtokens.css…
--r-smtokens.css…
--recess-filltokens.css…
--rgb-whitetokens.css…
--shadow-hairline-cardtokens.css…
--shadow-recesstokens.css…
--surface-solidtokens.css…
--text-smalltokens.css…
--wash-activetokens.css…
--wash-hovertokens.css…

Accessibility

  • aria-pressed carries the state, so the label must not change with it: "Bold", pressed or not pressed.
  • An icon-only toggle needs aria-label.

Do and don't

Do

  • Keep the label constant; the pressed state says the rest.

Don't

  • Don't use a Toggle to trigger a one-off action; that is a 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 toggle.md

Related: toggle-group, switch