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>As a link
as renders any element or component, and the props follow it: to is typed on a router Link.
tsx
<Button as={Link} to="/margo-ui" active={isCurrent} aria-current={isCurrent ? "page" : undefined}>
<Button.Label>documentation</Button.Label>
</Button>Reference
| prop | type | default | |
|---|---|---|---|
as? | ElementType | "button" | the element or component to render |
active? | boolean | false | primary border and shadow; visual only |
open? | boolean | false | keeps the label out, as on hover; visual only |
disabled? | boolean | false | native disabled on a button, aria-disabled on anything else; dimmed |
clickable? | boolean | true | false 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 |
…rest | props of as | — | typed against the chosen element |
Button.IconLabel
| prop | type | default | |
|---|---|---|---|
icon | ReactNode | — | a Button.Icon |
label | ReactNode | — | a Button.Label |
reverse? | boolean | false | keeps 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
| prop | type | default | |
|---|---|---|---|
children | ReactNode | — | the icon, in a 1rem square |
className? | string | — | added after the part's own class: what you set wins |
Button.Label
| prop | type | default | |
|---|---|---|---|
children | ReactNode | — | the text, rendered lowercase |
className? | string | — | added after the part's own class: what you set wins |