Actions

Button

Primary interactive control for triggering actions or rendering an anchor styled as a button via href.

import { Button } from '@lostgradient/cinder';
actioncta
01

Overview

Reference usage

A clickable button or anchor with built-in loading state, icon slots, and a discriminated prop union that forces consumers to provide an accessible name at compile time.

Usage

svelte
<script lang="ts">
  import { Button } from '@lostgradient/cinder';
</script>

<Button variant="primary" size="md" label="Save" />

When href is set, the component renders as <a>; otherwise it renders as <button>. Setting loading swaps in a spinner, blocks the consumer's onclick, forces aria-disabled / aria-busy, and strips href to prevent navigation. While loading the cursor is progress and the button keeps full strength; a page that dims it sets --cinder-button-loading-opacity (for example 0.75) on it. The width is held when the label stays or gets shorter; a longer label that arrives with loading ("Create", "Creating…") lets the width go so it never spills over the border.

Sizes

md is the default and the size for inline actions: the buttons in a row, a card, a dialog footer, or a toolbar. Use sm or xs where space is tight. Reserve lg for a page-level primary action, such as the one call to action that a page is organized around. A screen with several lg buttons has no primary action.

Set touchFace when the button itself should fill the 44px touch target. On coarse pointers this gives the face a 44px minimum height and width, so a small icon-only button draws as a 44px square. Fine pointers and compact header actions keep their usual sizes.

Filled by default

A Button is a pill, and with no variant it draws the filled soft face: a tinted fill with no outline, so a row of actions reads as filled controls rather than a row of boxes. primary is unchanged and marks the one action a region is organized around. Ask for secondary by name only where an outlined face is the point, such as a field's colour well.

Keep one labelled primary in a group of actions. The secondary options are icon-only Buttons (iconOnly) with an accessible name (aria-label or label) and a Tooltip that shows the same words, so the row is one labelled action and a few glyphs.

Content

A label is a short verb phrase, about four words: "Save draft", "Run now", "Add a memory". It names the action, not what the action will produce. A proposal, a preview or a sentence the person should read before acting belongs beside the button, in the row or card it acts on, with the button keeping a short verb ("Apply", "Use this").

A button that takes its words from label is never wider than its container. A label too long for the room truncates with an ellipsis, and the full words stay the accessible name, so nothing is lost to a screen reader; the sighted reader loses the end of the label, which is why a long label is a content defect rather than a layout to rely on. Labels never wrap onto a second line. The cap and the truncation apply to the label prop only; content you pass as children is laid out as you write it, so pass the words through label when they could run long.

Shortcut hint

shortcut takes a key ("N") or an array of keys (['Ctrl', 'K']) and renders a ShortcutHint after the label. The hint is decorative and aria-hidden, so the button's accessible name stays its label, and it only displays the shortcut; registering the key is the application's job. Each key is a quiet chip, on every variant, so it reads as a key to press and not as part of the label: a 14% wash of the button's own text color behind the key, a small radius, tight padding and no border, a step smaller than the label and a clear gap after it. The key's glyphs keep the button's text color at full strength, and the chip never makes the button taller at any size; under forced colors each key gets a 1px edge instead of the wash. It is hidden on touch devices (pointer: coarse or hover: none), which have no keyboard to press it with. A Kbd or ShortcutHint you nest in a button by hand gets the same treatment, so do not restyle it per page.

Disabled

A disabled button looks the same in every variant: a neutral surface (or none, for ghost and ghost-danger), --cinder-text-disabled text, and never an opacity fade (a fade would drop the label under 4.5:1). It never keeps its tone while disabled, so a disabled danger or ghost-danger button does not read as a faded red button. A primary button also never takes a tone from its container: inside a danger Card it is still the primary button.

Current and toggle buttons

Pass aria-current="true" to mark the current item in a set, such as the review already open. The secondary, soft, ghost, and ghost-accent variants keep a quiet selected tint on hover. The soft-danger and ghost-danger variants keep their danger tint. If both attributes are true, the pressed face takes precedence.

Pass aria-pressed="true" or "false" to make a button a toggle. A pressed button takes the filled accent face (every variant except primary and danger, which are already filled); see button.a11y.md. This applies to every Button that carries aria-pressed="true", including a consumer's own: for example, kanban-board.svelte sets it on a column's drag handle while that column is lifted, so a lifted column's handle now takes the filled face. No committed Cinder baseline shows a pressed Button at rest besides the new button/*-pressed images, which the baseline refresh confirmed.

Live preview

Primary button

02

When to use

Use when
  • Triggering a discrete action such as submit, save, or delete.
  • Rendering a link that should look and behave like a button by passing href.
  • Marking the current item in a set with aria-current.
  • Using touchFace to draw the full 44px target on coarse pointers.
Avoid when
  • Toggling a binary on or off state — use toggle instead.
  • Selecting one of a small fixed set of options — use segmented-control instead.
03

Examples

Disabled button

