# Change Preview

> Before and after of a change, exactly as it will run: DNS records, zone and cloud settings, mailboxes, a server's state, any API call.

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

Before and after of a change, exactly as it will run: DNS records, zone and cloud settings, mailboxes, a server's state, any API call. Goes inside an `ApprovalCard`.

- `fields`: `{label, before, after, mono}`; changed rows are marked (signal edge, the new value highlighted, the old one struck through), unchanged rows stay muted. `null` or an empty value shows "Empty" (created or deleted). Multi-line values keep their lines.
- `facts`: provider, account, region, target above the table. `onlyChanged` hides unchanged rows.
- `diff`: `{before, after, context}` adds a line diff below (`-`, `+`, ` `), folding long unchanged runs into "… 12 unchanged lines". `LineDiff` and `diffLines()` work on their own too.
- `warnings`: your own words, shown as warnings.
- Narrow (under 480px) each row stacks: field, then before and after with their labels.

## Example

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

const BEFORE = `server {
  listen 443 ssl;
  server_name shop.northwind.example;
  root /srv/shop/current;
  client_max_body_size 8m;
  gzip on;
  location / {
    try_files $uri /index.html;
  }
  location /api/ {
    proxy_pass http://127.0.0.1:4000;
    proxy_read_timeout 30s;
  }
}`;
const AFTER = BEFORE.replace("client_max_body_size 8m;", "client_max_body_size 32m;").replace(
  "proxy_read_timeout 30s;",
  "proxy_read_timeout 120s;",
);

export default function Preview() {
  return (
    <div className="tf-col" style={{ gap: 16 }}>
      <ApprovalCard
        agent="Scout"
        project="Domains"
        family="infra"
        age="3 min"
        title="Update the TXT record ops-test on northwind.example"
        text="The verification value changed after the provider renewed the token."
      >
        <ChangePreview
          title="Update TXT record · northwind.example"
          facts={[
            { k: "Provider", v: "DNS host" },
            { k: "Zone", v: "northwind.example", mono: true },
          ]}
          fields={[
            { label: "Type", before: "TXT", after: "TXT", mono: true },
            { label: "Name", before: "ops-test", after: "ops-test", mono: true },
            {
              label: "Content",
              before: "verify=4f1c0e92",
              after: "verify=b7d2a6f1",
              mono: true,
            },
            { label: "TTL", before: "3600", after: "300", mono: true },
            { label: "Comment", before: null, after: "Renewed token\nby the provider" },
          ]}
          warnings={["Changing a TXT record on the apex can affect mail verification."]}
        />
      </ApprovalCard>
      <div className="tf-panel">
        <ChangePreview
          title="Edit nginx.conf on web-1"
          fields={[
            {
              label: "File",
              before: "/etc/nginx/sites/shop.conf",
              after: "/etc/nginx/sites/shop.conf",
              mono: true,
            },
          ]}
          onlyChanged
          diff={{ before: BEFORE, after: AFTER, context: 2 }}
        />
      </div>
    </div>
  );
}
```

## Props

### ChangePreview

| Prop | Type | Notes |
| --- | --- | --- |
| `title?` | `ReactNode` | What changes, in one line ("Update TXT record ops-test · example.com"). |
| `facts?` | `KeyValueItem[]` | Context above the table: provider, account, region, target. |
| `fields` | `ChangeField[]` | Required |
| `fieldHeading?` | `string` | Heading of the first column (default "Field"). |
| `onlyChanged?` | `boolean` | Only the changed rows. |
| `diff?` | `{ before: string; after: string; context?: number }` | A line diff below the table (config files, long texts), folded around the changes. |
| `warnings?` | `ReactNode[]` | Worded by you; shown as warnings under the change. |
| `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. |

### LineDiff

| Prop | Type | Notes |
| --- | --- | --- |
| `before?` | `string` | Compare two texts … |
| `after?` | `string` |  |
| `lines?` | `DiffLine[]` | … or pass the lines yourself. |
| `context?` | `number` | Unchanged lines kept around each change; longer runs fold into "…" (default 3; `Infinity` keeps all). |
| `label?` | `string` | Accessible name (default "Line changes"). |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |
