Button
A button with variants, sizes and a pending state.
Installation
pnpm dlx @human-kit/design add buttonnpx @human-kit/design add buttonyarn dlx @human-kit/design add buttonbunx @human-kit/design add buttonThe command copies the files to src/lib/components/ui/button. It also
installs the packages that the files import.
Usage
<script lang="ts">
import * as Button from '$lib/components/ui/button';
</script>
<Button.Root onclick={save}>Save changes</Button.Root> Examples
Icon and count
Give the leading icon in icon, not in the label: the button then starts its text a step closer to the edge. count ends the label with how many records the action touches.
Destructive actions
intent="danger" marks an action that deletes or cannot be undone. It works with every variant: the filled one turns red, the others only their text.
Pending
While the action runs, pending shows a spinner in place of the label. The button keeps its width, its focus and its name, and it ignores presses until it is done.
Guidelines
- Use the
defaultvariant for the one action that the screen is for. One per screen, or per dialog. - Use
outlinefor every other action of a toolbar or a form. - Use
filledfor a secondary action that should read lighter than an outlined box: a soft grey, no edge. - Use
ghostfor icons and for actions that repeat down a list, where a box on each row would be noise. - Use
linkfor an action that reads as part of a sentence. - Start the label with a verb and say what happens: "Save changes", not "OK".
Accessibility
- It renders a native
<button>, oftype="button"unless you give another type. - The focus ring shows for the keyboard only, not after a click.
- A button with an icon and no text needs an
aria-label. - While pending it stays in the tab order and announces "pending" to a screen reader; a submit button does not submit its form again.
disabledtakes the button out of the tab order. To keep it reachable and say why it does nothing, usearia-disabledand a tooltip instead.
API reference
| Prop | Type | Default |
|---|---|---|
variant | 'default' | 'outline' | 'filled' | 'ghost' | 'link' How much the button stands out. | 'default' |
intent | 'neutral' | 'danger' What the action means. | 'neutral' |
size | 'sm' | 'default' | 'lg' | 'icon-sm' | 'icon' | 'icon-lg' | 'icon-xs' | 'icon-2xs' The height. The | 'default' |
icon | Component The icon that leads the label. | — |
count | number How many records the action touches, at the end of the label. | — |
pending | boolean Shows a spinner and ignores presses while an action runs. | false |
disabled | boolean Turns the button off and takes it out of the tab order. | false |
element | HTMLButtonElement | null The rendered element. Bindable. | — |
Plus every attribute of a native <button>.