|Kit

Button

Polymorphic

Interactive primitive. Five variants × eleven colors, slots, loading, a pressed (toggle) state, and asChild — with a playground to try them.

The Button is a polymorphic interactive primitive built on top of Ark UI's ark.button. Visual treatment splits into two orthogonal props:

  • variant — the shape (filled, light, outline, subtle, link)
  • color — the palette (brand, neutral, red, orange, yellow, green, teal, cyan, blue, purple, pink)

Color is delivered via CSS variables on a data-color attribute, so a single class set works for every palette and dark mode gets the right shade automatically.

import { Button } from "@42-central/ui-react/button";

<Button variant="filled" color="brand" onClick={() => console.log("hi")}>
  Get started
</Button>;

Playground

Tweak the visual props live — controls are curated in the story file. The code panel updates as you change them.

Component

Loading preview

Props

Code

<Component size="md">
  Default
</Component>

Variants

Five visual treatments, drawn from the Figma Button set. Each one reads the palette's --btn-* slots in colors.css, so they all swap palettes uniformly. link is bare underlined text: it drops the size's height and padding, so it sits in a line of prose.

Code

<Button variant="filled">Filled</Button>
<Button variant="light">Light</Button>
<Button variant="outline">Outline</Button>
<Button variant="subtle">Subtle</Button>
<Button variant="link">Link</Button>

Colors

Every variant accepts any color in the palette. Adding a new color is a CSS-only change — append a [data-color="…"] block to colors.css and a name to COLORS. Omitting color resolves to neutral via the :root cascade.

For a destructive action, use variant="filled" color="red". There is no separate destructive variant — intent is conveyed through color.

Sizes

Three sizes covering the standard density needs. For an icon-only square button, reach for ActionIcon.

Code

<Button size="sm">Small</Button>
<Button size="md">Medium</Button>
<Button size="lg">Large</Button>

Slots

startSlot and endSlot render before and after the children. Both are wrapped in aria-hidden so they don't pollute the accessible name. Pass a bare lucide-react icon — the button's size variant scales it automatically.

Code

import { ArrowRight, ExternalLink, Plus } from 'lucide-react';

<Button startSlot={<ExternalLink />}>Open</Button>
<Button endSlot={<ArrowRight />}>Continue</Button>
<Button
  variant="outline"
  color="neutral"
  startSlot={<Plus />}
  endSlot={<Kbd size="sm">⌘N</Kbd>}
>
  New file
</Button>

Loading

loading shows an inline spinner, blocks interaction, and sets aria-busy="true" — without changing the button's size or moving its label.

Code

const [pending, startTransition] = useTransition();

<Button
  loading={pending}
  onClick={() => startTransition(submit)}
>
  Save changes
</Button>

Toggle it on every slot combination:

Code

<Button color="brand" loading={loading}>Save changes</Button>
<Button variant="light" loading={loading} startSlot={<Save />}>Save</Button>
<Button variant="outline" loading={loading} endSlot={<ArrowRight />}>Next</Button>
<Button variant="subtle" loading={loading} startSlot={<Plus />} endSlot={<ArrowRight />}>
  Create
</Button>

Nothing leaves the layout while loading. The spinner crossfades into a place that's already there:

  • With a startSlot, the spinner takes the icon's place, in the same spot; the label and any endSlot stay as they are.
  • With only an endSlot, the same swap happens in the end slot.
  • With no slot, the label fades and lifts away while the spinner rises into its place. The label stays laid out underneath, so it still sizes the button.

The button keeps full contrast — dimming is what disabled looks like, and a loading button isn't disabled, it's busy. Hover styling is suppressed and the cursor switches to a progress spinner. With reduced motion on, the swap is instant; the spinner still turns.

Disabled

Disabled buttons switch to faint tints of their own palette rather than a uniform dim. Both native :disabled and Ark's data-disabled attribute are styled, so the disabled treatment lands whether the underlying element is a <button> or rendered through asChild.

Code

<Button disabled>Disabled</Button>

Toggle

Some buttons stay pressed: Bold in a toolbar, Show archived above a list, a mute button. Pass pressed, defaultPressed or onPressedChange and the Button becomes a toggle button: it renders aria-pressed, every click flips the state, and its look swaps from variant to pressedVariant. Without any of the three it stays a plain button, with no aria-pressed at all.

Code

<Button defaultPressed={false} startSlot={<Archive />}>
  Show archived
</Button>

Controlled

Own the state with pressed and onPressedChange, the same pair as open / onOpenChange elsewhere in the kit. onPressedChange receives the next state.

aria-pressed: false

Code

const [muted, setMuted] = useState(false);

<Button
  color="red"
  pressed={muted}
  onPressedChange={setMuted}
  startSlot={muted ? <MicOff /> : <Mic />}
>
  Mute
</Button>

Calling event.preventDefault() in your own onClick keeps the state as it is.

The pressed look

The swap is the one ButtonSelect makes for its selected item, with the same defaults: on a toggle, variant (the unpressed look) defaults to light and pressedVariant to filled. So a lone toggle and a toggle inside a ButtonSelect look the same. Set both to pick another pair.

Code

