Skip to the content
human-kit design
03 — Form

Button

A button with variants, sizes and a pending state.

Installation

pnpm dlx @human-kit/design add button
npx @human-kit/design add button
yarn dlx @human-kit/design add button
bunx @human-kit/design add button

The 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 default variant for the one action that the screen is for. One per screen, or per dialog.
  • Use outline for every other action of a toolbar or a form.
  • Use filled for a secondary action that should read lighter than an outlined box: a soft grey, no edge.
  • Use ghost for icons and for actions that repeat down a list, where a box on each row would be noise.
  • Use link for 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>, of type="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.
  • disabled takes the button out of the tab order. To keep it reachable and say why it does nothing, use aria-disabled and a tooltip instead.

API reference

PropTypeDefault
variant'default' | 'outline' | 'filled' | 'ghost' | 'link'

How much the button stands out.

'default'
intent'neutral' | 'danger'

What the action means. danger for one that destroys or cannot be undone.

'neutral'
size'sm' | 'default' | 'lg' | 'icon-sm' | 'icon' | 'icon-lg' | 'icon-xs' | 'icon-2xs'

The height. The icon sizes make a square for an icon alone.

'default'
iconComponent

The icon that leads the label.

—
countnumber

How many records the action touches, at the end of the label.

—
pendingboolean

Shows a spinner and ignores presses while an action runs.

false
disabledboolean

Turns the button off and takes it out of the tab order.

false
elementHTMLButtonElement | null

The rendered element. Bindable.

—

Plus every attribute of a native <button>.