Web and native

IconButton in kanso-ui 0.59.0, for React.

import { IconButton } from '@kanso-labs/kanso-ui'

A button that is an icon alone, at four styles and five heights, which can also act as a link or a toggle.

It follows the Material Design icon buttons page: its colour pairs, its sizes and the shape morph from a circle to a rounded square while pressed or once a toggle is chosen. One departure: the outlined border thickens with the size at Button's widths, so an icon button and a button of the same height sit side by side with the same rule. Its container, icon and rule colours and its corner ease between states over the short motion duration, and move at once for a reader who asks for reduced motion.

What you provide

  • children: the icon, drawn 1em square in currentColor, so it follows the size's icon size and the variant's colour.
  • aria-label, required: an icon has no name of its own. Pass undefined only inside a React Aria component that names the button itself.
  • Any other aria-* prop is forwarded to the element.

Props

PropTypeDefaultDescription
aria-label requiredstring | undefined—What the button does, in words. Required rather than optional: an icon on its own has no accessible name, so without this the control announces nothing at all. `undefined` is for a button inside a React Aria component that names it itself — a search field's clear button, a number field's steppers. React Aria takes a prop over its context, so a name written here would replace the one it gives in the reader's locale, and undefined leaves that stand.
childrenReactNode—
classNameClassNameOrFunction<IconButtonState>—A function may compute the class from the button's render state.
disableRipplebooleanfalseDisables the press ripple, and draws the flat pressed layer in its place. The hover layer is unaffected.
pendingLabelstring—The name of the ring shown while the button is pending, for a screen reader. The label it replaces is hidden while it shows. Left out, it is the word for it in the I18nProvider's locale — "Loading" in English.
renderDOMRenderFunction<'button', IconButtonState>—The element to render, given the props it would have carried. React Aria's own form: it has to return the element the component would have rendered itself.
size'lg' | 'md' | 'xl' | 'xs' | 'xxl''md'Control size: `xs` 32px, `md` 40px, `lg` 56px, the same heights `Button` uses, so the two line up beside each other in a row. The icon is 20px at `xs` and 24px above. `xl` and `xxl` are deprecated and render at `lg`, Kanso's largest, with a warning in development; use `lg`. Deprecated sizes. Kanso stops at lg, 56px: xl (96px) and xxl (136px) are deprecated in Kanso, though kanso-ui still accepts them.
styleStyleOrFunction<IconButtonState>—A function may compute the style from the button's render state.
variant'filled' | 'outlined' | 'standard' | 'tonal''standard'`standard` is an ink icon over nothing; `outlined` is inside a 1px ring; `filled` sits on ink and `tonal` on a container.

Also takes the props of ButtonForm, Omit<ButtonDOMProps, 'aria-label' | 'render'>.

Example

import { IconButton } from '@kanso-labs/kanso-ui'

<IconButton aria-label="Add" variant="tonal" onPress={add}>
  <PlusIcon />
</IconButton>

<IconButton aria-label="Star" variant="filled" defaultSelected>
  <StarIcon />
</IconButton>

The design’s classes

k-iconbtn, k-iconbtn--tonal, k-iconbtn--ink, k-iconbtn--outline, k-iconbtn--sm; aria-pressed for toggles; the icon is a k-icon, with k-icon--fill when pressed.

Maps to IconButton in kanso-ui and react-native-kanso-ui.