Skip to main content

Button

import { Button } from "@study/ui"

A button triggers something: save, create, upload. Its text says what happens, as a verb. If it only leads somewhere else, it is a LinkButton.

Result
Loading...
Live Editor
function Example() {
  const [saving, setSaving] = useState(false);
  return (
    <div style={{ display: "flex", gap: 10, flexWrap: "wrap" }}>
      <Button variant="primary" icon="check" loading={saving} onClick={() => { setSaving(true); setTimeout(() => setSaving(false), 1500); }}>
        Save
      </Button>
      <Button>Cancel</Button>
    </div>
  );
}

Variants and states​

Light

Dark

VariantFor
primarythe one main action of a view
secondaryeverything else (default)
softa friendly secondary action on a colour, e.g. "With Claude" (tone)
dangerdelete, leave, sign out
ghostquiet actions in bars and lists

When to use​

✓ DoOne main action, next to it the alternative. The main action is on the right.
✗ Don'tSeveral main actions next to each other – nobody knows what counts.
✓ DoThe text says what happens.
✗ Don't“OK” and “Yes” say nothing.
  • Use loading instead of your own spinner – the button is then locked and tells screen readers that it is working.
  • type="submit" only in a form; otherwise a Button is always type="button".
  • For elements that cannot be a Button, buttonClass({ variant, size }) gives the classes.

Props​

Plus all attributes of a <button> (onClick, type, disabled …).

PropTypeDefaultMeaning
iconenum–An icon before the text.
iconEndenum–An icon after the text, e.g. an arrow for "Next".
loadingboolean–Shows a spinner instead of the icon and blocks further presses.
refRef<HTMLButtonElement>–
sizeButtonSize–sm 36 px, md 44 px (default), lg 52 px high.
tone"blau" | "petrol" | "gruen" | "gelb" | "orange" | "rot" | "violett" | "grau"–The colour of a `soft` button; default the neutral tint.
variantButtonVariant–primary – the one main action of a view (dark). secondary – everything else (outlined); the default. soft – a friendly side action on a tint, e.g. "With Claude". danger – deleting and leaving. ghost – quiet actions in toolbars and lists.
wideboolean–As wide as its place.

Accessibility​

  • A real <button>: reachable with Tab, triggered with Enter and Space.
  • A clear focus ring (3 px, --ui-focus), only for keyboard use.
  • At least 44 px high in md; sm only where a mouse is likely.
  • loading sets aria-busy and blocks double clicks.