Button

Slant / Primitives

Primary, secondary and ghost buttons with sizes, icons and a loading state.

Demo

Buttons & badges

Usage

@tuttn/slant
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

PropTypeDefaultDescription
variant'primary' | 'secondary' | 'ghost''secondary', or the ButtonGroup'sEmphasis: a solid fill in the tone's colour, a raised surface, or no background.
toneTone'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'sHeight on the control scale: 28, 34 or 40px at regular density. `lg` also sets larger text and padding.
iconboolean—A square button holding only an icon; give it an aria-label.
loadingboolean—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.
fullWidthboolean—Stretches the button to the width of its container.
asChildboolean—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.
disabledbooleanfalseThe native attribute: the button leaves the tab order. With asChild it becomes aria-disabled.
…restButtonHTMLAttributes—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.

Full source