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>Send invite</Button>Usage
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.
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
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.
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.
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.
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:
/* 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.
loadingkeeps 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
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "neutral" | "primary" | "secondary" | "accent" | "danger" | "ghost" | "primary" | Visual style. danger is for destructive actions. |
size | "sm" | "md" | "lg" | "md" | Height and padding. |
iconStart | ReactNode | — | Icon before the label. Hidden from screen readers; the label names the button. |
iconEnd | ReactNode | — | Icon after the label. Hidden from screen readers. |
loading | boolean | false | Work in progress: the button can't be pressed but keeps focus and its width, and the change is announced to screen readers. |
disabled | boolean | — | Same as isDisabled, for parity with HTML. |
className | string | — | Extra classes, merged with Tailwind Merge. |
style | CSSProperties | — | 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. |
isDisabled | boolean | — | Disables the button. |
autoFocus | boolean | — | Focuses the button on mount. |