Button
FreeNewThe base button: six variants, four sizes, a press that gives slightly and a loading state that keeps its width.
Installation
pnpm dlx shadcn@latest add @viewport/button
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above.
"use client";
import { useState } from "react";
import { ArrowUpRight, Plus, Trash2 } from "lucide-react";
import { Button } from "@/components/viewport/button";
export default function ButtonDemo() {
const [saving, setSaving] = useState(false);
return (
<div className="flex w-full max-w-md flex-col items-center gap-5">
<div className="flex flex-wrap items-center justify-center gap-2">
<Button
loading={saving}
loadingText="Saving changes"
onClick={() => {
setSaving(true);
setTimeout(() => setSaving(false), 1600);
}}
>
Save changes
</Button>
<Button variant="secondary">Preview</Button>
<Button variant="outline">
<Plus aria-hidden />
New view
</Button>
<Button variant="ghost">Cancel</Button>
</div>
<div className="flex flex-wrap items-center justify-center gap-2">
<Button variant="destructive" size="sm">
<Trash2 aria-hidden />
Delete
</Button>
<Button variant="outline" size="icon" aria-label="Add item">
<Plus aria-hidden />
</Button>
<Button size="lg">Get started</Button>
<Button variant="link" asChild>
<a href="#docs">
Read the docs
<ArrowUpRight aria-hidden />
</a>
</Button>
</div>
</div>
);
}Props
| Prop | Type | Default |
|---|---|---|
| variant | VariantVisual weight. Use one `primary` per view. | "primary" |
| size | Size`icon` is a square for a single icon; give it an `aria-label`. | "md" |
| loading | booleanShows a spinner in place of the label and ignores presses. The width does not change and focus stays on the button. | false |
| loadingText | stringWhat screen readers hear while `loading` is set. | "Loading" |
| asChild | booleanStyle the child element instead of rendering a button, e.g. a link. | false |
Accessibility
- A native button; `asChild` styles a link without changing its role.
- While loading it stays focusable, sets aria-busy and reads a loading message.
- A 44px tall hit area on touch screens.
- Respects prefers-reduced-motion.