Skip to content
nexubDesign System
v12.7.0

Components · Actions

Button

StableAdded v0.0.1 · updated v1.7.0

Triggers an action or event. Supports multiple variants, sizes, and semantic tones.

import { Button } from '@nexub/react';
View as Markdown

Usage

Use it for
  • Triggering a primary or secondary action (submit, save, confirm)

  • Navigating users to another page or step in a flow

  • Opening a dialog, drawer, or modal overlay

  • Destructive actions that need a visible, labelled control

Use something else for
  • Inline text navigation — use a Link instead

  • Icon-only controls — use IconButton for touch target compliance

  • Selecting among multiple options — use ToggleGroup or SegmentedControl

  • Passive information display with no action

Playground

Playground

Live
TSX
<Button variant="filled" size="md">Click me</Button>

Examples

Default

Variants

Sizes

States

Loading

Async

Drive `status` from the request. Each click here moves to the next status.

status: idle

Hero (marketing mode)

Inside `data-mode="marketing"` with `@nexub/themes/marketing` loaded. The focus ring sits outside the gradient.

Magnetic

`magnetic` (4.3): drifts toward the pointer. Use it for one key action per screen.

States

  • default
  • disabled
  • Loading
    loading
  • size="sm"
  • size="md"
  • size="xs"
  • size="lg"
  • size="xl"
  • variant="glass"
  • variant="filled"
  • variant="tonal"
  • variant="outlined"
  • variant="text"
  • variant="hero"
  • variant="subtle"
  • variant="destructive"
  • tone="neutral"
  • tone="info"
  • tone="success"
  • tone="warning"
  • tone="danger"
  • tone="leap"
  • tone="bookub"
  • tone="payub"

Variant matrix

Variants × variant / size5 × 5
variant ↓ / size →xssmmdlgxl
filled
outlined
text
subtle
link

Props

Props
PropTypeDefaultDescription
variant'glass' | 'filled' | 'tonal' | 'outlined' | 'text' | 'hero' | 'subtle' | 'destructive' | 'accent' | 'link''filled'Visual style of the button. hero is the marketing-mode main button (gradient, glow, spring lift): a filled button outside data-mode="marketing"; one per screen. Deprecated in 8.4, removed in 9.0: the legacy aliases primary (filled), secondary (tonal), outline (outlined) and ghost (text) still work; npx nexub-migrate --rules button-aliases --write renames them.
size'sm' | 'md' | 'xs' | 'lg' | 'xl''md'Control height and padding.
status'idle' | 'error' | 'success' | 'loading'—Async feedback (beta, 1.7.0). loading shows a spinner and blocks clicks but keeps focus; success draws a check; error shakes once. The label stays in flow, so the width holds.
loadingboolean—Alias for status="loading".
loadingLabelstring'Loading'Announced when status becomes loading.
successLabelstring'Done'Announced on success. When set, it also replaces the visible label (with a check) instead of showing the check alone.
errorLabelstring'Something went wrong'Announced on error.
disabledbooleanfalseDisables the button.
magneticbooleanfalse4.3: drifts a few pixels toward the pointer on hover. For one key action per screen. Off for touch and reduced motion.
fullWidthboolean—Stretches the button to fill its container.
leadingIconReact.ReactNode—Icon rendered before the label.
trailingIconReact.ReactNode—Icon rendered after the label.
tone'neutral' | 'info' | 'success' | 'warning' | 'danger' | 'leap' | 'bookub' | 'payub' | 'founderub'—Semantic colour tone — overrides the variant colour with a semantic palette.
asChildbooleanfalseMerges props onto the immediate child element (Radix Slot). status and loading have no effect with asChild.

Design tokens

Button reads these component tokens. Each one is unset by default and falls back to the semantic role it aliases, so nothing changes until you set it. Set one on any element to restyle every Button below it, and leave the roles other components share alone. See the three token tiers.

Button design tokens
TokenAliasesNotes
--button-filled-bg--color-primary—
--button-filled-fg--color-on-primary—
--button-tonal-bg--color-secondary-container—
--button-tonal-fg--color-on-secondary-container—
--button-outlined-border--color-outline-variant—
--button-outlined-fg--color-on-surface—
--button-text-fg--color-on-surface—
CSS
/* One area of your app */
.checkout {
  --button-filled-bg: var(--color-secondary);
}

Accessibility

ARIA roles

button

Keyboard

  • Space

    Activates the focused button.

  • Enter

    Activates the focused button.

  • Tab

    Moves focus to the button in document order.

Focus

  • Receives focus in document order; `disabled` removes it from the tab sequence.

  • Visible focus ring uses `--color-border-focus` and meets WCAG 2.4.7 contrast.

Screen reader

  • Announces the visible label plus the implicit "button" role.

  • While loading the button sets `aria-busy` and `aria-disabled` (not `disabled`), so focus stays on it and clicks are ignored.

  • A button with `status` or `loading` renders a polite `role="status"` region next to it that announces `loadingLabel`, `successLabel` or `errorLabel` as the status changes.

Notes

  • Pair icon-only triggers with `IconButton` for a 44×44 touch target.