Skip to content

Button

Calm by default, clear about state, comfortable to press - with a loading state that keeps focus.

On this page
Used for
  • Run an agent
  • Confirm a delete
  • Send a prompt
  • Retry a failed run
  • Open a model picker

Examples

Installation

npx knowns-ui@latest add button
For Claude Code, Cursor or Codex: installs it and wires the props to your own data.

Props

variant
"primary" | "secondary" | "ghost" | "destructive" | "quiet"
Default"primary"
Solid chip, hairline chip, text only, soft red for deleting, or quiet: inline text actions like “Show more” with no chip and no lift.
size
"xs" | "sm" | "md" | "lg"
Default"md"
24, 28, 32 or 36px high; taller on touch screens. xs is for dense clusters like zoom controls. Quiet buttons take only the text size.
icon / iconRight
ReactNode
Icons before / after the label. Icon only (no children) makes it square: add an aria-label.
loading
boolean
Defaultfalse
Spinner replaces the left icon and a soft band sweeps the label. Stays focusable, sets aria-busy, ignores clicks.
...props
button attributes
Everything a native button takes, including ref, type and disabled.

What it handles

  1. 01Draws five variants (primary, secondary, ghost, destructive and quiet) in four sizes, xs to lg, from one cva map you can extend with a variant of your own.
  2. 02Turns into a square icon button when it has an icon and no children, so an aria-label is all an icon-only action needs.
  3. 03Takes the loading prop to swap the left icon for a Spinner, set aria-busy and ignore clicks while the button stays focusable.
  4. 04Reads the primary fill from --kn-accent, falling back to --primary, so one token recolours every primary button on the page.
  5. 05Grows to 32, 36 or 40px high on touch screens through pointer-coarse, so a small button is still a fair target for a thumb.
  6. 06Exports buttonClass and buttonVariants so a link or a router anchor can wear the button look without being wrapped in a button.

States

First render
Nothing. It paints as it is
none
Hover
Fill and ink change colour; ghost and quiet buttons brighten their text
120ms, ease out
Pressed
Filled buttons shrink to 97% while the pointer is down; quiet buttons do not
120ms, ease out
Keyboard focus
A focus ring appears around the button
none, at once
Loading
A Spinner replaces the left icon and a soft band sweeps across the label on a loop
none
Disabled
The button dims to half strength and the cursor changes
none, at once
Reduced motion
The press scale and the label sweep are off
0ms

Works with

When to use

When to use

  • Any action the user triggers: submit, save, run, cancel, with a loading state that stays focusable.

When not to use

  • Navigation to another page: use a link.
  • An on/off state: use Switch.

Using with AI

Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:

  • Add the Knowns UI Button to my app and wire it to my own data.
  • I need any action the user triggers: submit, save, run, cancel, with a loading state that stays focusable. Set that up with the Knowns UI Button.
  • Which Button props do I need for a minimal setup? Show me a short example.

With the server connected, your assistant calls get_component({ name: "button" }) and search_docs({ query: "button" }).

Need help?

Stuck on Button, or found something off? We read every message.