# IconButton

```tsx
import { IconButton } from '@tangible/ui';
```

Interactive docs and examples: [IconButton in Storybook](https://design.tangible.one/?path=/docs/primitives-iconbutton--docs).

## IconButton props

| Prop | Type | Default | Description |
| - | - | - | - |
| `icon` | `IconSource` | | Icon to display: a registry path or an icon component. Required — this is the button's visual content. |
| `label` | `string` | | Accessible label. Required — icon-only buttons must have a label for screen readers since there's no visible text. |
| `badge?` | `number` | | A count on the button's corner: unread notifications, items in a cart. Above `badgeMax` it shows "99+". `0`, a negative or a non-number shows nothing, so `badge={items.length}` needs no guard. The count is part of the button's name, not only its look: "Notifications, 5 new" (`labels.badgeCount`). The full count is spoken even when the badge is capped. Anything that replaces the name replaces the count with it: an `aria-label` or `aria-labelledby` (a dev warning fires), and `loadingLabel`, which is the whole busy name. A change of count is NOT announced: the name changes silently on a button the user isn't on. If people need to know about an arrival right away, tell them with your own status message (a Toast). The badge overhangs the button's end edge (a "99+" by about 10px at `sm`) and paints above later siblings, so leave a gap after a badged button. Its colour doesn't follow `theme`: it is `--tui-icon-button-badge-bg` (primary by default) on every button. Set `--tui-icon-button-badge-ring` to the surface the button sits on (a header) so its cut-out blends in. |
| `badgeDot?` | `boolean` | `false` | Show the badge as a dot instead of a number: "there's something new" without a count, or a quieter look for one. With a `badge` count as well, the dot still speaks the count in the name. |
| `badgeMax?` | `number` | `99` | The largest count the badge shows; above it, the badge reads "99+". At `xs`, consider 9: a wide count overhangs a small button a long way. Whole numbers of 1 or more. |
| `className?` | `string` | | Additional CSS class names. |
| `disabled?` | `boolean` | | Disabled state. |
| `href?` | `string` | | Only in some variants; the others reject it. |
| `labels?` | `IconButtonLabels` | | Override default strings for i18n, and opt in to loading announcements (`loadingStart` / `loadingEnd`, empty by default). The button's name is `label`; the busy name is `loadingLabel`. |
| `loading?` | `boolean` | | Loading state: shows a spinner and blocks activation while keeping the button focusable (`aria-disabled`, not native `disabled`), so a keyboard user who triggered it keeps their place. Only `onClick` is guarded: put the action there, not in `onKeyDown`/`onPointerDown`. By default the start and end of loading aren't announced: the busy name ("Save, loading") is set on the focused button, which screen readers rarely re-read, and it reverts silently. Opt in with `labels={{ loadingStart: 'Saving…', loadingEnd: 'Saved' }}` to speak each transition through a pre-mounted polite live region (portaled, so it never becomes a DOM sibling of the button). If the button unmounts when the action completes, the end can't be spoken from here: confirm through your own status message (a Toast). With `loadingStart`, don't set `aria-busy` on an ancestor of the button: NVDA and Chromium hold live-region output under a busy ancestor. Test with a screen reader: some also re-read the busy name ("Save, loading"), which can double up with `loadingStart`. While loading, the button stays focusable, so it mutes its colors rather than dimming the whole element: the focus ring keeps full contrast. |
| `loadingLabel?` | `string` | `` `${name}, loading` (English), where `name` includes any badge `` | Accessible label override during loading state. For i18n support. It is the whole busy name: include the badge count yourself if it matters. |
| `pressed?` | `boolean` | | Pressed state for toggle buttons. When true, applies aria-pressed="true" and active styling. |
| `shape?` | `"circle" \| "square"` | `'square'` | Button shape. Use `'circle'` for avatar-adjacent actions, FABs, or anywhere a round affordance is expected. |
| `showTooltip?` | `boolean` | `false` | Show the label as a tooltip on hover. Since icon-only buttons have no visible text, enabling this helps sighted users discover what the button does. Recommended for most standalone icon buttons. Can be omitted in toolbars where a shared Tooltip provider handles it, or where adjacent visible text already communicates the action. |
| `size?` | `"lg" \| "md" \| "sm" \| "xs"` | `'sm'` | Size of the button. `'xs'`: 24px — below WCAG 2.5.8 minimum target size (24×24 CSS px). Use only in dense, mouse-first UIs (toolbars, table rows) where touch is not expected. Consider pairing with adequate spacing or a larger touch target via padding/margin. `'sm'`: 32px (default); `'md'`: 40px; `'lg'`: 48px |
| `theme?` | `"danger" \| "info" \| "neutral" \| "primary" \| "secondary" \| "success" \| "warning"` | `'secondary'` | Semantic color theme. Note: Defaults to 'secondary' (unlike Button which defaults to 'primary') because IconButtons are typically used for toolbar/utility actions. |
| `tooltipSide?` | `"bottom" \| "left" \| "right" \| "top"` | `'top'` | Tooltip placement side. |
| `variant?` | `"ghost" \| "outline" \| "solid"` | `'ghost'` | Visual style variant. `'solid'`: Filled background; `'outline'`: Border only, transparent background; `'ghost'`: No border or background, icon only — has no at-rest visual affordance. Best suited for toolbar groups, icon bars, or other contexts where surrounding UI makes the interactive nature obvious. |

Also accepts the standard attributes of `AnchorHTMLAttributes` and `ButtonHTMLAttributes` (`data-*`, `aria-*`, event handlers), passed to the element it renders.

## Other exports

- `defaultIconButtonLabels`: `Required<IconButtonLabels>`

## Examples

- [Neutral](https://design.tangible.one/?path=/story/primitives-iconbutton--neutral): `neutral` in every variant, resting and pressed: the base look on the
  neutral ladder, so it stays gray when a host brands secondary.

- [Badge](https://design.tangible.one/?path=/story/primitives-iconbutton--badge): A count or dot on the icon's corner, for unread notifications or a cart. The
  badge is hidden from assistive tech and its meaning goes into the button's
  name, so the bell below is "Notifications, 5 new" and the capped one still
  says 120. See the `badge` prop for the rules.

  The header row shows the wiring for a coloured surface: set
  `--tui-icon-button-badge-ring` to the header's background so the cut-out
  blends in, and `--tui-icon-button-badge-bg` / `-fg` for a red badge. The
  colour doesn't follow `theme`.

Other stories: Playground, Variants, Themes, Sizes, Common Use Cases, States, Pressed State (Toggles), As Link, Circle Shape, With Tooltip ([interactive page](https://design.tangible.one/?path=/docs/primitives-iconbutton--docs)).

## Component API tokens

Read via fallback, never declared. Set one on an ancestor to restyle every instance under it.

- `--tui-icon-button-bg`
- `--tui-icon-button-fg`
- `--tui-icon-button-border`
- `--tui-icon-button-border-width`
- `--tui-icon-button-radius`
- `--tui-icon-button-bg-interact`
- `--tui-icon-button-fg-interact`
- `--tui-icon-button-bg-pressed`
- `--tui-icon-button-fg-pressed`
- `--tui-icon-button-badge-bg`
- `--tui-icon-button-badge-fg`
- `--tui-icon-button-badge-ring`

---

Interactive version: https://design.tangible.one/?path=/docs/primitives-iconbutton--docs
