# Approval Card

> An animated approval card for React and shadcn, showing the diff an agent wants approved, with hold to approve.

A permission request where the diff is the thing being approved: the change fills the card and the reason is one muted line. Approve is a hold, so a brand fill sweeps the button and letting go drains it; deny, approve or expiry fold the card to a header that names the outcome.

- Tier: Eased Pro
- Interaction: Press
- Page: https://eased.dev/components/approval-card
- Installs: motion, diff

## Install

Approval Card ships with Eased Pro (https://eased.dev/#pricing). Members add the `@eased-pro` registry with their token (https://eased.dev/account), then run:

```bash
npx shadcn add @eased-pro/approval-card
```

A request for permission where the diff is the thing being approved. The proposed change fills the card (computed with jsdiff); the reason is one muted line. Approve is a hold.

## When to use

- An agent wants to write a file, change a record or send something, and the person should see exactly what changes.
- Human-in-the-loop tools in `awaiting-approval`.

## When not to use

- A yes/no question with nothing to diff: use a confirm dialog or an Ask-User card.

## Usage

```tsx example.tsx
import { ApprovalCard } from "@/components/eased/approval-card/approval-card";

<ApprovalCard
  title="Update the Team plan"
  description="Existing subscribers keep their price until renewal."
  files={[{ path: "src/billing/plans.ts", before, after }]}
  expiresAt={Date.now() + 5 * 60_000}
  onApprove={() => addToolApprovalResponse({ id, approved: true })}
  onDeny={() => addToolApprovalResponse({ id, approved: false })}
/>
```

## API reference

### ApprovalCard

| Prop | Type | Default | Description |
|---|---|---|---|
| `title` | `string` | | What it will do. |
| `description` | `ReactNode` | | Why, in one muted line. |
| `files` | `ApprovalFile[]` | | `{ path, before, after }` or `{ path, hunks: DiffHunk[] }`. |
| `state` | `ApprovalState` | uncontrolled | `awaiting-approval`, `running`, `done`, `denied`, `error`, `expired`. |
| `onApprove` | `() => void \| Promise` | | A promise shows "Applying…" until it settles. |
| `onDeny` | `() => void` | | |
| `expiresAt` / `onExpire` | `number` / `() => void` | | A ring drains toward it. |
| `expiresIn` | `number` | | Milliseconds from mount, in place of `expiresAt`. |
| `holdMs` | `number` | `800` | |
| `context` | `number` | `2` | Context lines around each change. |
| `open` | `boolean` | `true` | Show the body while pending; false leaves the header (a queue's closed rows). |
| `icon` | `ReactNode` | | A 16px glyph in place of the shield while pending. |
| `meta` | `ReactNode` | | Muted text after the title, e.g. "Billing agent · 6 min ago". It truncates before the title, and hides under 30rem. |
| `keys` | `{ approve?, deny? }` | `{ approve: "y", deny: "n" }` | The keys that approve (held) and deny while focus is inside the card. |
| `actions` | `ReactNode` | | More footer actions after Deny, e.g. an Edit button. |
| `tabIndex` / `ref` | `number` / `Ref<HTMLDivElement>` | | Make the card itself focusable, e.g. the open card in a queue. |

`toDiffHunks(before, after, context?)` is exported for your own diff views. The diff scrolls past 8rem; set `--approval-diff-max` on the card (`className="[--approval-diff-max:14rem]"`) to give it more room.

## Keyboard

| Key | Action |
|---|---|
| `Space` / `Enter` (held) on Approve | Approves when the hold completes; release early to cancel. |
| `Y` (held) | Same, while focus is inside the card. `keys` changes it. |
| `N` | Denies, while focus is inside the card. `keys` changes it. |

## Accessibility

- The card is a `group` named by its title; the diff is a `table` with added and removed lines labelled. The outcome is announced from a status region. Approve explains its hold through `aria-describedby`. An empty diff disables Approve and says why inline.

## Motion

The hold fills a brand layer across the button left to right in exact time (linear, 800ms), revealing the label in on-brand ink; letting go drains it on a 0.3s spring with no overshoot. Deciding folds the body on Auto Height while the header's mark swaps (the check draws) and the title gains its outcome through Text Swap. Reduced motion keeps the fill (it is information) and drops the swaps to fades.

## Notes for AI

Always pass the real before/after text so the diff is the body; keep `description` to one sentence. Wire `onApprove` to the AI SDK approval response.

Do not add a separate confirm dialog: the hold is the confirmation.

## Related

- [Tool Call Row](/components/tool-call-row): the row the call becomes once decided.
