# Approval card

> The agent asks before it acts: what it wants to do, the details, Approve or Deny.

Human-in-the-loop, designed. The card says plainly what the agent wants to do, lists the details worth checking, and asks. Once answered it doesn’t get swapped for a receipt: the same card folds into one line. The body closes, the action slides up beside the header, "Needs your approval" morphs into "Approved" and a check draws itself where the shield was. Destructive actions get a red Approve, and requests can count down, the seconds rolling back like a clock, and expire the same way.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/approval-card.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `number-roll`, `text-morph`
- Docs and live preview: https://hairlineui.com/ui/approval-card
- Registry item (source): https://hairlineui.com/r/approval-card.json

## Usage

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

<ApprovalCard
  title="Send email to 3 people"
  description="The agent drafted a follow-up and wants to send it from your address."
  details={[
    { label: "To", value: "maya@acme.com, +2 more" },
    { label: "Subject", value: "Thursday tasting menu" },
  ]}
  onApprove={send}
  onDeny={skip}
/>
```

## With the AI SDK

```tsx
// Server: ask for approval before a tool runs
streamText({ model, messages, tools, toolApproval: { sendEmail: "user-approval" } });

// Client
import { useChat } from "@ai-sdk/react";
import { ApprovalCard } from "@/components/approval-card";

const { messages, addToolApprovalResponse } = useChat();

// for each part where part.type === "tool-sendEmail":
if (part.state === "approval-requested") {
  return (
    <ApprovalCard
      title={`Send email to ${part.input.to.length} people`}
      reason={part.approval.requestReason}
      details={[{ label: "Subject", value: part.input.subject }]}
      onApprove={() => addToolApprovalResponse({ id: part.approval.id, approved: true })}
      onDeny={() => addToolApprovalResponse({ id: part.approval.id, approved: false })}
    />
  );
}
if (part.state === "approval-responded") {
  return <ApprovalCard title="Send email" status={part.approval.approved ? "approved" : "denied"} />;
}
if (part.state === "output-denied") {
  return <ApprovalCard title="Send email" status="denied" />;
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `title / description` | `string` | – | What the agent wants to do, in plain words. |
| `details` | `{ label; value }[]` | – | The specifics worth checking: recipients, amounts, files. |
| `reason` | `string` | – | Why approval is needed, e.g. the AI SDK’s requestReason. |
| `status / defaultStatus` | `"pending" \| "approved" \| "denied" \| "expired"` | `"pending"` | Controlled, or let the card remember the choice. |
| `onApprove / onDeny` | `() => void` | – | Send the decision back to your agent. |
| `approveLabel / denyLabel` | `string` | `"Approve" / "Deny"` | Name the actual action, e.g. "Send" and "Don’t send". |
| `destructive` | `boolean` | `false` | Red Approve for deletes, payments and other irreversible actions. |
| `expiresAt / onExpire` | `number / () => void` | – | Countdown to when the request lapses. |

## States

- **pending**: The request with its details and Deny / Approve. With expiresAt, a countdown whose digits roll down each second (00 rolls back to 59, like a clock).
- **approved**: One motion over 480ms: the body folds shut and blurs out, the padding tightens, the action slides into the header line, the label morphs to "Approved" and an emerald check draws itself in place of the shield.
- **denied**: Folds the same way into "Denied" with a ban icon; the agent carries on without it.
- **expired**: The countdown reaches 0:00, folds away with the body, and the label morphs to "Expired".

## What it handles

When an agent is about to do something that can’t be taken back, a confirm dialog interrupts the page and then vanishes. This card asks inside the conversation, keeps the answer there as a one-line record, and can time out.

- **It says what will happen**: A title, a description and a list of the specifics worth checking, such as recipients, amounts or files.
- **Approve or Deny**: Name the real action (“Send” and “Don’t send”) and get onApprove or onDeny back.
- **Red for irreversible**: Set destructive for deletes and payments and Approve turns red.
- **It becomes the receipt**: The same card folds into one line, “Approved” with a drawn check, rather than being swapped for something new.
- **Requests can expire**: A countdown rolls down like a clock and the card folds into “Expired” when it reaches zero.
- **Hard to approve by accident**: Approve is never focused automatically, so a stray Enter can’t approve an action.

## Replaces

a confirm dialog, a countdown timer, approved and denied state, a destructive button style, a decision receipt

## Where it fits

- **AI agent chats**: Ask before the agent sends an email, deletes files or spends money.
- **Payments and billing**: Ask before a refund, a plan change or a large payment goes out.
- **Workflow tools**: A step that waits for a person’s go-ahead before the run continues.
- **Admin tools**: A sign-off before something that can’t be undone, such as deleting a project.

## Notes

- The card is a labelled group in every state; the outcome is announced from a status region inside it, so screen readers hear "Approved: Send email to 3 people".
- When you answer, focus moves to the card itself rather than dropping to the page as the buttons fold away. The folded body is inert.
- The countdown is not a live region, so it never chatters; its digits are hidden from assistive tech and the time is real text.
- Installs Number roll and Text morph. With reduced motion, the card changes state in place.
- Approve is never focused automatically, so a stray Enter can’t approve an action.
- Details wrap rather than truncate, because they are what the user is approving.

License: MIT (https://hairlineui.com/license#components)