A plain (non-icon-only) disabled button. The secondary variant has no variant-specific disabled override, so its border color comes from the base disabled rule in button.css and its text takes `--cinder-text-disabled` with no opacity fade.

Icon-only buttons

Icon-only buttons keep the visual surface compact while still carrying an accessible name through label or aria-label.

Inert buttons with a reason

An aria-disabled button stays focusable, ignores the press and says why through aria-describedby and a tooltip. Icon-only inert buttons keep their accessible name; the live Export beside them still works.

Loading state

A permanent loading button alongside one that toggles loading on click; both render the spinner and set aria-busy.

Loading: label, width and spinner

Press "Start" to put every button in flight. When the label stays (Save), the width does not move; shorter words (Testing…) keep the width; longer words (Creating…) take the width they need so they never spill over the border. A page that dims the button while it works sets --cinder-button-loading-opacity (Connecting…).

Long labels and the preview row

A label is a short verb phrase. A proposal the person should read sits beside the button, and a label too long for its container truncates with an ellipsis while the full words stay the accessible name.

Primary button

The one high-emphasis action in a region. Every other action takes the default filled soft face.

Button with a shortcut hint

The shortcut prop renders a decorative key hint after the label. It is plain glyphs in the button's own color on every variant, and touch devices hide it. The accessible name stays the label.

Button sizes

xs, sm, md, and lg sizes, on the shared 24/28/32/40px control height scale. Use md for inline actions and keep lg for a page-level primary action.

Soft variants

Soft and soft-danger use a tinted fill with no border — mid-emphasis between ghost and primary/danger.

Text + icon buttons

leadingIcon and trailingIcon snippets are decorative-only and wrap their SVGs in aria-hidden. Meaning still lives in the button label.

Top bar icon buttons

Notifications and quick settings as 32px icon-only buttons. They rest as the bare glyph (quiet). Each has an aria-label, the notifications label carries the unread count, and hover, focus and pressed are distinct; focus uses the shared quiet ring.

Button variants

Primary, secondary, danger, and ghost styles.

04

Props

Props for button
Name
Type
Default
Description
variant 'primary''secondary''soft''danger''soft-danger''ghost''ghost-danger''ghost-accent'
1 more members 'link'
'soft' Visual style.
size 'xs' | 'sm' | 'md' | 'lg' 'md' Size of the button. lg is for page-level primary actions only; inline actions use md.
fullWidth boolean false Expand to container width.
touchFace boolean false Draw the button face at least 44px tall and wide on coarse pointers. Compact buttons ignore it.
loading boolean false Show a spinner and make the button inert while work is in flight. The button gets aria-disabled and aria-busy (not the native disabled, so it keeps focus), keeps its label, ignores further presses, and holds the width it had at rest.
loadingStatus text Text a polite, visually hidden status announces while loading (for example Saving…). The status node is rendered beside the button, so it never joins the button's accessible name, and it is mounted from the start so the announcement is not lost. Omit it and no status node is rendered.
loadingWidth 'hold' | 'grow' 'hold' What the button's width does while loading. hold (default) keeps the width it had at rest and fits the spinner into its padding, so nothing around it moves. grow lets the box take the spinner and its words at their normal padding, for a button in a row with room to spare (an action beside a line of text), where the squeezed padding would read as cramped.
mutating boolean false Marks a button that changes something (Edit, Save, Delete, a header "+"). Inside a stale <StaleRegion> it goes inert: aria-disabled, still focusable, ignoring the press, and described by the region's reason ("Off until it’s back"). It returns by itself when the region stops being stale. A button that only reads (a link, Try again) leaves this off and stays live.
iconOnly false false
quiet boolean false Rests as the bare glyph: drops the resting fill and rule an icon-only ghost button otherwise paints, for a toolbar such as the shell's top bar. Hover, pressed and focus still paint. It has no effect unless the button is iconOnly with variant="ghost".
flush boolean false A quiet button that starts a line under text: it is pulled back by its inline padding and its 1px transparent border, so its words start on the text edge above it, and only its hover tint and ring reach past. It has no effect unless the variant is ghost, ghost-accent or ghost-danger with a label. Set it on the button that starts its line, never on one after another control.
leadingIcon snippet DECORATIVE icon rendered before the label/children. Always wrapped in aria-hidden. If the icon conveys meaning, supply accessible text via label/aria-label instead. The button sizes an SVG icon at 1em of its text, so it follows size; pass no size.
trailingIcon snippet DECORATIVE icon rendered after the label/children. Always wrapped in aria-hidden. Same accessible-name guidance as leadingIcon.
shortcut text A keyboard shortcut hint (a key such as "N", or ["Ctrl", "K"]) rendered after the label through ShortcutHint. It is decorative and aria-hidden, so the accessible name stays the label, and it is plain glyphs in the button's own color on every variant, hidden on touch devices. It only displays the shortcut; registering the key is the application's job.
children snippet
label text
href discriminated-union
onclick MouseEventHandler<T> | undefined | null