# Redact

Words scribbled out with the pen, shown when clicked and scribbled over again on the next.

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

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

```tsx
import { Redact } from "@/components/ui/redact"

<p>The code name is <Redact>Blue Biro</Redact>.</p>
```

Props:

- `label`: `string` (default `"Hidden text"`). What screen readers hear while it's hidden; they don't get the words until it's shown.
- `revealed / defaultRevealed`: `boolean` (default `false`). Shown or scribbled over, controlled or not.
- `onRevealedChange`: `(revealed: boolean) => void`. Called as it's clicked.
- `seed`: `string | number`. Pins the scribble.

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

## Example

```tsx
import { Redact } from "@/components/ui/redact";

export default function RedactDemo() {
  return (
    <p className="max-w-sm text-lg leading-relaxed text-ink-2">
      The launch is on <Redact seed="redact-date">October 14th</Redact>, and the code name is{" "}
      <Redact seed="redact-name">Blue Biro</Redact>. Click to read them.
    </p>
  );
}
```

## Reveal them all

Control revealed and the scribbles come off together; clicking one still reports through onRevealedChange.

```tsx
"use client";

import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Redact } from "@/components/ui/redact";

const lines = [
  ["Codename", "Blue Biro"],
  ["Launch", "October 14th"],
  ["Budget", "$1,200"],
] as const;

export default function RedactControlled() {
  const [revealed, setRevealed] = useState(false);
  return (
    <div className="flex w-full max-w-sm flex-col gap-5">
      <dl className="flex flex-col gap-2 text-lg text-ink-2">
        {lines.map(([term, value]) => (
          <div key={term} className="flex gap-3">
            <dt className="w-24 text-ink-3">{term}</dt>
            <dd>
              <Redact revealed={revealed} onRevealedChange={setRevealed} label={`${term}, hidden`} seed={`rc-${term}`}>
                {value}
              </Redact>
            </dd>
          </div>
        ))}
      </dl>
      <Button variant="outline" size="sm" className="w-fit" onClick={() => setRevealed((r) => !r)} seed="rc-toggle">
        {revealed ? "Cover them up" : "Show everything"}
      </Button>
    </div>
  );
}
```

## In a letter

Names, places and sums scribbled over; click each to read it, and again to cover it.

```tsx
import { Redact } from "@/components/ui/redact";

export default function RedactLetter() {
  return (
    <div className="flex w-full max-w-md flex-col gap-3 text-lg leading-relaxed text-ink-2">
      <p>
        Dear <Redact seed="rl-name">Dr Hopper</Redact>,
      </p>
      <p>
        We write about the project at <Redact seed="rl-place">Harvard</Redact>. The budget stands at <Redact seed="rl-sum">£48,000</Redact> and the first test is
        set for <Redact seed="rl-date">March 3rd</Redact>.
      </p>
      <p>Please tell no one. Click a bar to read it, and again to cover it.</p>
    </div>
  );
}
```

## Secrets in a table

Keys that stay hidden until asked for, each with its own screen-reader label.

```tsx
import { Redact } from "@/components/ui/redact";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";

const keys = [
  ["Production", "sk_live_51Hx9QeK2", "Active"],
  ["Staging", "sk_test_4eC39HqLy", "Active"],
  ["Old laptop", "sk_live_7dYpm0Zt", "Revoked"],
];

export default function RedactTable() {
  return (
    <Table>
      <TableHeader>
        <TableRow>
          <TableHead>Key</TableHead>
          <TableHead>Secret</TableHead>
          <TableHead className="text-right">Status</TableHead>
        </TableRow>
      </TableHeader>
      <TableBody>
        {keys.map(([name, secret, status]) => (
          <TableRow key={name}>
            <TableCell className="font-bold">{name}</TableCell>
            <TableCell className="font-mono text-sm">
              <Redact label={`${name} secret`} seed={`rt-${name}`}>
                {secret}
              </Redact>
            </TableCell>
            <TableCell className="text-right text-ink-2">{status}</TableCell>
          </TableRow>
        ))}
      </TableBody>
    </Table>
  );
}
```

## Pen settings

- `roughness`: `number` (default `1`). 0 is ruler-neat, 1 a quick confident hand, 2 a scrawl.
- `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.
