Button
The one button: four weights, five tones, three sizes, and a link when given an href.
Examples
Playground
Variant
Visual weight, from most to least emphasis. Weight only: meaning is `tone`.
Tone
What the action means. Every tone works at every variant (see Tone × Variant).
Size
sm is 28px for dense pointer UI, md 36px is the default, lg 44px is the AAA target size.
States
Every state side by side. Hover, focus and pressed are forced, so they can be reviewed without a pointer. Loading keeps the width of the rest state.
Content
A long label stays on one line, and the external glyph follows any label.
As a link
A disabled anchor has no `href`, `tabindex="-1"` and no `target`. `aria-disabled` alone announces a state without creating one: the link stayed focusable and still navigated.
Tone by variant
Every combination, because the point is that every cell works. A tone remaps custom properties and decides nothing about weight; a variant reads the ones it needs and decides nothing about meaning.
Install
npx shadcn add @hipuku/buttonUsage
import { Button } from '@/components/haus/components/Button'
<Button variant="primary" onClick={save}>
Save changes
</Button>API
Button also takes its element's own attributes and forwards its ref. className lands on the root.
| Prop | Type | Description |
|---|---|---|
variant | "primary" | "secondary" | "ghost" | "text" | |
tone | "neutral" | "info" | "success" | "warning" | "error" | What it means. error is what variant="danger" used to say. |
size | "sm" | "md" | "lg" | |
external | boolean | Opens elsewhere: appends the glyph and, with href, is the honest signal
that the destination leaves this app. Behaviour, so not a variant. |
asChild | false | |
loading | boolean | |
href | string | Renders as an anchor when provided |
target | string |
Variants
variant is visual weight. Use one primary per view, for the action the view is for.
variant | Use it for |
|---|---|
primary | The main action |
secondary | Actions beside the main one |
ghost | Quiet actions in toolbars and dense rows |
text | An action that sits in a line of text |
Tones
tone is meaning, separate from weight, and every tone works at every variant: neutral, info,
success, warning and error. Use error for an action that destroys something.
Sizes
md is the default. sm is for dense interfaces, and lg meets the enhanced touch target size.
Links
Give it href and it renders an <a>. Add external for a destination outside the app: it adds
an arrow, and a _blank target gets rel="noopener noreferrer".
For a router's link, pass it as the single child with asChild:
<Button asChild variant="secondary">
<Link href="/settings">Settings</Link>
</Button>Loading
loading shows a spinner in place of the label. The button keeps its width and its focus, and
it does not run onClick or submit its form a second time while it loads.
loading cannot be combined with asChild, and that is a type error: a link has no submitting
state to show.
Accessibility
- A
<button>, or an<a>withhref, so it works from the keyboard as itself: Enter and Space, or Enter on a link. - The focus outline shows on keyboard focus only, and meets the 3:1 contrast WCAG asks of it.
- A disabled link is really disabled: out of the tab order and not activatable.
loading sets aria-busy, which marks the button as busy but does not make a screen reader say
anything. If the wait has to be announced, put its text in a live region you own.