npx shadcn@4.23.1 add @goop/meadow-icon-buttonIcon button
FreeA button whose one visible label is a pack icon, for toolbars, rows and headers, with a spoken name, for React and Tailwind CSS. Free, MIT.
What an agent sees
- IconButtonIconThe single icon inside an IconButton
- IconButtonCaptionThe small caption under an icon button
import { useState } from 'react';
import { IconButton, IconButtonCaption, IconButtonIcon } from '@/components/ui/goop/icon-button';
function WeekHeader({ onStep, onAdd }: { onStep: (n: number) => void; onAdd: () => void }) {
return (
<div className="flex items-center gap-1">
<div className="flex gap-0.5">
<IconButton aria-label="Previous week" onClick={() => onStep(-1)}>
<IconButtonIcon icon="chevron-left" />
</IconButton>
<IconButton aria-label="Next week" onClick={() => onStep(1)}>
<IconButtonIcon icon="chevron-right" />
</IconButton>
</div>
<IconButton variant="plain" size="sm" aria-label="Add an event" onClick={onAdd}>
<IconButtonIcon icon="plus" box={{ w: 14, h: 14 }} />
</IconButton>
</div>
);
}
function Feedback() {
const [vote, setVote] = useState('');
const press = (s: string) => () => setVote(vote === s ? '' : s);
return (
<div className="flex gap-2">
<IconButton variant="plain" size="xs" aria-label="Good summary" aria-pressed={vote === 'up'} onClick={press('up')}>
<IconButtonIcon icon="tabler-outline:thumb-up" />
</IconButton>
<IconButton variant="plain" size="xs" aria-label="Poor summary" aria-pressed={vote === 'down'} onClick={press('down')}>
<IconButtonIcon icon="tabler-outline:thumb-down" />
</IconButton>
</div>
);
}
function PanelClose({ onClose }: { onClose: () => void }) {
return (
<div className="flex flex-col items-center gap-1.5">
<IconButton variant="filled" size="xl" shape="pill" aria-label="Close settings" aria-keyshortcuts="Escape" onClick={onClose}>
<IconButtonIcon icon="x" />
</IconButton>
<IconButtonCaption>ESC</IconButtonCaption>
</div>
);
}
function NewNote({ busy, onNew }: { busy: boolean; onNew: () => void }) {
return (
<IconButton aria-label="New note" tooltipKeys={['⌘', 'N']} loading={busy} onClick={onNew}>
<IconButtonIcon icon="plus" />
</IconButton>
);
}Switch every look, shape and size and the icon; disable it or make it busy. Press it and the count goes up, never while disabled or busy (busy keeps its box and the focus). Nothing is saved: the press is only counted.
When to use
- A button whose one visible label is a pack icon, for toolbars, rows and headers, with a spoken name.
- Also called: icon-only button.
When not to use
- With words use Button.
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 Icon 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-icon-buttonAdd the Goop Icon button to this project. The install steps are at https://goop.so/docs/install.mdUsage
import { useState } from 'react';
import { IconButton, IconButtonCaption, IconButtonIcon } from '@/components/ui/goop/icon-button';
function WeekHeader({ onStep, onAdd }: { onStep: (n: number) => void; onAdd: () => void }) {
return (
<div className="flex items-center gap-1">
<div className="flex gap-0.5">
<IconButton aria-label="Previous week" onClick={() => onStep(-1)}>
<IconButtonIcon icon="chevron-left" />
</IconButton>
<IconButton aria-label="Next week" onClick={() => onStep(1)}>
<IconButtonIcon icon="chevron-right" />
</IconButton>
</div>
<IconButton variant="plain" size="sm" aria-label="Add an event" onClick={onAdd}>
<IconButtonIcon icon="plus" box={{ w: 14, h: 14 }} />
</IconButton>
</div>
);
}
function Feedback() {
const [vote, setVote] = useState('');
const press = (s: string) => () => setVote(vote === s ? '' : s);
return (
<div className="flex gap-2">
<IconButton variant="plain" size="xs" aria-label="Good summary" aria-pressed={vote === 'up'} onClick={press('up')}>
<IconButtonIcon icon="tabler-outline:thumb-up" />
</IconButton>
<IconButton variant="plain" size="xs" aria-label="Poor summary" aria-pressed={vote === 'down'} onClick={press('down')}>
<IconButtonIcon icon="tabler-outline:thumb-down" />
</IconButton>
</div>
);
}
function PanelClose({ onClose }: { onClose: () => void }) {
return (
<div className="flex flex-col items-center gap-1.5">
<IconButton variant="filled" size="xl" shape="pill" aria-label="Close settings" aria-keyshortcuts="Escape" onClick={onClose}>
<IconButtonIcon icon="x" />
</IconButton>
<IconButtonCaption>ESC</IconButtonCaption>
</div>
);
}
function NewNote({ busy, onNew }: { busy: boolean; onNew: () => void }) {
return (
<IconButton aria-label="New note" tooltipKeys={['⌘', 'N']} loading={busy} onClick={onNew}>
<IconButtonIcon icon="plus" />
</IconButton>
);
}- Fits: frame, list, schedule (their recipes).
- Also known as: Button size="icon".
- IconButtonCaption: Stand the button and its caption in a column, 6 px apart:
<div className="flex flex-col items-center gap-1.5"><IconButton variant="filled" size="xl" shape="pill" aria-label="Close" aria-keyshortcuts="Escape" onClick={onClose}><IconButtonIcon icon="x" /></IconButton> <IconButtonCaption>ESC</IconButtonCaption></div>. The Escape key itself is the layer's (a dialog or a sheet closes on it): the caption only says so. - height, width, gap, corner, border, background, text, motion: add no class for these.
API reference
| Option | Type | What it does |
|---|---|---|
| variant | ghost | plain | filled | outline | primary | overlay = ghost | |
| shape | rounded | pill | pill-start | pill-end = rounded | |
| size | xs | sm | md | lg | xl = md |
- Each option with its sentence: icon-button--options.md
| Part | What it is |
|---|---|
| IconButtonIcon | The single icon inside an IconButton; name the button with aria-label, not the icon; its props: icon-button--icon.md |
| IconButtonCaption | The small caption under an icon button |
- Class recipes (cva): iconButtonVariants (IconButton)
- data-slot values (to select a part by): icon-button, icon-button-caption, icon-button-icon, icon-button-spinner
IconButtonIcon
The single icon inside an IconButton; name the button with aria-label, not the icon.
import { IconButtonIcon } from '@/components/ui/goop/icon-button';Options
- icon: IconName — A pack icon name.
- box?: { w: number; h: number } — The glyph's box in CSS px,
{ w, h }: 16 by 16 (22 by 22 onlg, 20 by 20 onxl) unless the caller sizes it.
IconButton: every option
import { IconButton } from '@/components/ui/goop/icon-button';Options
- variant: ghost (default), plain, filled, outline, primary, overlay
- shape: rounded (default), pill, pill-start, pill-end
- size: xs, sm, md (default), lg, xl
- aria-label: string — The button's name: a glyph-only control has no words to be named by.
- asChild?: boolean = false — Render the button's look on the one child element instead of a
button(a link, a menu's trigger). - tooltip?: string | false — The tooltip: the button's
aria-labelwhen left out; other words;falsefor none. - tooltipKeys?: readonly string[] — A shortcut's keys after the tooltip's words (
['⌘', 'K']). - loading?: boolean = false — The button's action is running: the spinner in the icon's place, and no press reaches
onClick; it keeps the focus. - loadingLabel?: string = 'Loading' — What a reader hears after the button's name while
loading. - Also takes: type?: 'button' | 'submit' | 'reset'; onClick?: (event: MouseEvent) => void; disabled?: boolean
Keyboard
| Key | What it does |
|---|---|
| Enter | Activate |
| Space | Activate |
Accessibility
- The native element answers the keyboard.
- hover, active, focus: the browser's own (:hover, :active, :focus): write nothing
Its states are drawn from attributes and props, so assistive technology and your agent read the same thing:
| State | Drawn by |
|---|---|
| focus-visible | the attribute data-focus-visible |
| pressed | the attribute aria-pressed |
| expanded | the attribute data-state=open |
| open | the attribute data-state=open |
| 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.