npx shadcn@4.23.1 add @goop/meadow-toggle-buttonToggle button
FreeA button that stays pressed until it is pressed again, for React and Tailwind CSS. Free, MIT.
What an agent sees
- ToggleButtonIconThe toggle's icon
import { ToggleButton, ToggleButtonIcon } from '@/components/ui/goop/toggle-button';
function NotesViewToggle({ grouped, onGrouped }: { grouped: boolean; onGrouped: (next: boolean) => void }) {
return (
<div className="flex items-center gap-1">
<ToggleButton aria-label="Group into lists" pressed={grouped} onPressedChange={onGrouped}>
<ToggleButtonIcon icon="text-align-justify" />
</ToggleButton>
<ToggleButton variant="muted" aria-label="Starred notes only" defaultPressed>
<ToggleButtonIcon icon="star" />
</ToggleButton>
<ToggleButton variant="chip">Due date</ToggleButton>
</div>
);
}Press it to hold it down, press again to let it up; switch every look and size, words or icon, and disable it. No notes are filtered: the line under it only says the state.
When to use
- A button that stays pressed until it is pressed again.
- Also called: toggle.
Installation
Paste the prompt below into your coding agent. It reads Goop's install steps, installs the part and its tokens once, then reuses this same Toggle button on every screen instead of drawing a new one: the same height, the same focus ring, the same spacing.
npx shadcn@4.23.1 add @goop/meadow-toggle-buttonAdd the Goop Toggle button to this project. The install steps are at https://goop.so/docs/install.mdUsage
import { ToggleButton, ToggleButtonIcon } from '@/components/ui/goop/toggle-button';
function NotesViewToggle({ grouped, onGrouped }: { grouped: boolean; onGrouped: (next: boolean) => void }) {
return (
<div className="flex items-center gap-1">
<ToggleButton aria-label="Group into lists" pressed={grouped} onPressedChange={onGrouped}>
<ToggleButtonIcon icon="text-align-justify" />
</ToggleButton>
<ToggleButton variant="muted" aria-label="Starred notes only" defaultPressed>
<ToggleButtonIcon icon="star" />
</ToggleButton>
<ToggleButton variant="chip">Due date</ToggleButton>
</div>
);
}- Fits: record, chat: toolbar.
- Also known as: Toggle.
- height, width, padding, gap, corner, background, shadow, text, motion: add no class for these.
API reference
| Option | Type | What it does |
|---|---|---|
| variant | default | muted | chip | outline = default | |
| size | md | lg = md | |
| shape | pill | circle = pill | |
| asChild? | boolean | |
| pressed? | boolean | |
| defaultPressed? | boolean = false | |
| onPressedChange? | (pressed: boolean) => void | |
| disabled? | boolean |
- State: pressed (pressed / defaultPressed / onPressedChange)
| Part | What it is |
|---|---|
| ToggleButtonIcon | The toggle's icon; icon: IconName — A pack icon name; pressedIcon?: IconName — The pack icon drawn instead while the toggle is pressed; none by default |
- Class recipes (cva): toggleButtonVariants (ToggleButton)
- data-slot values (to select a part by): toggle-button, toggle-button-icon
Keyboard
| Key | What it does |
|---|---|
| Enter | Toggle |
| Space | Toggle |
Accessibility
- The behaviour layer under the part answers keys, focus and dismissal: never write your own.
- hover, active, focus, focus-visible: the browser's own (:hover, :active, :focus, :focus-visible): write nothing
Its states are drawn from attributes and props, so assistive technology and your agent read the same thing:
| State | Drawn by |
|---|---|
| pressed | the attribute aria-pressed |
| disabled | the prop disabled |
Motion
- The part sets its own motion: add no transition or animation of your own.
Notes for AI
Give your coding agent this page as text instead of screenshots: the parts, the options, the states and the keys. An agent that reads the real part builds the real part, not a lookalike.