# Button

A pen-drawn box that lifts off a hatched shadow. Solid, outline, secondary, ghost, destructive and link.

Docs: https://ballpoint.st9wd.com/docs/button

```bash
npx shadcn@latest add @ballpoint/button
```

```tsx
import { Button } from "@/components/ui/button"

export function Actions() {
  return (
    <>
      <Button>Book a call</Button>
      <Button variant="outline">Copy email</Button>
    </>
  )
}
```

Props:

- `variant`: `"default" | "outline" | "secondary" | "ghost" | "destructive" | "link"` (default `"default"`). Shaded solid, boxed, hatched, drawn on hover, red pen, or underlined.
- `size`: `"default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg"` (default `"default"`). Height and type size. Icon sizes are square.
- `seed`: `string | number`. Pins the drawing. By default each button gets its own wobble, stable between server and client.

Pen settings: `draw`, `roughness`, `passes`, `radius`, `corners`, `fill`, `shadow`, `weight`, `speed` (see Pen settings).

Every other prop goes to Base UI's Button: https://base-ui.com/react/components/button

## Example

```tsx
import { Button } from "@/components/ui/button";
import { InkGlyph } from "@/lib/ink-glyphs";

export default function ButtonDemo() {
  return (
    <div className="flex flex-col gap-9">
      <div className="flex flex-wrap items-center gap-5">
        <Button seed="v-default">
          Book a call <InkGlyph name="arrow-up-right" />
        </Button>
        <Button variant="outline" seed="v-outline">
          Outline
        </Button>
        <Button variant="secondary" seed="v-secondary">
          Secondary
        </Button>
        <Button variant="destructive" seed="v-destructive">
          Destructive
        </Button>
      </div>
      <div className="flex flex-wrap items-center gap-5">
        <Button variant="ghost" seed="v-ghost">
          Ghost
        </Button>
        <Button variant="link" seed="v-link">
          Link
        </Button>
        <Button size="icon" variant="outline" seed="i-outline" aria-label="Add a page">
          <InkGlyph name="plus" />
        </Button>
        <Button size="icon" variant="ghost" seed="i-ghost" aria-label="Next page">
          <InkGlyph name="arrow-right" />
        </Button>
      </div>
      <div className="flex flex-wrap items-center gap-5">
        <Button size="xs" variant="outline" seed="s-xs">
          Extra small
        </Button>
        <Button size="sm" variant="outline" seed="s-sm">
          Small
        </Button>
        <Button variant="outline" seed="s-default">
          Default
        </Button>
        <Button size="lg" variant="outline" seed="s-lg">
          Large
        </Button>
      </div>
      <div className="flex flex-wrap items-center gap-5">
        <Button draw="mount" seed="mount">
          Draws itself in
        </Button>
        <Button variant="outline" seed="disabled" disabled>
          Disabled
        </Button>
      </div>
    </div>
  );
}
```

## Pen settings

Corners, roughness, weight, fills and shadows, per button or for a whole group with InkProvider.

```tsx
import { Button } from "@/components/ui/button";
import { InkProvider } from "@/hooks/use-ink-box";

export default function ButtonPens() {
  return (
    <div className="flex flex-col gap-8">
      <div className="flex flex-wrap items-center gap-5">
        <Button radius={10} seed="pen-rounded">
          Rounded
        </Button>
        <Button variant="outline" radius="full" seed="pen-pill">
          Pill
        </Button>
        <Button variant="secondary" radius={10} seed="pen-rounded-2">
          Rounded hatch
        </Button>
        <Button variant="outline" corners="joined" passes={2} seed="pen-joined">
          Joined corners
        </Button>
      </div>
      <div className="flex flex-wrap items-center gap-5">
        <Button roughness={0} passes={1} seed="pen-neat">
          Ruler-neat
        </Button>
        <Button roughness={2} seed="pen-scrawl">
          Scrawled
        </Button>
        <Button variant="outline" weight={1.8} seed="pen-heavy">
          Heavy pen
        </Button>
        <Button variant="outline" shadow="solid" seed="pen-solid-shadow">
          Solid shadow
        </Button>
      </div>
      <div className="flex flex-wrap items-center gap-5">
        <Button fill="hatch" seed="pen-fill-hatch">
          Cross-hatched
        </Button>
        <Button fill="scribble" seed="pen-fill-scribble">
          Scribbled
        </Button>
        <Button fill="flat" seed="pen-fill-flat">
          Flat ink
        </Button>
        <Button variant="secondary" fill="flat" seed="pen-fill-wash">
          Wash
        </Button>
      </div>
      {/* Pen settings apply to everything inside a provider. */}
      <InkProvider radius="full" roughness={1.4} shadow="none">
        <div className="flex flex-wrap items-center gap-5">
          <Button seed="pen-group-1">Save</Button>
          <Button variant="outline" seed="pen-group-2">
            Cancel
          </Button>
          <Button variant="destructive" seed="pen-group-3">
            Delete
          </Button>
        </div>
      </InkProvider>
    </div>
  );
}
```

## With icons

Icons sit beside the label, or stand alone in the icon sizes.

