← All proposals

Icon Button

Starting point for an IconButton proposal.

Extends a PDS componentOpen in Storybook

proposals/IconButton/IconButton.mdx52 lines · View on GitHub
import { Canvas, Controls, Meta, Title } from '@storybook/addon-docs/blocks';

import * as IconButtonStories from './IconButton.stories';

<Meta of={IconButtonStories} name='Usage' />

<Title />

## Purpose

The PDS Icon Button, copied as the base for this proposal. It adds three things: `variant='agentic'` (the AI gradient painted as the border, for an action the agent does), `variant='primary'` (filled like a primary Button) with an `isWorking` state, which together make the Send button of a composer, and a `2xs` size.

## Usage

- `variant="agentic"` is always bordered with the AI gradient, so `hasBorder` does not apply to it.
- `variant="primary"` is for the main action of a toolbar, such as Send. Send has three states, made from the props the button already has: `iconName="paperPlane"` to send, `isWorking` while the request is in flight (a spinner, disabled, `aria-busy`), and `iconName="stop"` to stop a running response. Update `ariaLabel` with the state.
- `hasBorder` does not apply to `agentic` or `primary`; both draw their own look.

## Accessibility

- It is a native `button`. `ariaLabel` is required and names the action, since there is no visible text.
- Keyboard: Tab to focus, Enter or Space to activate. Focus shows an outline in `--pds-color-interactive-focus` (the primary variant offsets it by 1px).
- `isWorking` sets `aria-busy` and disables the button; the spinner inside is decorative and the button's label does not change by itself. Change `ariaLabel` with the state (for example "Send message", then "Sending message", then "Stop response"), so the new state is what is announced. There is no separate working-label prop.
- `isPressed` maps to `aria-pressed`.
- The tooltip repeats `ariaLabel` for sighted pointer users. With `hasTooltip={false}`, or while disabled or working, `ariaLabel` is set as the `title` attribute instead.
- The gradient border and the icon are decorative; the state is never conveyed by color alone.
- Not checked: no a11y panel or contrast run was made on these stories in light or dark.

## Sizes

| Size          | Box  | Token                            | Icon       | Spinner (`isWorking`) |
| ------------- | ---- | -------------------------------- | ---------- | --------------------- |
| `2xs` (new)   | 24px | `--pds-spacing-xl`               | `s`, 14px  | `s`                   |
| `xs`          | 28px | `--pds-spacing-button-height-xs` | `m`, 16px  | `s`                   |
| `s` (default) | 32px | `--pds-spacing-button-height-s`  | `m`, 16px  | `m`                   |
| `m`           | 40px | `--pds-spacing-button-height-m`  | `xl`, 20px | `l`                   |

`2xs` is for dense rows, such as the tool icons on an Agent Tree card. 24px is the smallest box that meets the WCAG 2.2 minimum target size (24 by 24), so there is no smaller size; the tooltip offset is 4px. The Spinner has no size under `s`.

## Implementation

See the table below for the available props. The other stories show every variant and state.

- `buttonType` — Sets the `type` attribute on the button (default `button`).
- `icon2Name` — Which icon to render second. If this is set, the button will be animated.
- `pressedIconName` — Icon to display when `isPressed` is true. When not set, `iconName` is used in both states.

<hr />

<Canvas of={IconButtonStories.Default} />
<Controls of={IconButtonStories.Default} />