Toggle

Loading...

Installation

Add the component with the CLI.

npx shadcn@latest add @intentui/toggle

Manual installation

Install the dependencies, then copy the component source into your project.

npm install react-aria-components tailwind-variants cn

Examples

Intent

Customize the look of the toggle button using the intent prop.

Loading...

Size

Adjust the toggle button's size using the size prop.

Loading...

Controlled

Manage the toggle button's state with the isSelected prop.

Loading...

Disabled

Set isDisabled to disable the toggle button.

Loading...

Touch hitbox

For icon-only buttons, use a sq-* size and the touch-target utility to increase the interactive area.

@utility touch-target {
  position: relative;
  &::before {
    content: "";
    position: absolute;
    display: block;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    min-height: 44px;
    min-width: 44px;
    z-index: 9999;
  }
}

Component API

Toggle

Toggle extends the React Aria Components <ToggleButton> component.

classNamestring
intent"outline" | "plain"
Default: plain
isCircleboolean
Default: false
size"xs" | "sm" | "md" | "lg" | "sq-xs" | "sq-sm" | "sq-md" | "sq-lg"
Default: md

See the React Aria for the full API reference.

Design