Components / Actions

Button04

Presses like it means it. It squashes and springs back in Sticker, snaps in Retro, goes POW in Comic and scores points in Arcade. Same props, four personalities.

Button · PlaygroundLive
variant
size
JSX
<Button>Send invite</Button>

Usage

TSX
import { Button } from "plonk-ui";

export function Invite() {
  return <Button onPress={() => sendInvite()}>Send invite</Button>;
}

Use onPress for actions. It fires once for mouse, touch and keyboard, and ignores the press if the pointer leaves the button before release. onClick still works, so existing code keeps running while you migrate:

<Button onClick={(event: React.MouseEvent) => track(event)}>Track</Button>;

Variants

primary is the main action on a screen. Use danger for destructive actions and ghost for quiet ones, like toolbars.

Button · VariantsLive
TSX
import { Button } from "plonk-ui";

export default function Variants() {
  return (
    <div className="flex flex-wrap items-center gap-3">
      <Button>Primary</Button>
      <Button variant="secondary">Secondary</Button>
      <Button variant="accent">Accent</Button>
      <Button variant="neutral">Neutral</Button>
      <Button variant="danger">Delete</Button>
      <Button variant="ghost">Ghost</Button>
    </div>
  );
}

Sizes

Button · SizesLive
TSX
import { Button } from "plonk-ui";

export default function Sizes() {
  return (
    <div className="flex flex-wrap items-center gap-3">
      <Button size="sm">Small</Button>
      <Button size="md">Medium</Button>
      <Button size="lg">Large</Button>
    </div>
  );
}

With icons

Icons are hidden from screen readers; the label names the button. A button with only an icon needs an aria-label.

Button · IconsLive
TSX
import { Button } from "plonk-ui";

const Plus = () => (
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={3}>
    <path d="M12 5v14M5 12h14" />
  </svg>
);

const Arrow = () => (
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={3}>
    <path d="M5 12h14M13 6l6 6-6 6" />
  </svg>
);

export default function Icons() {
  return (
    <div className="flex flex-wrap items-center gap-3">
      <Button iconStart={<Plus />}>New project</Button>
      <Button variant="neutral" iconEnd={<Arrow />}>
        Continue
      </Button>
      <Button variant="ghost" aria-label="Add item" iconStart={<Plus />} />
    </div>
  );
}

Loading

Pass loading while work is in flight. The button can't be pressed again, keeps its width and focus, and screen readers hear that it's busy.

Button · LoadingLive
TSX
import { useState } from "react";
import { Button } from "plonk-ui";

const save = () => new Promise((resolve) => setTimeout(resolve, 1500));

export default function Loading() {
  const [saving, setSaving] = useState(false);
  const [saved, setSaved] = useState(false);

  async function handlePress() {
    setSaving(true);
    setSaved(false);
    await save();
    setSaving(false);
    setSaved(true);
  }

  return (
    <div className="flex items-center gap-4">
      <Button loading={saving} onPress={handlePress}>
        Save changes
      </Button>
      {saved && <span className="font-bold">Saved.</span>}
    </div>
  );
}

In a form

type="submit" submits the surrounding form, just like a native button.

Button · FormLive
import { useState, type FormEvent } from "react";
import { Button, Input } from "plonk-ui";

export default function Form() {
  const [email, setEmail] = useState<string | null>(null);

  function handleSubmit(event: FormEvent<HTMLFormElement>) {
    event.preventDefault();
    const data = new FormData(event.currentTarget);
    setEmail(String(data.get("email")));
  }

  return (
    <form onSubmit={handleSubmit} className="flex flex-wrap items-end gap-3">
      <Input
        label="Email"
        name="email"
        type="email"
        required
        placeholder="you@studio.com"
      />
      <Button type="submit">Subscribe</Button>
      {email && <p className="w-full font-bold">Subscribed: {email}</p>}
    </form>
  );
}

Personalities

Every personality has its own press. Sticker squashes and springs back like jelly, Retro snaps instantly, Comic shouts a sound effect where you clicked, and Arcade throws points into the air. To keep a button quiet, turn the effect off:

CSS
/* No POW! or +100 for these buttons */
.quiet {
  --plonk-press-effect: none;
}

Accessibility

  • Built on React Aria's button: Enter and Space press it, and focus is only shown for keyboard users.
  • loading keeps the button focusable and announces the busy state.
  • Icons are decorative. Give icon-only buttons an aria-label.
  • Reduced motion keeps the press feedback but drops jelly and effects.

API

PropTypeDefaultDescription
variant"neutral" | "primary" | "secondary" | "accent" | "danger" | "ghost""primary"Visual style. danger is for destructive actions.
size"sm" | "md" | "lg""md"Height and padding.
iconStartReactNode—Icon before the label. Hidden from screen readers; the label names the button.
iconEndReactNode—Icon after the label. Hidden from screen readers.
loadingbooleanfalseWork in progress: the button can't be pressed but keeps focus and its width, and the change is announced to screen readers.
disabledboolean—Same as isDisabled, for parity with HTML.
classNamestring—Extra classes, merged with Tailwind Merge.
styleCSSProperties—Inline styles, e.g. Plonk tokens for this button only.
onPress(e: PressEvent) => void—Called when pressed with mouse, touch or keyboard. Prefer it over onClick.
type"button" | "submit" | "reset""button"Native button type. Use submit inside forms.
isDisabledboolean—Disables the button.
autoFocusboolean—Focuses the button on mount.