Toggle
Sharp two-state button that fills signal when pressed; `default` (borderless) and `outline` (keylined) variants.
import { BoldIcon } from "lucide-react";import { Toggle } from "@/registry/okibi/ui/toggle";export default function ToggleDemo() { return ( <Toggle aria-label="Toggle bold"> <BoldIcon /> </Toggle> );}npx shadcn@latest add https://okibi.cndr.dev/r/toggle.jsonInstallation
Install the theme first, then add the component:
npx shadcn@latest add https://okibi.cndr.dev/r/toggle.jsonInstall the required dependencies:
npm install @radix-ui/react-toggle class-variance-authorityCopy the source from the Code tab above into components/ui/toggle.tsx. It uses the cn helper and the okibi theme tokens — install the theme first if you haven't.
Usage
import { BoldIcon } from "lucide-react"
import { Toggle } from "@/components/ui/toggle"
<Toggle variant="outline" aria-label="Toggle bold">
<BoldIcon />
</Toggle>Examples
Outline
The outline variant adds a keyline that snaps to signal on hover; pair the icon with a text label.
import { ItalicIcon } from "lucide-react";import { Toggle } from "@/registry/okibi/ui/toggle";export default function ToggleOutlineDemo() { return ( <Toggle variant="outline" aria-label="Toggle italic"> <ItalicIcon /> Italic </Toggle> );}Pressed
Set pressed/defaultPressed to show the signal-fill on-state statically, in both default and outline variants.
import { StarIcon } from "lucide-react";import { Toggle } from "@/registry/okibi/ui/toggle";export default function TogglePressedDemo() { return ( <div className="flex flex-wrap items-center gap-3"> <Toggle defaultPressed aria-label="Toggle favorite"> <StarIcon /> Favorite </Toggle> <Toggle variant="outline" defaultPressed aria-label="Toggle favorite"> <StarIcon /> Favorite </Toggle> </div> );}API Reference
Toggle
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "default" | "outline" | "default" | Borderless or keylined. |
size | "sm" | "md" | "lg" | "md" | Control size. |
pressed | boolean | – | Controlled pressed state. |
defaultPressed | boolean | false | Initial pressed state (uncontrolled). |
onPressedChange | (pressed: boolean) => void | – | Fires when toggled. |
disabled | boolean | false | Lock the toggle in its current state. |
Accessibility
- Built on Radix
Toggle.Root, so pressed state is exposed asaria-pressedautomatically. - Icon-only toggles have no text — they require an
aria-labeldescribing the action they control. - Focus shows a 2px signal ring with offset;
disabledsetsdisabled:pointer-events-noneand dims toopacity-60. - The pressed look is the signal
primaryfill, an AA-enforced color pair — state isn't carried by a subtle tint alone.
Guidelines
Do
- Use it for a single on/off control whose state persists, like a formatting button.
- Give icon-only toggles an
aria-label, and prefer theoutlinevariant when the control sits on a busy surface. - Drive it with
pressed/onPressedChangewhen the state lives in your own model.
Don't
- Don't use it for an action that fires and forgets — that's a
Button, not a stateful toggle. - Don't group several mutually exclusive toggles by hand; reach for
ToggleGroupso roving focus and selection are handled.
Input OTP
Segmented one-time-code field with sharp mono cells, a 2px signal focus ring on the active slot, and a blinking block caret.
Toggle Group
Segmented control: a strong-bordered bar of Toggles divided by hairline keylines, each filling signal when active. `type="multiple"` for independent toggles, `type="single"` for a one-of-many selector.