```tsx
import { Button } from "@/components/ui/button";
import { InkIcon } from "@/components/ui/ink-icons";

export default function ButtonIcons() {
  return (
    <div className="flex flex-col gap-8">
      <div className="flex flex-wrap items-center gap-5">
        <Button seed="bi-send">
          <InkIcon name="send" /> Send
        </Button>
        <Button variant="outline" seed="bi-download">
          <InkIcon name="download" /> Download
        </Button>
        <Button variant="secondary" seed="bi-mail">
          Email me <InkIcon name="mail" />
        </Button>
        <Button variant="ghost" seed="bi-copy">
          <InkIcon name="copy" /> Copy link
        </Button>
      </div>
      <div className="flex flex-wrap items-center gap-5">
        <Button size="icon-xs" variant="outline" seed="bi-xs" aria-label="Bookmark">
          <InkIcon name="bookmark" />
        </Button>
        <Button size="icon-sm" variant="outline" seed="bi-sm" aria-label="Star">
          <InkIcon name="star" />
        </Button>
        <Button size="icon" variant="outline" seed="bi-md" aria-label="Settings">
          <InkIcon name="settings" />
        </Button>
        <Button size="icon-lg" variant="outline" seed="bi-lg" aria-label="Delete">
          <InkIcon name="trash" />
        </Button>
        <Button size="icon" variant="destructive" seed="bi-destructive" aria-label="Delete forever">
          <InkIcon name="trash" />
        </Button>
      </div>
    </div>
  );
}
```

## Loading

Disable the button while it works and show a spinning loop; the label says what is happening.

```tsx
"use client";

import { useState } from "react";
import { Button } from "@/components/ui/button";
import { InkGlyph } from "@/lib/ink-glyphs";

export default function ButtonLoading() {
  const [pending, setPending] = useState(false);
  const save = () => {
    setPending(true);
    setTimeout(() => setPending(false), 1800);
  };
  return (
    <div className="flex flex-wrap items-center gap-5">
      <Button onClick={save} disabled={pending} seed="bl-save">
        {pending && <InkGlyph name="loading" className="motion-safe:animate-spin" />}
        {pending ? "Saving…" : "Save changes"}
      </Button>
      <Button variant="outline" disabled seed="bl-disabled">
        <InkGlyph name="loading" className="motion-safe:animate-spin" /> Please wait
      </Button>
    </div>
  );
}
```

## As a link

Render the button's drawing on an <a> with render and nativeButton={false}.

```tsx
import { Button } from "@/components/ui/button";
import { InkGlyph } from "@/lib/ink-glyphs";

// `render` puts the button's drawing on any element; for a link, say it isn't a <button>.
export default function ButtonLink() {
  return (
    <div className="flex flex-wrap items-center gap-5">
      <Button render={<a href="#docs" />} nativeButton={false} seed="bk-docs">
        Read the docs <InkGlyph name="arrow-right" />
      </Button>
      <Button render={<a href="https://github.com/useit015/ballpoint" />} nativeButton={false} variant="outline" seed="bk-github">
        GitHub <InkGlyph name="arrow-up-right" />
      </Button>
      <Button render={<a href="#changelog" />} nativeButton={false} variant="link" seed="bk-changelog">
        What&apos;s new
      </Button>
    </div>
  );
}
```

## Form actions

Cancel, save and publish in order of weight; a destructive choice beside a quiet alternative.

```tsx
import { Button } from "@/components/ui/button";

export default function ButtonActions() {
  return (
    <div className="flex w-full max-w-md flex-col gap-8">
      <div className="flex flex-wrap items-center justify-end gap-3">
        <Button variant="ghost" seed="ba-cancel">
          Cancel
        </Button>
        <Button variant="outline" seed="ba-draft">
          Save draft
        </Button>
        <Button seed="ba-publish">Publish</Button>
      </div>
      <div className="flex flex-wrap items-center justify-between gap-3">
        <p className="text-ink-2">Delete this notebook for good?</p>
        <div className="flex gap-3">
          <Button variant="outline" size="sm" seed="ba-keep">
            Keep it
          </Button>
          <Button variant="destructive" size="sm" seed="ba-delete">
            Delete
          </Button>
        </div>
      </div>
    </div>
  );
}
```

## Pen settings

- `draw`: `"auto" | "mount" | "none"` (default `"auto"`). When the strokes draw themselves in: the first time they scroll into view, as soon as they render, or never (already drawn).
- `roughness`: `number` (default `1`). 0 is ruler-neat, 1 a quick confident hand, 2 a scrawl.
- `passes`: `1 | 2 | 3`. How many times an outline is gone over. Each component picks its own default.
- `radius`: `number | "full"` (default `0`). Corner radius in px; "full" draws a pill.
- `corners`: `"crossed" | "joined"` (default `"crossed"`). Square corners: sides pulled separately past each other, or the box drawn in one motion.
- `fill`: `"shade" | "hatch" | "scribble" | "flat"`. How an area is coloured in. Solid parts default to shade, light ones to hatch.
- `shadow`: `"hatch" | "solid" | "none"` (default `"hatch"`). What a lifted box leaves on the paper. "none" turns the lift off too.
- `weight`: `number` (default `1`). Line weight multiplier. Also settable in CSS as --ink-weight.
- `speed`: `number` (default `1`). Drawing speed multiplier. Also settable in CSS as --ink-speed.
