GooseUI

Components

Toggle


Toggle is a two-state button. It exposes its state through aria-pressed. Use it for settings that can be switched on and off. It supports controlled and uncontrolled state.

Preview

Installation

npx shadcn@latest add @gooseui/toggle
pnpm dlx shadcn@latest add @gooseui/toggle
yarn dlx shadcn@latest add @gooseui/toggle
bunx --bun shadcn@latest add @gooseui/toggle

Usage

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

<Toggle>Bold</Toggle>

Examples

<Toggle
  onPressedChange={(on) =>
    customToast.info(`Bold: ${on ? "on" : "off"}`)
  }
>
  Bold
</Toggle>

Icon only

<Toggle
  size="icon"
  aria-label="Bold"
  onPressedChange={(on) =>
    customToast.info(`Bold: ${on ? "on" : "off"}`)
  }
>
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
    <path d="M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8" />
  </svg>
</Toggle>

{/* Star fills when pressed */}
<Toggle size="icon" variant="outline" aria-label="Favorite" className="data-[state=on]:[&_svg]:fill-current">
  <StarIcon />
</Toggle>

Icon and text

<Toggle variant="outline" className="px-3">
  <BoldIcon />
  Bold
</Toggle>

Props

PropTypeDefaultDescription
onPressedChange(pressed: boolean) => void-Called on press with the new state.
size"default" | "sm" | "lg" | "icon""default"Size. The icon option gives a 36×36 square button for a single icon; always set aria-label.
classNamestring-Additional CSS classes.