Button
Slant / Primitives
Primary, secondary and ghost buttons with sizes, icons and a loading state.
Demo
Usage
import { Button } from '@tuttn/slant'
<Button variant="primary">Deploy</Button>
<Button>Secondary</Button>
<Button variant="ghost" size="sm">Ghost</Button>
<Button variant="primary" size="lg">Get started</Button>
// tone is the colour: a danger fill is a destructive action.
<Button variant="primary" tone="danger">Delete project</Button>
<Button tone="danger">Discard draft</Button>
// Loading shows a small Spinner and sets aria-busy and aria-disabled. The
// button keeps focus, and clicks are ignored until it finishes.
<Button variant="primary" loading={saving} onClick={save}>{saving ? 'Saving…' : 'Save'}</Button>
// Icon-only buttons are square; give them a label.
<Button icon aria-label="Add"><PlusIcon /></Button>
// asChild renders your link (or a router's Link) with the button's look.
<Button asChild variant="primary"><a href="/docs">Read the docs</a></Button>
<Button fullWidth type="submit">Continue</Button>Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'primary' | 'secondary' | 'ghost' | 'secondary', or the ButtonGroup's | Emphasis: a solid fill in the tone's colour, a raised surface, or no background. |
tone | Tone | 'accent' | Semantic colour. `primary` fills with it, so `tone="danger" variant="primary"` is a destructive button; `secondary` and `ghost` take it as their text and border colour. With `accent` and `neutral` they keep their usual look. |
size | 'sm' | 'md' | 'lg' | 'md', or the ButtonGroup's | Height on the control scale: 28, 34 or 40px at regular density. `lg` also sets larger text and padding. |
icon | boolean | — | A square button holding only an icon; give it an aria-label. |
loading | boolean | — | Shows a small Spinner before the label, in the button's text colour, and sets aria-busy and aria-disabled. The button keeps focus, so a screen reader stays on it, but clicks are ignored until loading ends. |
fullWidth | boolean | — | Stretches the button to the width of its container. |
asChild | boolean | — | Renders the single child (a link, a router's Link) instead of a button, with the button's class, data attributes and handlers merged onto it. No `type` is added, and `disabled` becomes aria-disabled, which a link understands. |
type | 'button' | 'submit' | 'reset' | 'button' | Never submits a form by accident. Not added with asChild. |
disabled | boolean | false | The native attribute: the button leaves the tab order. With asChild it becomes aria-disabled. |
…rest | ButtonHTMLAttributes | — | onClick, aria-* and every other button attribute pass through; a ref reaches the button element, or the child with asChild. |
loading is not disabled: it keeps the button focused, so keyboard and screen reader users don't lose their place, and looks disabled through aria-disabled. Use disabled for a button that can't be used at all yet. The busy mark is a small, decorative Spinner in the button's text colour; the label stays the button's name, so change it ("Saving…") if the wait needs words.