# Margin Note

A handwritten aside out in the margin, with an arrow (or a line) drawn to the words it's about, and the words themselves underlined, circled, boxed or highlighted; under the line on narrow screens.

Docs: https://ballpoint.st9wd.com/docs/margin-note

```bash
npx shadcn@latest add @ballpoint/margin-note
```

```tsx
import { MarginNote } from "@/components/ui/margin-note"

<p className="max-w-xs">
  Every box is drawn as four pulls, and{" "}
  <MarginNote note="took three tries">the corners cross</MarginNote>.
</p>
```

Props:

- `note`: `ReactNode`. What's written in the margin.
- `side`: `"left" | "right"` (default `"right"`). Which margin. Below lg the note drops in under the line instead.
- `color`: `"ink" | "red" | "pencil"` (default `"ink"`). The ink, the red pen for a correction, or pencil, lighter and slanted.
- `className`: `string`. Styles the note; --margin-note-width (9rem) and --margin-note-gap (2.5rem) set its size and distance.
- `pointer`: `"arrow" | "line" | "none"` (default `"arrow"`). What is drawn from the note to the words: a headed arrow, a plain line, or nothing.
- `mark`: `"none" | "underline" | "circle" | "box" | "highlight"` (default `"none"`). A mark drawn on the words themselves, in the note's colour (it uses Annotate).
- `tilt`: `number` (default `-1.5`). Degrees the note is turned from level.
- `width`: `string` (default `"9rem"`). How wide the note is out in the margin, as a CSS length.
- `seed`: `string | number`. Pins the drawing.

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

## Example

```tsx
import { MarginNote } from "@/components/ui/margin-note";

export default function MarginNoteDemo() {
  return (
    <div className="w-full max-w-xl">
      <p className="max-w-xs text-lg leading-relaxed text-ink-2">
        Every box is drawn as four pulls of the pen, and{" "}
        <MarginNote note="took three tries to get right" seed="margin-note-corners">
          the corners cross
        </MarginNote>{" "}
        the way they do when you sketch one quickly. The seed keeps the wobble the same on the server and in the browser.
      </p>
    </div>
  );
}
```

## Left, and in red

Flip the side, or use red for a correction.

```tsx
import { MarginNote } from "@/components/ui/margin-note";

export default function MarginNoteSides() {
  return (
    <div className="flex w-full max-w-xl flex-col gap-8">
      <p className="max-w-xs self-center text-lg leading-relaxed text-ink-2">
        <MarginNote side="left" note="the other margin" seed="mns-left">
          This note
        </MarginNote>{" "}
        sits on the left, where the first words of a line leave room for it.
      </p>
      <p className="max-w-xs self-center text-lg leading-relaxed text-ink-2">
        Use red for a correction: the figure was{" "}
        <MarginNote color="red" note="check this!" seed="mns-red">
          4,000
        </MarginNote>
        , not 400.
      </p>
    </div>
  );
}
```

## In an essay

Notes along a paragraph, one in ink and one in red pen.

```tsx
import { MarginNote } from "@/components/ui/margin-note";

export default function MarginNoteEssay() {
  return (
    <div className="w-full max-w-2xl">
      <p className="max-w-sm text-lg leading-relaxed text-ink-2">
        A good pen is{" "}
        <MarginNote note="not the expensive one" seed="mne-a">
          one you forget you are holding
        </MarginNote>
        . It starts on the first try, writes as fast as you think, and leaves a line you would{" "}
        <MarginNote note="check this!" color="red" seed="mne-b">
          not mind being read in
        </MarginNote>{" "}
        ten years. The paper matters just as much.
      </p>
    </div>
  );
}
```

## Marking the words

mark underlines, circles, boxes or highlights what the note is about, in the note's colour.

```tsx
import { MarginNote } from "@/components/ui/margin-note";

const p = "max-w-xs self-center text-lg leading-relaxed text-ink-2";

export default function MarginNoteMarks() {
  return (
    <div className="flex w-full max-w-2xl flex-col gap-7">
      <p className={p}>
        The note can underline{" "}
        <MarginNote mark="underline" note="underlined" seed="mm-a">
          the words
        </MarginNote>
        .
      </p>
      <p className={p}>
        <MarginNote mark="circle" note="ringed, for a name" seed="mm-b">
          Ada Lovelace
        </MarginNote>{" "}
        gets a ring.
      </p>
      <p className={p}>
        A highlight for{" "}
        <MarginNote mark="highlight" note="the date" seed="mm-c">
          14 October
        </MarginNote>
        .
      </p>
      <p className={p}>
        And a box round the{" "}
        <MarginNote mark="box" color="red" note="check the figure" seed="mm-d">
          4,000
        </MarginNote>
        .
      </p>
    </div>
  );
}
```

## Arrows, lines, none

The pointer drawn as an arrow, a plain line, or left out; and the note tilted the other way.

```tsx
import { MarginNote } from "@/components/ui/margin-note";

const p = "max-w-xs self-center text-lg leading-relaxed text-ink-2";

export default function MarginNotePointers() {
  return (
    <div className="flex w-full max-w-2xl flex-col gap-7">
      <p className={p}>
        The default is a curved{" "}
        <MarginNote pointer="arrow" note="pointer=&quot;arrow&quot;" seed="mp-a">
          arrow
        </MarginNote>{" "}
        to the words.
      </p>
      <p className={p}>
        Quieter still is a plain{" "}
        <MarginNote pointer="line" note="pointer=&quot;line&quot;, tilted the other way" tilt={2.5} seed="mp-b">
          line
        </MarginNote>
        .
      </p>
      <p className={p}>
        And with nothing between them, a mark does{" "}
        <MarginNote pointer="none" color="pencil" mark="underline" note="no pointer, in pencil" seed="mp-c">
          the work
        </MarginNote>
        .
      </p>
    </div>
  );
}
```

## A review

Notes on a draft, in ink, red pen and pencil, each with its own mark and width.

```tsx
import { MarginNote } from "@/components/ui/margin-note";
import { Paper } from "@/components/ui/paper";

export default function MarginNoteReview() {
  return (
    <Paper lifted edge="dog-ear" stains={1} seed="mnr" className="w-full max-w-2xl px-8 py-8">
      <h4 className="mb-4 text-xl font-bold">Launch post, draft 2</h4>
      <ul className="flex max-w-sm flex-col gap-5 text-lg leading-relaxed text-ink-2">
        <li>
          We are{" "}
          <MarginNote mark="underline" note="good opening" seed="mnr-a" width="7rem">
            proud to announce
          </MarginNote>{" "}
          a library drawn by hand.
        </li>
        <li>
          It ships in{" "}
          <MarginNote mark="circle" color="red" note="still right?" seed="mnr-b" width="7rem">
            November
          </MarginNote>
          .
        </li>
        <li>
          With{" "}
          <MarginNote mark="highlight" color="pencil" note="ask legal" seed="mnr-c" width="7rem">
            forty components
          </MarginNote>{" "}
          to start.
        </li>
      </ul>
    </Paper>
  );
}
```

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