npx shadcn@4.23.1 add @goop/trail-icon-buttonIcon button
FreeA button whose only visible label is one icon, for toolbars, rows and headers, for React and Tailwind CSS. Free, MIT.
What an agent sees
- IconButtonIconThe single icon inside an IconButton
import { IconButton, IconButtonIcon } from '@/components/ui/goop/icon-button';
<div className="flex items-center gap-2">
<IconButton variant="ghost" size="sm" aria-label="More">
<IconButtonIcon icon="dots" />
</IconButton>
<IconButton variant="outline" aria-label="Archive note" loading>
<IconButtonIcon icon="archive" />
</IconButton>
<IconButton variant="ghost" aria-label="Archive">
<IconButtonIcon icon="archive" />
</IconButton>
<IconButton variant="ghost" aria-label="Search" tooltipKeys={['⌘', 'K']}>
<IconButtonIcon icon="search" />
</IconButton>
<IconButton variant="ghost" aria-label="Copy" tooltip={false}>
<IconButtonIcon icon="copy" />
</IconButton>
</div>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 only visible label is one icon, for toolbars, rows and headers.
- Also called: icon-only button.
When not to use
- It still takes a spoken name, and 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/trail-icon-buttonAdd the Goop Icon button to this project. The install steps are at https://goop.so/docs/install.mdUsage
import { IconButton, IconButtonIcon } from '@/components/ui/goop/icon-button';
<div className="flex items-center gap-2">
<IconButton variant="ghost" size="sm" aria-label="More">
<IconButtonIcon icon="dots" />
</IconButton>
<IconButton variant="outline" aria-label="Archive note" loading>
<IconButtonIcon icon="archive" />
</IconButton>
<IconButton variant="ghost" aria-label="Archive">
<IconButtonIcon icon="archive" />
</IconButton>
<IconButton variant="ghost" aria-label="Search" tooltipKeys={['⌘', 'K']}>
<IconButtonIcon icon="search" />
</IconButton>
<IconButton variant="ghost" aria-label="Copy" tooltip={false}>
<IconButtonIcon icon="copy" />
</IconButton>
</div>- Fits: list, schedule (their recipes).
- Also known as: Button size="icon".
- The default look is
outline(a ring); the filled accent one isvariant="primary", the quiet one most rows and toolbars usevariant="ghost". - height, width, padding, gap, corner, border, background, shadow, text, motion: add no class for these.
API reference
| Option | Type | What it does |
|---|---|---|
| variant | outline | ghost | primary | overlay = outline | |
| shape | pill | rounded | pill-end | pill-start = pill | |
| size | xs | sm | md | lg = md | |
| 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-label when left out; other words; false for 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. |
| type? | 'button' | 'submit' | 'reset' | |
| onClick? | (event: MouseEvent) => void | |
| disabled? | boolean |
| Part | What it is |
|---|---|
| IconButtonIcon | The single icon inside an IconButton; name the button with aria-label, not the icon; icon: IconName — A pack icon name; box?: { w: number; h: number } — The glyph's box in CSS px, { w, h }: 14 by 14 (16 by 16 on the 32 and 20 px buttons) unless given |
- Class recipes (cva): iconButtonVariants (IconButton)
- data-slot values (to select a part by): icon-button, icon-button-icon, icon-button-spinner
Keyboard
| Key | What it does |
|---|---|
| Enter | Activate |
| Space | Activate |
Accessibility
- The native element answers the keyboard.
- hover, active, focus, focus-visible, focus-within: the browser's own (:hover, :active, :focus, :focus-visible, :focus-within): write nothing
Its states are drawn from attributes and props, so assistive technology and your agent read the same thing:
| State | Drawn by |
|---|---|
| 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.
- How the theme moves, and how to move your own parts the same way: Motion.
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.