Skip to content

components/IconButton

import { … } from 'zidane-ui'ui/src/components/IconButton.tsx

sizes xs, sm, md, lg
active, danger, disabled
node icon, badge, render as link
IconToggle in a segment

Components#

IconButtonComponent#

Renders a square icon button with an accessible label. Hover and active states lift it to the raised chip. Use render to draw another element, such as a link, with the same look. The ref goes to the button.

TypeScript
const IconButton: ForwardRefExoticComponent<IconButtonProps & RefAttributes<HTMLButtonElement>>
IconButton props
NameTypeDefaultDescription
active?from IconButtonLookboolean

Toggled on / open: shows as the raised chip.

children?ReactNode

Badges and overlays (an unseen dot, a spinner) over the glyph.

iconReactNode

An icon class (i-ph-*) or a node (SwapIcon, an svg).

labelstring

Accessible name and default tooltip. Required, since the button has no text.

overlay?from IconButtonLookboolean

Room for badges / overlays positioned over the glyph.

render?(props: IconButtonRenderProps) => ReactElement

Render another element with the button's look (a link).

size?from IconButtonLook'xs' | 'sm' | 'md' | 'lg''md'

Button size.

tone?from IconButtonLook'danger' | 'neutral''neutral'

Colour of the glyph. danger turns it red on hover.

ui/src/components/IconButton.tsx:83

Functions#

iconButtonClassFunction#

The IconButton look as a class string, for elements that can't be the component.

TypeScript
function iconButtonClass(look?: IconButtonLook): string
Parameters
NameTypeDefaultDescription
look?IconButtonLook{}

The size, tone and overlay options of the look. Defaults to a md, neutral button without overlay.

string

ui/src/components/IconButton.tsx:47

Interfaces#

IconButtonLookInterface#

Visual options of an IconButton, shared with iconButtonClass.

TypeScript
interface IconButtonLook
IconButtonLook properties
NameTypeDefaultDescription
active?boolean

Toggled on / open: shows as the raised chip.

overlay?boolean

Room for badges / overlays positioned over the glyph.

size?'xs' | 'sm' | 'md' | 'lg''md'

Button size.

tone?'danger' | 'neutral''neutral'

Colour of the glyph. danger turns it red on hover.

ui/src/components/IconButton.tsx:24

IconButtonPropsInterface#

Visual options of an IconButton, shared with iconButtonClass.

TypeScript
interface IconButtonProps extends IconButtonLook, Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children'>
IconButtonProps properties
NameTypeDefaultDescription
active?from IconButtonLookboolean

Toggled on / open: shows as the raised chip.

children?ReactNode

Badges and overlays (an unseen dot, a spinner) over the glyph.

iconReactNode

An icon class (i-ph-*) or a node (SwapIcon, an svg).

labelstring

Accessible name and default tooltip. Required, since the button has no text.

overlay?from IconButtonLookboolean

Room for badges / overlays positioned over the glyph.

render?(props: IconButtonRenderProps) => ReactElement

Render another element with the button's look (a link).

size?from IconButtonLook'xs' | 'sm' | 'md' | 'lg''md'

Button size.

tone?from IconButtonLook'danger' | 'neutral''neutral'

Colour of the glyph. danger turns it red on hover.

ui/src/components/IconButton.tsx:67

IconButtonRenderPropsInterface#

Props IconButtonProps.render receives to spread onto the element it renders.

TypeScript
interface IconButtonRenderProps
IconButtonRenderProps properties
NameTypeDescription
aria-labelstring

Accessible name, taken from label.

childrenReactNode

The icon followed by any badges or overlays.

classNamestring

Classes carrying the button's look, merged with the caller's className.

data-active?''

Set to an empty string while the button is active, otherwise absent.

titlestring

Tooltip text. The title prop, or label when none is given.

ui/src/components/IconButton.tsx:54

Types#

IconButtonSizeType#

Size of an IconButton: xs (20px), sm (24px), md (28px) or lg (32px).

TypeScript
type IconButtonSize = keyof typeof SIZES

ui/src/components/IconButton.tsx:21