// Unpressed (top row in the demo)
<Button color="brand" defaultPressed={false}>Light → filled</Button>
<Button color="brand" variant="outline" pressedVariant="light" defaultPressed={false}>Outline → light</Button>
<Button color="brand" variant="subtle" pressedVariant="light" defaultPressed={false}>Subtle → light</Button>

// Pressed (bottom row)
<Button color="brand" defaultPressed>Light → filled</Button>
<Button color="brand" variant="outline" pressedVariant="light" defaultPressed>Outline → light</Button>
<Button color="brand" variant="subtle" pressedVariant="light" defaultPressed>Subtle → light</Button>

Loading and disabled

loading and disabled block the click, so the state can't change. Both hold under asChild too, where native disabled alone wouldn't stop a click. A loading toggle keeps its pressed look. A disabled one takes the disabled tints of its pressedVariant, which sit close to the unpressed ones, as in the Figma Button set; aria-pressed still reports the state.

Code

<Button color="brand" defaultPressed loading>Bold</Button>
<Button color="brand" defaultPressed disabled>Bold</Button>
<Button color="brand" defaultPressed={false} disabled>Bold</Button>

aria-pressed has no meaning on a link, so a toggle is always a <button>. A Button that wraps a link through asChild (an <a>, or a router Link with an href or a to) ignores the pressed props and logs a warning in development. TypeScript can't see the child, but it does forbid href on Button itself, with the reason in the error, so a link's props spread onto a toggle don't compile:

// ✗ Type 'string' is not assignable to type
//   'Unavailable<"aria-pressed has no meaning on a link: …">'
<Button pressed {...linkProps} />

To show the current page in a navigation, use aria-current on the link instead.

Button, ButtonSelect or Switch?

  • One option that stays on or off — a filter, a format, mute: a toggle Button or ActionIcon.
  • Several related toggles, or one choice among a few — a formatting toolbar, a view picker: ButtonMultiSelect or ButtonSelect. The group owns the selection, joins the buttons and adds arrow-key navigation.
  • A setting that takes effect right away and reads as on / off — "Email notifications": a Switch.

Polymorphic with asChild

Render any other element while keeping the button's styling and behavior. Useful for wrapping a Next.js <Link> so you don't lose client-side navigation.

import Link from "next/link";

<Button asChild color="brand">
  <Link href="/dashboard">Open dashboard</Link>
</Button>;

A toggle works the same way: aria-pressed, the click and the pressed variant all land on the child. A link child is the exception, see Not on a link.

startSlot/endSlot and loading still render — they're composed into the rendered child's own children rather than the child itself, since Ark's asChild only allows a single element through.

Code

<Button asChild color="brand" startSlot={<ArrowRight />} endSlot={<ExternalLink />}>
  <a href="/dashboard">Go</a>
</Button>

Form submission

Buttons default to type="button" to prevent accidental form submission. Opt in explicitly when you want submit semantics:

<form action={createPost}>
  <Button type="submit" color="brand">
    Publish
  </Button>
</form>

API

Prop

Type

All other props are forwarded to the underlying button (or asChild element).

Accessibility

  • Focus ring is exposed only on keyboard focus (focus-visible:), so pointer interactions stay quiet. The ring is a fixed brand-500 and does not track color — see Focus.
  • A toggle renders aria-pressed="true" or "false", so screen readers announce it as a toggle button with its state. Keep the label the same in both states: aria-pressed already says whether it's on, and a label that flips too ("Mute" → "Unmute") reads as the opposite action. Swapping the icon is fine.
  • aria-busy and aria-disabled are set whenever the button is loading or disabled, regardless of the visual state.
  • Slot contents are aria-hidden; the accessible name comes from the children. For icon-only triggers, use ActionIcon, which forces an explicit aria-label.

Changelog

v0.30.0
  • href on Button and ActionIcon is now a type error, including through a spread; wrap a link with asChild instead

    #483
  • New toggle state: pressed, defaultPressed, onPressedChange and pressedVariant (light unpressed, filled pressed by default)

    #483
v0.28.0
  • Button and ActionIcon read their own --btn-* slots in colors.css; overriding --c-* no longer restyles them

    #458
  • variant="link": underlined text with no height or padding, so it sits in a line of prose

    #458
  • Colors follow the Figma V3 Button set, and every palette's hover steps up the way neutral's does

    #458
  • Disabled uses the palette's tints instead of 50% opacity

    #458
  • A size class on the icon (className="size-5") now wins over the component's default

    #460
v0.25.0
  • outline's edge is its colour at 35 %, like light's

    #438
v0.20.0
  • loading no longer changes the button's width or moves its label: the spinner fades into the icon's place or over the label, at full contrast

    #370
v0.19.0
  • Spinner's accessible name comes from label, and label={null} takes it out of the accessibility tree, so loading Buttons and ActionIcons no longer expose an extra "Spinner" image

    #319
v0.6.0
  • With asChild, slots and the loading spinner stay visible, and the spinner dims correctly

    #79
v0.3.0
  • isLoading → loading on Button and ActionIcon

    #25
  • Drop variant="default": a bare <Button> is now filled + neutral

    #35
  • Drop the radius prop: corners are a fixed 4px

    #35
  • Button colors and Card surfaces realigned to the 42 UI Kit Figma

    #35
v0.0.1
  • Button, with startSlot/endSlot and a loading state

On this page