Button
Button
The base action: variants, 24–40px sizes, a 3% press, and status (pending, success, error) shown through an icon slot and a morphing label.
Dependencies
Interaction states
- idle — Resting button: filled primary, or a 1px thin line for secondary and outline.
- pressed — Gives 3% and settles back in 200ms (none with reduced motion).
- pending — The icon slot opens and a spinner blurs in; the label morphs; aria-busy, clicks swallowed, focus kept.
- success / error — A check draws itself, or an alert with a short shake; icon-only buttons swap their icon the same way.
- disabled — 45% opacity and a default cursor.
Installation
Add this component with your preferred package manager.
pnpm dlx shadcn@4.21.5 add @cavemio/buttonFirst install? Configure @cavemio once
Run npx shadcn@4.21.5 init if shadcn is not set up, then merge this entry into the registries field in your existing components.json. Keep your other settings and registries.
{
"registries": {
"@cavemio": "https://registry.cavemio.dev/r/cavemio-{name}.json"
}
}Where it’s used
Form submits
Primary actions with in-place loading state that retains keyboard focus.
Toolbars & headers
Secondary and ghost buttons with thin line borders and adaptive press feel.
Destructive dialogs
Clean destructive actions with clear visual distinction and no blurry glow.
Icon triggers
Concentric square icon buttons with deeper tactile push feedback.
What it handles
- Adaptive press scale — Small icon buttons push deeper (0.95), wide buttons push subtly (0.985), and floating anchor triggers never scale so popover bounds remain pixel-perfect.
- Smooth width morphing — When children or labels change, the button measures the new natural width and glides smoothly without jumping surrounding layout.
- In-place loading state — Loading morphs a centered spinner into place while keeping the button focusable (aria-disabled) so keyboard users never lose their place.
- thin line 1px precision — Pure 1px border tokens with zero fuzzy drop shadows and full dark mode compatibility.
Usage
Interactive local fixture. Data and async results are simulated in the preview; the caller supplies application services.
import { Button } from "@/components/button";
<Button variant="primary" size="md">Save changes</Button>
<Button variant="secondary" loading={isSaving}>Deploy</Button>Props
| Prop | Type | Description |
|---|---|---|
| variant | "primary" | "secondary" | "outline" | "ghost" | "destructive" | "link" | "primary" · Visual appearance of the button. |
| size | "xs" | "sm" | "md" | "lg" | "icon" | "md" · Height and typographic scale. |
| loading | boolean | false · Shows an in-place spinner while retaining keyboard focus. |
| icon | ReactNode | – · Leading icon slot. |
| trailingIcon | ReactNode | – · Trailing icon slot. |
| disabled | boolean | false · Disables user interaction. |
Accessibility & motion
- No external animation libraries: uses CSS transitions and native layout geometry. - Anchor triggers for Popovers and Dropdowns are guarded from press scaling to preserve positioning geometry. - Strict 1px thin line styling with zero drop shadows.
pnpm dlx shadcn@4.21.5 add @cavemio/button