# Alert

A note boxed off from the page; the destructive one in red pen.

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

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

```tsx
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"

<Alert variant="destructive">
  <AlertTitle>The page couldn't be saved</AlertTitle>
  <AlertDescription>The connection dropped halfway.</AlertDescription>
</Alert>
```

Props:

- `variant`: `"default" | "note" | "destructive"` (default `"default"`). Pencil, hatched lightly across like a margin highlight, or red pen.
- `fill`: `"hatch" | "flat"`. How the note variant is coloured in: hatching, or a flat wash.
- `seed`: `string | number`. Pins the drawing.

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

## Example

```tsx
import { Alert, AlertAction, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import { InkGlyph } from "@/lib/ink-glyphs";

export default function AlertDemo() {
  return (
    <div className="flex w-full max-w-xl flex-col gap-6">
      <Alert seed="alert-note">
        <InkGlyph name="info-circle" />
        <AlertTitle>The ink is still wet</AlertTitle>
        <AlertDescription>Changes save as you type; give it a second before closing the tab.</AlertDescription>
      </Alert>
      <Alert variant="destructive" seed="alert-error">
        <InkGlyph name="alert-circle" />
        <AlertTitle>The page couldn&apos;t be saved</AlertTitle>
        <AlertDescription>The connection dropped halfway. Nothing was lost; try again.</AlertDescription>
        <AlertAction>
          <Button size="xs" variant="destructive" seed="alert-retry">
            Retry
          </Button>
        </AlertAction>
      </Alert>
    </div>
  );
}
```

## Without an icon

Title only, description only, and with an action.

```tsx
import { Alert, AlertAction, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import { InkGlyph } from "@/lib/ink-glyphs";

export default function AlertSimple() {
  return (
    <div className="flex w-full max-w-xl flex-col gap-6">
      <Alert seed="as-title">
        <AlertTitle>Title only, no icon</AlertTitle>
      </Alert>
      <Alert seed="as-description">
        <AlertDescription>A plain note: a single line of text boxed off from the page.</AlertDescription>
      </Alert>
      <Alert seed="as-action">
        <InkGlyph name="info-circle" />
        <AlertTitle>A new refill is ready</AlertTitle>
        <AlertDescription>Swap it in before your next long session.</AlertDescription>
        <AlertAction>
          <Button size="xs" variant="outline" seed="as-action-btn">
            Order
          </Button>
        </AlertAction>
      </Alert>
    </div>
  );
}
```

## Variants

Pencil, a hatched note, and red pen, each with its glyph.

```tsx
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { InkGlyph } from "@/lib/ink-glyphs";

export default function AlertVariants() {
  return (
    <div className="grid w-full max-w-xl gap-6">
      <Alert seed="av-default">
        <InkGlyph name="info-circle" />
        <AlertTitle>Default</AlertTitle>
        <AlertDescription>Pencilled around the note, for anything worth a second look.</AlertDescription>
      </Alert>
      <Alert variant="note" seed="av-note">
        <InkGlyph name="info-circle" />
        <AlertTitle>Note</AlertTitle>
        <AlertDescription>Hatched lightly across, as if it had been highlighted in the margin.</AlertDescription>
      </Alert>
      <Alert variant="destructive" seed="av-destructive">
        <InkGlyph name="alert-circle" />
        <AlertTitle>Destructive</AlertTitle>
        <AlertDescription>In red pen. The notebook will be deleted for good.</AlertDescription>
      </Alert>
    </div>
  );
}
```

## Dismissible

An action in the corner closes the note, and brings it back.

```tsx
"use client";

import { useState } from "react";
import { Alert, AlertAction, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import { InkGlyph } from "@/lib/ink-glyphs";

export default function AlertDismiss() {
  const [open, setOpen] = useState(true);
  return (
    <div className="flex w-full max-w-xl flex-col items-start gap-4">
      {open ? (
        <Alert variant="note" seed="ad-note">
          <InkGlyph name="info-circle" />
          <AlertTitle>Autosave is on</AlertTitle>
          <AlertDescription>Your page is saved as you write. Turn it off in settings.</AlertDescription>
          <AlertAction>
            <Button variant="ghost" size="icon-sm" seed="ad-close" onClick={() => setOpen(false)}>
              <InkGlyph name="close" />
              <span className="sr-only">Dismiss</span>
            </Button>
          </AlertAction>
        </Alert>
      ) : (
        <p className="text-ink-2">Dismissed.</p>
      )}
      {!open && (
        <Button variant="outline" size="sm" seed="ad-undo" onClick={() => setOpen(true)}>
          Bring it back
        </Button>
      )}
    </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.
- `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.
