Button

A button with an icon, a label, or both. With both, the label slides out on hover and focus.

Usage

The button is a shell: the parts you mount decide what it shows. With Button.IconLabel it rests as a square and the label slides out on hover and focus.

tsx
<Button onClick={save}>
  <Button.IconLabel
    icon={<Button.Icon><MdSave /></Button.Icon>}
    label={<Button.Label>save</Button.Label>}
  />
</Button>

Label only

tsx
<Button onClick={submit}>
  <Button.Label>submit</Button.Label>
</Button>

Icon only

tsx
<Button aria-label="copy" onClick={copy}>
  <Button.Icon><MdContentCopy /></Button.Icon>
</Button>

Reverse

The label stays and the icon slides out. Use it when the text already says what the button does.

tsx
<Button onClick={next}>
  <Button.IconLabel
    reverse
    icon={<Button.Icon><MdArrowForward /></Button.Icon>}
    label={<Button.Label>continue</Button.Label>}
  />
</Button>

Direction

direction="left" slides the hidden part out to the left, for buttons on the right edge of a bar.

tsx
<Button onClick={openSettings}>
  <Button.IconLabel direction="left" icon={<Button.Icon><MdSettings /></Button.Icon>} label={<Button.Label>settings</Button.Label>} />
</Button>

Active and open

tsx
<Button active>…</Button>
<Button open>…</Button>

Disabled and not clickable

disabled dims the button and disables it. clickable={false} makes it inert but leaves it looking normal, which is what a loading button needs.

tsx
<Button disabled>
  <Button.Label>delete</Button.Label>
</Button>

<Button clickable={false}>
  <Button.IconLabel
    icon={<Button.Icon><Spinner /></Button.Icon>}
    label={<Button.Label>saving</Button.Label>}
  />
</Button>

Reference

proptypedefault
as?ElementType"button"the element or component to render
active?booleanfalseprimary border and shadow; visual only
open?booleanfalsekeeps the label out, as on hover; visual only
disabled?booleanfalsenative disabled on a button, aria-disabled on anything else; dimmed
clickable?booleantruefalse makes it inert without changing how it looks
onClick?MouseEventHandler—not called while disabled
className?string—added after the component's own class: what you set wins
…restprops of as—typed against the chosen element

Button.IconLabel

proptypedefault
iconReactNode—a Button.Icon
labelReactNode—a Button.Label
reverse?booleanfalsekeeps the label and reveals the icon
direction?"left" | "right""right"which way the hidden part slides out
gap?string"0.5rem"space between the two once both show
className?string—added after the part's own class: what you set wins

Button.Icon

proptypedefault
childrenReactNode—the icon, in a 1rem square
className?string—added after the part's own class: what you set wins

Button.Label

proptypedefault
childrenReactNode—the text, rendered lowercase
className?string—added after the part's own class: what you set wins