Button
Triggers an action. Renders a native button unless asChild is set, in which
case it forwards its styling to whatever it wraps.
import { Button } from "antlitz";
API
| Prop | Type | Default |
|---|---|---|
| asChild | boolean | false |
| command | "show-modal" | "close" | "request-close" | "show-popover" | "hide-popover" | "toggle-popover" | `--${string}` | — |
| commandFor | string | — |
| loading | boolean | false |
| radius | "none" | "sm" | "md" | "lg" | "full" | none |
| size | "xs" | "sm" | "md" | "lg" | "icon-sm" | "icon" | "icon-lg" | md |
| tone | "base" | "muted" | "subtle" | base |
| variant | "solid" | "soft" | "outline" | "ghost" | "danger" | "danger-soft" | "link" | "plain" | solid |
Every remaining prop is forwarded to the underlying element, so
React.ButtonHTMLAttributes applies in full.
Variants
export function Variants() {
return VARIANTS.map((variant) => (
<Button key={variant} variant={variant}>
{variant}
</Button>
));
}link styles the button as inline text, for destructive confirmations that
should not look like primary actions.
Sizes
export function Sizes() {
return (
<>
<Button size="xs">Extra small</Button>
<Button size="sm">Small</Button>
<Button size="md">Medium</Button>
<Button size="lg">Large</Button>
</>
);
}sm, md and lg are the same heights as Input and Select at the same
size — 30, 38 and 46 pixels — so a field and its button line up at every step.
xs sits below the field scale, for buttons inside dense rows.
export function IconSizes() {
return (["icon-sm", "icon", "icon-lg"] as const).map((size) => (
<Button key={size} size={size} variant="outline" aria-label="Add">
<Icon size={16}>
<path d="M12 5v14M5 12h14" />
</Icon>
</Button>
));
}The icon sizes are square and expect a single Icon child rather than a
label. icon-sm, icon and icon-lg match sm, md and lg.
export function Alignment() {
return (["sm", "md", "lg"] as const).map((size) => (
<div key={size} className="flex w-full max-w-md gap-2">
<Input size={size} placeholder={`Input ${size}`} />
<Button size={size}>Button</Button>
<Button
size={size === "md" ? "icon" : `icon-${size}`}
variant="outline"
aria-label="Search"
>
<Icon size={16}>
<circle cx="11" cy="11" r="7" />
<path d="m20 20-3.5-3.5" />
</Icon>
</Button>
</div>
));
}Radius
export function Radius() {
return RADII.map((radius) => (
<Button key={radius} variant="outline" radius={radius}>
{radius}
</Button>
));
}Tones
export function Tones() {
return (
<>
<Button variant="ghost" tone="base">
Base
</Button>
<Button variant="ghost" tone="muted">
Muted
</Button>
<Button variant="ghost" tone="subtle">
Subtle
</Button>
</>
);
}Tone shifts the foreground only, so it applies to variants that do not paint a background of their own.
States
export function States() {
return (
<>
<Button loading>Saving</Button>
<Button variant="outline" loading>
Saving
</Button>
<Button disabled>Disabled</Button>
<Button variant="outline" size="icon" aria-label="Loading" loading />
</>
);
}loading adds a Spinner before the label and sets aria-busy. It also
disables the button, so loading and disabled need not be combined.
The spinner is hidden from assistive technology. aria-busy already reports
the state, so the button keeps its own name rather than being announced as
"Loading Saving".
Commands
export function Commands() {
return (
<>
<Button
variant="outline"
command="toggle-popover"
commandFor="button-command"
>
Toggle
</Button>
<Popover id="button-command">Opened by an invoker command.</Popover>
</>
);
}command and commandFor are the native invoker command attributes: the
button acts on the element whose id is in commandFor. show-modal,
close and request-close drive a dialog; toggle-popover,
show-popover and hide-popover drive a popover; a custom --name reaches
the target as a command event for your own script to handle.
React does not know these attributes yet, so Button takes them as props and writes them to the element itself. Invoker commands are recent — a browser without them ignores the attributes, and the button does nothing.
Composition
export function Composition() {
return (
<>
<Button asChild variant="outline">
<Link href="/components/link" variant="plain">
Internal
</Link>
</Button>
<Button asChild>
<Link href="https://example.com" variant="plain">
External
</Link>
</Button>
</>
);
}asChild merges Button's styling onto its child rather than nesting an
element, which avoids invalid a > button markup.