# Document Preview

> A change to a document: text documents as a line diff of before and after (unchanged runs folded, context lines kept), spreadsheets as the cells before → after (cells, with the range).

Component · AI · Pro kit · [Live page](https://ui.twentyfirst.media/pro/components/DocumentPreview/)

A change to a document: text documents as a line diff of `before` and `after` (unchanged runs folded, `context` lines kept), spreadsheets as the cells before → after (`cells`, with the `range`). `href` opens the document (`linkAs` for a router).

## Example

```tsx
import { ApprovalCard, DocumentPreview } from "@twentyfirstmedia/pro";

export default function Preview() {
  return (
    <div className="tf-col" style={{ gap: 16 }}>
      <ApprovalCard
        agent="Writer"
        project="Operations"
        family="apps"
        age="2 min"
        title="Edit the onboarding guide"
      >
        <DocumentPreview
          title="Onboarding guide"
          href="#"
          before={
            "# Onboarding\n\nWelcome to the team.\n\n## First week\n- Laptop and accounts\n- Meet your buddy\n- Read the handbook\n\n## Tools\n- Mail\n- Calendar\n- Chat\n\n## Contacts\nPeople team: people@example.com"
          }
          after={
            "# Onboarding\n\nWelcome to the team.\n\n## First week\n- Laptop and accounts\n- Meet your buddy on day one\n- Read the handbook\n- Set up two-factor sign-in\n\n## Tools\n- Mail\n- Calendar\n- Chat\n\n## Contacts\nPeople team: people@example.com"
          }
          context={1}
        />
      </ApprovalCard>
      <ApprovalCard
        agent="Ledger"
        project="Finance"
        family="money"
        age="9 min"
        title="Update the Q2 budget sheet"
        compact
      >
        <DocumentPreview
          title="Budget 2026"
          range="Q2!B4:D6"
          cells={[
            { cell: "B4", before: "12,000", after: "14,500" },
            { cell: "C4", before: "Travel", after: "Travel" },
            { cell: "D6", before: null, after: "=SUM(B4:B5)" },
          ]}
        />
      </ApprovalCard>
    </div>
  );
}
```

## Props

### DocumentPreview

| Prop | Type | Notes |
| --- | --- | --- |
| `title` | `ReactNode` | The document's name. |
| `before?` | `string` | Text documents: a line diff of `before` and `after`. |
| `after?` | `string` |  |
| `cells?` | `{ cell: string; before?: string \| null; after?: string \| null }[]` | Spreadsheets: the cells that change. |
| `range?` | `string` | The sheet range ("Budget!B4:D9"). |
| `href?` | `string` | Opens the document (new tab, or `linkAs`). |
| `linkAs?` | `ElementType` |  |
| `context?` | `number` |  |
| `warnings?` | `ReactNode[]` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### ApprovalCard

| Prop | Type | Notes |
| --- | --- | --- |
| `title` | `ReactNode` | Required |
| `text?` | `ReactNode` |  |
| `children?` | `ReactNode` |  |
| `agent?` | `string` |  |
| `project?` | `string` |  |
| `family?` | `RiskFamily` |  |
| `familyLabel?` | `string` |  |
| `age?` | `string` |  |
| `escalation?` | `ReactNode` |  |
| `trace?` | `ReactNode` |  |
| `note?` | `ReactNode` |  |
| `heading?` | `string` |  |
| `options?` | `ApprovalOption[]` |  |
| `approveLabel?` | `string` |  |
| `onDecide?` | `(key: ApprovalKey, text?: string) => void \| Promise<unknown>` | Called with the answer (and the text of B or D). Return a Promise to keep the card busy until it settles: the answer's button spins and every answer is disabled; a rejection shows an error (a rejected string is shown as is) and keeps the card open. Once it resolves, a card without a `decision` prop collapses to its one-line record; with a plain callback, set `decision` yourself. |
| `decision?` | `ApprovalDecision \| null` | The decision record: shown as one line instead of the card; `null` keeps the card open. |
| `compact?` | `boolean` | Side panels: tighter, the answers in a row, the payload folded behind "Show what runs" (one click, never a summary). |
| `stepUp?` | `boolean` | Money, legal and infrastructure decisions: A and B (the answers that run something) need a fresh passkey. They show "Needs your passkey"; while `onDecide` is pending the pressed answer says "Confirm with passkey". Do the WebAuthn step-up in `onDecide` and reject if it fails. |
| `busy?` | `ApprovalKey \| null` | The answer being sent, when you track it yourself (controlled busy state). |
| `error?` | `ReactNode` | An error to show above the answers (controlled); a rejected `onDecide` shows one by itself. |
| `screen?` | `boolean` | Fills its container, e.g. a deep link on a phone: the content scrolls and A–D stay at the bottom, full width, in thumb reach (with the safe area). |
| `href?` | `string` | Makes the title a link to the full approval (with `linkAs` for a router's link). |
| `linkAs?` | `ElementType` |  |
| `onApprove?` | `() => void` |  |
| `onDeny?` | `() => void` |  |
| `onEdit?` | `(text: string) => void` |  |
| `state?` | `"approved" \| "denied"` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |
