Toggle
Toggle a button between pressed and unpressed states.
Installation
pnpm dlx shadcn@4.18.0 add @siteplane/toggleComplete the one-time setup first. Registry JSON lists source files and dependencies.
Usage
import { Toggle } from "@/siteplane/components/toggle";
<Toggle variant="outline">Bookmark</Toggle>;Variants and disabled state
The default variant has no border until it is hovered or pressed; outline adds one. Disabled toggles keep their pressed appearance.
Icon-only toggles
Use padding="icon" for square icon-only toggles and give each one an aria-label that stays the same when it is pressed.
Sizes
Omit size to inherit the provider’s control size.
Controlled state
Pass pressed and onPressedChange when your application owns the state, for example an editor’s current formatting.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
variant | default | outline | default | Surface. |
size | sm | md | lg | xl | provider / lg | Control size. |
padding | default | comfortable | icon | default | Padding or square layout. |
pressed / default | boolean | unset / false | Controlled or initial state. |
on | (pressed, eventDetails) => void | unset | State callback. |
disabled | boolean | false | Prevents interaction. |
lift | boolean | false | Lifts the icon once each time the toggle turns on, for a reaction such as a like. The icon is the first child; reduced motion keeps it still. |
TogglePrimitive exports Base UI Toggle. toggleVariants({size, variant, padding, className}) returns the utility classes Toggle adds beside its stylesheet, with lg size and default variant; the look comes from the kit stylesheet through the attributes Toggle renders. The component also defaults padding to default. Other props and refs follow Base UI Toggle.
Usage notes
Space or Enter toggles the button. Keep the label and icon the same in both states; the pressed state is announced separately. Toggle does not submit a boolean form value; use Checkbox/Switch or serialize application state.