Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Button

FreeNew

The 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.

button-demo.tsx
"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

PropTypeDefault
variantVariant

Visual weight. Use one `primary` per view.

"primary"
sizeSize

`icon` is a square for a single icon; give it an `aria-label`.

"md"
loadingboolean

Shows a spinner in place of the label and ignores presses. The width does not change and focus stays on the button.

false
loadingTextstring

What screen readers hear while `loading` is set.

"Loading"
asChildboolean

Style 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.