# Scrawl

The scratches a ballpoint leaves in a margin while it gets going (a zigzag, a worked-over corner, a star, slashes, a spiral, loops, a wave) and a proofreader's marks (a cross, an asterisk, a ring, a tick), in ink or red pen.

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

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

```tsx
import { Scrawl } from "@/components/ui/scrawl"

<section className="relative">
  <Scrawl kind="star" rotate={-8} className="absolute -right-16 top-4" />
  …
</section>
```

Props:

- `kind`: `"zigzag" | "corner" | "star" | "slash" | "spiral" | "loops" | "waves" | "cross" | "asterisk" | "ring" | "tick"` (default `"zigzag"`). Which scribble: the ones a pen makes while it gets going (zigzag, corner, star, slash, spiral, loops, waves), or a proofreader's marks (cross, asterisk, ring, tick).
- `scale`: `number` (default `1`). Size; the line stays the same weight.
- `rotate`: `number` (default `0`). Degrees.
- `delay`: `number` (default `0`). ms after it comes into view before the pen starts.
- `color`: `"ink" | "red"` (default `"ink"`). The ink, or the red pen.
- `flip`: `boolean` (default `false`). Mirror it, so the same scribble can lean the other way.
- `retrace`: `number`. 0 to 1: how much of it the pen goes back over. Each kind has its own habit (a spiral none, a zigzag most of it).
- `weight`: `number` (default `1`). Line weight multiplier. Also settable in CSS as --ink-weight.
- `seed`: `string | number`. Pins the drawing.

Pen settings: `draw`, `weight`, `speed` (see Pen settings).

## Example

```tsx
import { Scrawl, type ScrawlKind } from "@/components/ui/scrawl";

const kinds: ScrawlKind[] = ["zigzag", "corner", "star", "slash"];

export default function ScrawlDemo() {
  return (
    <ul className="flex flex-wrap items-end justify-center gap-x-12 gap-y-8">
      {kinds.map((kind, i) => (
        <li key={kind} className="flex flex-col items-center gap-3">
          <Scrawl kind={kind} seed={`scrawl-${kind}`} delay={i * 250} scale={kind === "corner" ? 0.8 : 1} />
          <span className="text-sm text-ink-3">{kind}</span>
        </li>
      ))}
    </ul>
  );
}
```

## As a stamp

Position a scrawl on a corner of a card, staggering the delay so each is drawn in turn.

```tsx
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Scrawl } from "@/components/ui/scrawl";

export default function ScrawlStamp() {
  return (
    <div className="relative w-full max-w-sm">
      <Card seed="ss-card">
        <CardHeader>
          <CardTitle>Draft: launch post</CardTitle>
          <CardDescription>Reviewed by two people.</CardDescription>
        </CardHeader>
        <CardContent className="text-ink-2">Looks good. Ship it on Tuesday.</CardContent>
      </Card>
      <Scrawl kind="star" rotate={-10} delay={400} seed="ss-star" className="absolute -top-5 -right-4" />
      <Scrawl kind="slash" scale={1.4} rotate={-4} delay={900} seed="ss-slash" className="absolute -bottom-3 left-8" />
    </div>
  );
}
```

## As dividers

A scrawl between sections, a different one each time.

```tsx
import { Scrawl } from "@/components/ui/scrawl";

const sections = [
  ["Mornings", "Coffee, then the first page.", "zigzag"],
  ["Afternoons", "Letters, lists and errands.", "star"],
  ["Evenings", "Sketching until the lamp goes on.", "slash"],
] as const;

export default function ScrawlDividers() {
  return (
    <div className="flex w-full max-w-md flex-col gap-4">
      {sections.map(([title, note, kind], i) => (
        <div key={title} className="flex flex-col gap-4">
          {i > 0 && <Scrawl kind={kind} scale={0.7} seed={`sd-${kind}`} delay={i * 200} className="self-center text-ink-3" />}
          <section>
            <h4 className="text-xl font-bold">{title}</h4>
            <p className="text-ink-2">{note}</p>
          </section>
        </div>
      ))}
    </div>
  );
}
```

