IconButton
A control that is an icon and nothing else.
Examples
Playground
Variant
Visual weight. `ghost` is the one both products use most: a bare glyph that grows a surface on hover.
Tone
What the action means, at every variant (see Tone × Variant).
Size
Three sizes, and each is measured rather than chosen. `md` is 28px, which is what **both** products already draw their default icon button at, agreeing to the pixel, and is already `control-height-sm`. Below that they disagree: core has 22px, vault has 24px and 20px. Three answers from two products is not evidence for any of them, so `sm` takes the one that is also a rule: **24px, the WCAG 2.5.8 AA minimum target size**. That makes core's 22px and vault's 20px both under the floor, and neither was ported up. `lg` is 36px, `control-height-md`, the height of a default `Button`, so an icon-only action can stand level with a labelled one beside it.
States
Every state side by side. Hover, focus and pressed are forced, so they can be reviewed without a pointer.
Tone by variant
Every combination works, as Button's does.
Install
npx shadcn add @hipuku/icon-buttonUsage
import { IconButton } from '@/components/haus/components/IconButton'
<IconButton icon={<SettingsIcon />} label="Settings" variant="ghost" />API
IconButton also takes the button's own attributes and forwards its ref. className lands on the
root.
| Prop | Type | Description |
|---|---|---|
iconrequired | React.ReactNode | The icon. Required, and the only child: an icon button with a label is a Button, and passing one here would silently produce a square control with text overflowing it. |
labelrequired | string | What it does, for anyone who cannot see the icon. Required, because the accessible name cannot come from the content the way Button's does: an SVG contributes nothing, so without this the control announces as "button" and nothing else. Both products got this right per-site and neither had anything enforcing it. |
variant | "primary" | "secondary" | "ghost" | |
tone | "neutral" | "info" | "success" | "warning" | "error" | |
size | "sm" | "md" | "lg" | |
asChild | false | |
loading | boolean |
Variants and tones
primary, secondary and ghost, with secondary the default and ghost the one for toolbars.
Every tone works at every variant, as on Button.
Sizes
size | Height | Use it for |
|---|---|---|
sm | 24px | Dense rows. The smallest size that meets the WCAG minimum target |
md | 28px | The default |
lg | 36px | Beside a default Button, so the two stand level |
IconButton's sizes are one step smaller than Button's of the same name. Next to a md Button, use
a lg IconButton.
Loading
loading swaps the icon for a spinner. It keeps its focus and does not run onClick while it
loads. It is type="button" unless you set type="submit".
Accessibility
labelis required: an icon has no accessible name of its own, solabelis what is announced.- The icon is hidden from screen readers, so it never adds a second name.
- For a link, pass the anchor as the single child with
asChild. The label still applies.