npx shadcn@4.23.1 add @goop/meadow-switchSwitch
FreeAn on/off control for a setting that takes effect at once, for React and Tailwind CSS. Free, MIT.
What an agent sees
import { Switch } from '@/components/ui/goop/switch';
function NotificationSettings({ digest, onDigest }: { digest: boolean; onDigest: (on: boolean) => void }) {
return (
<div className="flex flex-col gap-4">
<div className="flex items-center justify-between gap-4">
<label htmlFor="weekly-digest" className="text-base">
Weekly digest of the Fieldwork notes
</label>
<Switch id="weekly-digest" checked={digest} onCheckedChange={onDigest} />
</div>
<div className="flex items-center justify-between gap-4">
<label htmlFor="visit-reminders" className="text-base">
Remind me the day before a site visit
</label>
<Switch id="visit-reminders" name="reminders" defaultChecked />
</div>
</div>
);
}Press the switch (or Space on it) to turn the digest on and off; switch its size and disable it from the panel. Nothing is saved: the switch only says its state.
When to use
- An on/off control for a setting that takes effect at once.
- Also called: toggle.
When not to use
- For a choice saved with a form use Checkbox.
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 Switch 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-switchAdd the Goop Switch to this project. The install steps are at https://goop.so/docs/install.mdUsage
import { Switch } from '@/components/ui/goop/switch';
function NotificationSettings({ digest, onDigest }: { digest: boolean; onDigest: (on: boolean) => void }) {
return (
<div className="flex flex-col gap-4">
<div className="flex items-center justify-between gap-4">
<label htmlFor="weekly-digest" className="text-base">
Weekly digest of the Fieldwork notes
</label>
<Switch id="weekly-digest" checked={digest} onCheckedChange={onDigest} />
</div>
<div className="flex items-center justify-between gap-4">
<label htmlFor="visit-reminders" className="text-base">
Remind me the day before a site visit
</label>
<Switch id="visit-reminders" name="reminders" defaultChecked />
</div>
</div>
);
}- Fits: flow, settings (their recipes).
- height, width, corner, background, shadow, motion: add no class for these.
API reference
| Option | Type | What it does |
|---|---|---|
| size | md | sm | xs = md | |
| onCheckedChange? | (checked: boolean) => void | Called after onChange with the switch's new state. |
| checked? | boolean | |
| defaultChecked? | boolean | |
| onChange? | (event: ChangeEvent<HTMLInputElement>) => void | |
| value? | string | |
| name? | string | |
| required? | boolean | |
| disabled? | boolean | |
| form? | string |
- State: checked (checked / defaultChecked / onCheckedChange)
- Class recipes (cva): switchVariants (Switch)
- data-slot values (to select a part by): switch
Keyboard
| Key | What it does |
|---|---|
| Space | Toggle |
Accessibility
- The native element answers the keyboard.
- hover, active, focus-visible, checked: the browser's own (:hover, :active, :focus-visible, :checked): write nothing
Its states are drawn from attributes and props, so assistive technology and your agent read the same thing:
| State | Drawn by |
|---|---|
| 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.