## Seven more

A spiral, a row of loops, a wave, and the marks of a proofreader: cross, asterisk, ring and tick.

```tsx
import { Scrawl, type ScrawlKind } from "@/components/ui/scrawl";

const kinds: ScrawlKind[] = ["spiral", "loops", "waves", "cross", "asterisk", "ring", "tick"];

export default function ScrawlKinds() {
  return (
    <ul className="grid w-full max-w-xl grid-cols-2 items-end gap-x-10 gap-y-9 sm:grid-cols-4">
      {kinds.map((kind, i) => (
        <li key={kind} className="flex flex-col items-center gap-3">
          <Scrawl kind={kind} seed={`sk-${kind}`} delay={i * 200} />
          <span className="font-mono text-sm text-ink-3">{kind}</span>
        </li>
      ))}
    </ul>
  );
}
```

## Red pen

A tick, a ring, an asterisk and a cross, scaled down and set beside a to-do list.

```tsx
import { Scrawl } from "@/components/ui/scrawl";

const lines = [
  ["Buy more blue pens", "tick"],
  ["Finish the draft by Friday", "ring"],
  ["Ask about the old notebook", "asterisk"],
  ["Paint the shed", "cross"],
] as const;

export default function ScrawlRed() {
  return (
    <ul className="flex w-full max-w-sm flex-col gap-5 text-lg">
      {lines.map(([text, kind], i) => (
        <li key={text} className="relative flex items-center gap-4">
          <span className="relative w-12 shrink-0">
            <Scrawl kind={kind} color="red" scale={0.7} seed={`sr-${kind}`} delay={i * 300} className="absolute -top-5 left-0" />
          </span>
          <span className="text-ink-2">{text}</span>
        </li>
      ))}
    </ul>
  );
}
```

## Testing the pen

The first page of a new notebook: a spiral, loops, a wave and a zigzag, on ruled paper.

```tsx
import { Paper } from "@/components/ui/paper";
import { Scrawl } from "@/components/ui/scrawl";

export default function ScrawlPenTest() {
  return (
    <Paper variant="ruled" margin edge="torn" lifted seed="spt" tilt={-0.8} className="w-full max-w-md pb-5">
      <p className="text-ink-3">Testing the new pen</p>
      <div className="relative h-[6rem]">
        <Scrawl kind="spiral" scale={1.1} seed="spt-a" delay={100} className="absolute top-1 left-0" />
        <Scrawl kind="loops" scale={1.3} seed="spt-b" delay={500} className="absolute top-0 left-20" />
        <Scrawl kind="waves" seed="spt-c" delay={900} className="absolute top-14 left-6" />
        <Scrawl kind="zigzag" scale={0.7} rotate={90} seed="spt-d" delay={1200} className="absolute top-2 right-4" />
      </div>
      <p>Works. Smooth, too.</p>
    </Paper>
  );
}
```

## In the margins

Marks around a paragraph, as if someone had read it with a pen in hand.

```tsx
import { Scrawl } from "@/components/ui/scrawl";

export default function ScrawlMargins() {
  return (
    <div className="relative w-full max-w-md px-10 py-6">
      <Scrawl kind="asterisk" color="red" scale={0.6} seed="sm-a" delay={300} className="absolute top-5 left-1" />
      <Scrawl kind="tick" color="red" scale={0.7} seed="sm-b" delay={700} className="absolute top-28 left-0" />
      <Scrawl kind="ring" scale={0.7} seed="sm-c" delay={1000} className="absolute right-0 bottom-8" flip />
      <p className="text-lg leading-relaxed text-ink-2">
        Read slowly, the whole page is drawn in the margins as well: a star where something was important, a tick where it checked out, and a
        ring round the one line worth coming back to. Nobody drew them to be looked at. They are the sound of someone reading with a pen in
        hand.
      </p>
    </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).
- `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.
