Button
Primary, secondary, ghost and danger actions in three sizes, with optional leading or trailing icons and a pending state.
Variants
Primary uses the accent gradient and a soft colored glow. Secondary is a white raised surface.
"use client";
import { Button } from "@/components/ui/button";
export default function Example() {
return (
<div className="flex flex-wrap items-center gap-3">
<Button variant="primary">Find prospects</Button>
<Button variant="secondary">Export</Button>
<Button variant="ghost">Cancel</Button>
<Button variant="danger">Delete list</Button>
</div>
);
}Sizes
36, 40 and 44px tall, all radius 12.
"use client";
import { Button } from "@/components/ui/button";
export default function Example() {
return (
<div className="flex flex-wrap items-center gap-3">
<Button variant="primary" size="sm">Small · 36</Button>
<Button variant="primary" size="md">Medium · 40</Button>
<Button variant="primary" size="lg">Large · 44</Button>
</div>
);
}With icons
Padding tightens on the icon side. Icon-only buttons need an aria-label.
"use client";
import { ChevronDown, Plus, Sparkles } from "lucide-react";
import { Button } from "@/components/ui/button";
export default function Example() {
return (
<div className="flex flex-wrap items-center gap-3">
<Button variant="primary" leadingIcon={<Sparkles />}>Find prospects</Button>
<Button leadingIcon={<Plus />}>Add to list</Button>
<Button trailingIcon={<ChevronDown />}>Owner</Button>
<Button variant="primary" iconOnly aria-label="Add">
<Plus />
</Button>
<Button iconOnly aria-label="Add">
<Plus />
</Button>
</div>
);
}Pending and disabled
Press the first button to see the pending spinner.
"use client";
import { useState } from "react";
import { Button } from "@/components/ui/button";
export default function Example() {
const [pending, setPending] = useState(false);
const run = () => {
setPending(true);
setTimeout(() => setPending(false), 1500);
};
return (
<div className="flex flex-wrap items-center gap-3">
<Button variant="primary" isPending={pending} onPress={run}>
{pending ? "Enriching…" : "Enrich 24 prospects"}
</Button>
<Button variant="primary" isDisabled>Disabled</Button>
<Button isDisabled>Disabled</Button>
</div>
);
}Neutral, soft and outline
Neutral is a dark filled action; soft and outline are lower-emphasis accent styles; danger-soft for reversible destructive actions.
"use client";
import { Plus, Trash2 } from "lucide-react";
import { Button } from "@/components/ui/button";
export default function Example() {
return (
<div className="flex flex-wrap items-center gap-3">
<Button variant="neutral" leadingIcon={<Plus />}>New deal</Button>
<Button variant="soft">Enrich</Button>
<Button variant="outline">Preview</Button>
<Button variant="danger-soft" leadingIcon={<Trash2 />}>Remove</Button>
</div>
);
}Compact sizes
32 and 28px for card headers, toolbars and dense tables.
"use client";
import { Plus } from "lucide-react";
import { Button } from "@/components/ui/button";
export default function Example() {
return (
<div className="flex flex-wrap items-center gap-3">
<Button size="2xs" leadingIcon={<Plus />}>2XS · 28</Button>
<Button size="xs" leadingIcon={<Plus />}>XS · 32</Button>
<Button size="xs" variant="primary">See all</Button>
<Button size="2xs" variant="soft">Today</Button>
</div>
);
}Installation
Components are copied into your project — no runtime package.
Install the following dependencies:
terminalnpm install react-aria-components lucide-reactCreate a
button.tsxfile and paste the following code into it.src/components/ui/button.tsx"use client"; import { Loader2 } from "lucide-react"; import type { ReactNode } from "react"; import { Button as AriaButton, type ButtonProps as AriaButtonProps } from "react-aria-components"; import { cx } from "@/utils/cx"; export type ButtonVariant = "primary" | "secondary" | "ghost" | "danger" | "neutral" | "soft" | "outline" | "danger-soft"; export type ButtonSize = "2xs" | "xs" | "sm" | "md" | "lg"; export interface ButtonProps extends Omit<AriaButtonProps, "className" | "children"> { variant?: ButtonVariant; size?: ButtonSize; /** Icon rendered before the label. */ leadingIcon?: ReactNode; /** Icon rendered after the label. */ trailingIcon?: ReactNode; /** Square button with only an icon. Requires `aria-label`. */ iconOnly?: boolean; className?: string; children?: ReactNode; } const base = "group relative inline-flex shrink-0 cursor-default select-none items-center justify-center gap-2 whitespace-nowrap rounded-md text-base font-medium outline-none transition-[background,box-shadow,color] duration-150 " + "data-focus-visible:ring-3 data-focus-visible:ring-accent/25 " + "data-disabled:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0"; const variants: Record<ButtonVariant, string> = { primary: "bg-linear-to-b from-accent-light to-accent text-fg-inverse shadow-button-primary " + "data-hovered:from-accent data-hovered:to-accent-hover data-pressed:from-accent-pressed data-pressed:to-accent-pressed " + "data-disabled:bg-none data-disabled:bg-muted data-disabled:text-fg-disabled data-disabled:shadow-none", secondary: "bg-surface text-fg shadow-button data-hovered:bg-subtle data-pressed:bg-active " + "data-disabled:bg-muted data-disabled:text-fg-disabled data-disabled:shadow-none [&_svg]:text-fg-secondary", ghost: "text-fg data-hovered:bg-muted data-pressed:bg-active data-disabled:text-fg-disabled [&_svg]:text-fg-secondary", danger: "bg-error text-fg-inverse data-hovered:bg-error-hover data-pressed:bg-error-text " + "data-disabled:bg-muted data-disabled:text-fg-disabled", // Dark filled — for high-emphasis actions on light surfaces when accent would compete. neutral: "bg-inverse text-fg-inverse shadow-[0_1px_2px_rgb(0_0_0/0.12),inset_0_1px_0_rgb(255_255_255/0.08)] data-hovered:bg-fg/90 data-pressed:bg-fg/80 " + "data-disabled:bg-muted data-disabled:text-fg-disabled data-disabled:shadow-none", // Accent "lighter" — tinted, no shadow. soft: "bg-accent-soft text-accent-text data-hovered:bg-accent-soft-border data-pressed:bg-accent-soft-border " + "data-disabled:bg-muted data-disabled:text-fg-disabled", // Accent stroke on white. outline: "bg-surface text-accent-text shadow-[inset_0_0_0_1px_var(--color-accent-soft-border)] data-hovered:bg-accent-soft data-pressed:bg-accent-soft-border " + "data-disabled:bg-muted data-disabled:text-fg-disabled data-disabled:shadow-none", "danger-soft": "bg-error-soft text-error-text data-hovered:bg-error-border data-pressed:bg-error-border " + "data-disabled:bg-muted data-disabled:text-fg-disabled", }; // Heights: 28 / 32 / 36 / 40 / 44 (size/button-sm|md|lg plus compact sizes). Padding tightens on the icon side. const sizes: Record<ButtonSize, { base: string; lead: string; trail: string; icon: string }> = { "2xs": { base: "h-7 gap-1 rounded-sm px-2 text-sm [&_svg]:size-3.5", lead: "pl-1.5", trail: "pr-1.5", icon: "size-7 px-0" }, xs: { base: "h-8 gap-1.5 rounded-[10px] px-2.5", lead: "pl-2", trail: "pr-2", icon: "size-8 px-0" }, sm: { base: "h-9 px-3", lead: "pl-2", trail: "pr-2.5", icon: "size-9 px-0" }, md: { base: "h-10 px-4", lead: "pl-3", trail: "pr-3", icon: "size-10 px-0" }, lg: { base: "h-11 px-5", lead: "pl-4", trail: "pr-4", icon: "size-11 px-0" }, }; export function Button({ variant = "secondary", size = "md", leadingIcon, trailingIcon, iconOnly, isPending, className, children, ...props }: ButtonProps) { const s = sizes[size]; return ( <AriaButton {...props} isPending={isPending} className={cx( base, variants[variant], s.base, Boolean(leadingIcon) && !iconOnly && s.lead, Boolean(trailingIcon) && !iconOnly && s.trail, iconOnly && s.icon, className, )} > {isPending ? <Loader2 className="animate-spin" aria-hidden /> : leadingIcon} {iconOnly ? (isPending ? null : children) : children} {!iconOnly && trailingIcon} </AriaButton> ); }Add the theme tokens and the
cxhelper from Installation if you haven’t yet, then update the import paths to match your project setup.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "primary" | "secondary" | "ghost" | "danger" | "neutral" | "soft" | "outline" | "danger-soft" | "secondary" | Visual style. |
| size | "2xs" | "xs" | "sm" | "md" | "lg" | "md" | Height: 28, 32, 36, 40 or 44px. |
| leadingIcon | ReactNode | — | Icon before the label. |
| trailingIcon | ReactNode | — | Icon after the label. |
| iconOnly | boolean | false | Square button. Pass the icon as children. |
| isPending | boolean | false | Shows a spinner and blocks presses. |
| isDisabled | boolean | false | Disables the button. |
| onPress | (e: PressEvent) => void | — | Called on click, tap or keyboard activation. |