# Annotate

Marks a word or phrase the way you would with a pen: underlined, circled, boxed, struck through, scribbled out, bracketed or shaded in, drawn as it scrolls into view.

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

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

```tsx
import { Annotate } from "@/components/ui/annotate"

<p>
  The build <Annotate type="circle" color="red">failed</Annotate> twice.
</p>
```

Props:

- `type`: `"underline" | "circle" | "box" | "strike" | "scribble" | "bracket" | "highlight"` (default `"underline"`). The mark. A highlight is shaded in behind the words.
- `color`: `"ink" | "red"` (default `"ink"`). The ink, or the red pen corrections are made in.
- `as`: `"span" | "mark" | "del" | "s" | "ins" | "em" | "strong"` (default `"span"`). The element: mark for a highlight, del or s for words struck out, so the meaning survives without the drawing.
- `delay`: `number` (default `0`). ms after it scrolls into view before the pen starts. Rising delays draw a run of marks one after another.
- `active`: `boolean`. Draws the mark while true and pulls it back out when false, instead of drawing it once.
- `brackets`: `"both" | "left" | "right"` (default `"both"`). Which brackets a bracket draws.
- `seed`: `string | number`. Pins the drawing.

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

## Example

```tsx
import { Annotate } from "@/components/ui/annotate";

export default function AnnotateDemo() {
  return (
    <p className="max-w-md text-lg leading-loose text-ink-2">
      The plan was to{" "}
      <Annotate type="underline" seed="annotate-ship">
        ship on Friday
      </Annotate>
      . The build{" "}
      <Annotate type="circle" color="red" delay={500} seed="annotate-failed">
        failed
      </Annotate>{" "}
      twice, so we{" "}
      <Annotate type="scribble" as="del" delay={1000} seed="annotate-blamed">
        blamed the cache
      </Annotate>{" "}
      <Annotate type="highlight" as="mark" delay={1500} seed="annotate-read">
        read the logs
      </Annotate>{" "}
      and found it in{" "}
      <Annotate type="box" delay={2000} seed="annotate-minutes">
        ten minutes
      </Annotate>
      .
    </p>
  );
}
```

## Seven marks

Underline, circle, box, strike, scribble, bracket and highlight, in the ink or the red pen.

```tsx
import { Annotate, type AnnotateType } from "@/components/ui/annotate";

const types: AnnotateType[] = ["underline", "circle", "box", "strike", "scribble", "bracket", "highlight"];

export default function AnnotateTypes() {
  return (
    <ul className="grid gap-x-12 gap-y-7 text-lg sm:grid-cols-2">
      {types.map((type, i) => (
        <li key={type} className="flex items-baseline justify-between gap-6">
          <span className="text-sm text-ink-3">{type}</span>
          <Annotate type={type} color={type === "circle" || type === "strike" ? "red" : "ink"} delay={i * 200} seed={`annotate-${type}`}>
            a ballpoint
          </Annotate>
        </li>
      ))}
    </ul>
  );
}
```

## On and off

With active, a mark draws in when it turns true and pulls back out when it turns false.

```tsx
"use client";

import { useState } from "react";
import { Annotate } from "@/components/ui/annotate";
import { Button } from "@/components/ui/button";

export default function AnnotateActive() {
  const [done, setDone] = useState(false);
  return (
    <div className="flex flex-col items-center gap-6">
      <p className="text-lg text-ink-2">
        <Annotate type="strike" active={done} seed="annotate-milk">
          Buy milk
        </Annotate>{" "}
        and{" "}
        <Annotate type="circle" color="red" active={!done} seed="annotate-call">
          call the plumber
        </Annotate>
      </p>
      <Button variant="outline" size="sm" seed="annotate-toggle" onClick={() => setDone((d) => !d)}>
        {done ? "Not done yet" : "Done"}
      </Button>
    </div>
  );
}
```

## In running text

Marks mixed through a changelog: a title underline, a highlight, a red strike and a boxed link.

```tsx
import { Annotate } from "@/components/ui/annotate";

export default function AnnotateReview() {
  return (
    <article className="flex max-w-md flex-col gap-4 text-lg leading-loose text-ink-2">
      <h3 className="text-xl font-bold text-ink">
        <Annotate type="underline" seed="ar-title">
          Release notes
        </Annotate>
      </h3>
      <p>
        This version is <Annotate type="highlight" as="mark" seed="ar-faster" delay={300}>twice as fast</Annotate>, and the{" "}
        <Annotate type="strike" color="red" as="del" seed="ar-old" delay={600}>
          old config file
        </Annotate>{" "}
        is gone. Read the <Annotate type="box" seed="ar-guide" delay={900}>migration guide</Annotate> first.
      </p>
      <p>
        Questions? <Annotate type="bracket" seed="ar-ask" delay={1200}>Ask in the issues</Annotate>.
      </p>
    </article>
  );
}
```

## 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.
- `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.
