{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "approval-card",
  "title": "Approval card",
  "description": "Asks before an AI agent acts — an inline card that names the action, shows exactly what will happen, lets people edit it in place, and has a main button that says what it does.",
  "registryDependencies": [
    "button",
    "textarea",
    "https://www.quilldesignsystem.com/r/icon.json",
    "https://www.quilldesignsystem.com/r/ai-mark.json"
  ],
  "files": [
    {
      "path": "registry/lib/approval-card.tsx",
      "content": "'use client'\n\nimport * as React from 'react'\nimport { Button } from '@/components/ui/button'\nimport { Textarea } from '@/components/ui/textarea'\nimport { Icon } from '@/components/ui/icon'\nimport { AiMark } from '@/components/ui/ai-mark'\nimport { cn } from '@/lib/utils'\n\nexport type ApprovalDetail = { label: string; value: React.ReactNode }\n\n// The card ends each label with a colon so every app's rows read the same (\"To:\", \"Subject:\"). A label that already\n// ends in a colon or a question mark, in any script, is left alone (no \"Subject::\", no \"Send a copy?:\"); a full stop\n// is not one of them, because it usually closes an abbreviation (\"Qty.\"). An empty label stays empty, and a label\n// that is not text (a plain-JS app can pass a node) is drawn as given.\nconst withColon = (label: React.ReactNode) => {\n  if (typeof label !== 'string') return label\n  const trimmed = label.trim()\n  return trimmed === '' || /[:：?？؟]$/.test(trimmed) ? trimmed : `${trimmed}:`\n}\n\nexport type ApprovalCardProps = {\n  /** Names the action: \"The agent wants to send this email\". */\n  title: string\n  /** Key and value rows that say exactly what will happen: To, Subject, Amount. Pass the bare word; the card adds the colon. */\n  details?: ApprovalDetail[]\n  /** The content itself. Controlled when passed; leave it out and use defaultBody to let the card keep its own. */\n  body?: string\n  defaultBody?: string\n  onBodyChange?: (body: string) => void\n  /** Names the edit field for screen readers: \"Email body\". */\n  bodyLabel?: string\n  /** false hides Edit. */\n  editable?: boolean\n  /** The main button's words. They name the action (\"Send email\"), never a generic \"Approve\". */\n  actionLabel: string\n  actionIcon?: React.ReactNode\n  /** Receives the body as it stands, edited or not; undefined when the card has no body. */\n  onApprove: (body?: string) => void\n  denyLabel?: string\n  /** Shows the quiet button on the right. */\n  onDeny?: () => void\n  /** One line under the buttons: who it reaches, what it costs, or that it cannot be undone. */\n  consequence?: string\n  /** For actions that delete or cannot be undone: the stock destructive Button. */\n  destructive?: boolean\n  /** Once the person has decided: one line that replaces the buttons (\"Sent to 6 people.\"). */\n  outcome?: string\n  className?: string\n}\n\n/** Asks before an AI agent acts — an inline card that names the action, shows exactly what will happen, lets people edit it in place, and has a main button that says what it does. */\nexport function ApprovalCard({\n  title, details, body, defaultBody, onBodyChange, bodyLabel = 'Content', editable = true,\n  actionLabel, actionIcon, onApprove, denyLabel = 'Deny', onDeny, consequence, destructive = false, outcome, className,\n}: ApprovalCardProps) {\n  const titleId = React.useId()\n  const [ownBody, setOwnBody] = React.useState(defaultBody ?? '')\n  const [editing, setEditing] = React.useState(false)\n  const fieldRef = React.useRef<HTMLTextAreaElement>(null)\n  const cardRef = React.useRef<HTMLDivElement>(null)\n  const statusRef = React.useRef<HTMLDivElement>(null)\n  const hasBody = body !== undefined || defaultBody !== undefined\n  const text = body === undefined ? ownBody : body\n  const decided = Boolean(outcome)\n  const rows = details ?? []\n  const showField = editing && !decided\n  // A body that was given and is now empty would send nothing; the action waits for text.\n  const blank = hasBody && text.trim().length === 0\n  // A controlled body with nowhere to report edits would open a field nothing updates: hide Edit instead.\n  const canEdit = hasBody && editable && (body === undefined || Boolean(onBodyChange))\n  const showTile = rows.length > 0 || text.length > 0 || showField\n  const wasDecided = React.useRef(decided)\n\n  // \"Opens in place\" for a keyboard user means the cursor is in the field.\n  React.useEffect(() => { if (showField) fieldRef.current?.focus() }, [showField])\n\n  // Set when the person presses this card's own main or decline button. An outcome can also arrive on its own (a\n  // timeout, a decision made on another screen), and focus resting on the page body looks the same in both cases.\n  const decidedHere = React.useRef(false)\n\n  // Pressing the main or the decline button removes the button that had focus. Keep the person's place inside the\n  // card, but only after a press in this card, and only if they have not moved on to something else since.\n  // preventScroll: the line is beside the button they just pressed, so the page has no reason to jump.\n  React.useEffect(() => {\n    if (decided && !wasDecided.current && decidedHere.current) {\n      const active = document.activeElement\n      if (!active || active === document.body || cardRef.current?.contains(active)) statusRef.current?.focus({ preventScroll: true })\n    }\n    if (decided) decidedHere.current = false\n    wasDecided.current = decided\n  }, [decided])\n\n  const change = (next: string) => {\n    if (body === undefined) setOwnBody(next)\n    onBodyChange?.(next)\n  }\n\n  return (\n    <div ref={cardRef} data-slot=\"approval-card\" role=\"group\" aria-labelledby={titleId}\n      className={cn('grid grid-cols-[minmax(0,1fr)] gap-2.5 rounded-xl border border-border bg-card px-4 py-3.5 text-sm shadow-sm', className)}>\n      <div className=\"flex items-center gap-2\">\n        <AiMark size=\"icon-md\" />\n        <p id={titleId} className=\"min-w-0 flex-1 font-semibold break-words text-ink-soft\">{title}</p>\n      </div>\n      {showTile ? (\n        // The divider line, not the control line: the tile is read-only content, told apart from the card by its fill.\n        // The control line is kept for things people press or type in.\n        <div data-slot=\"proposal\" className=\"grid grid-cols-[minmax(0,1fr)] gap-1.5 rounded-lg border border-border bg-background px-3 py-2.5\">\n          {rows.length ? (\n            // Each row reads as a line, one space after the colon (\"To: growth@…\"), not as two aligned columns.\n            <dl className=\"grid gap-y-1\">\n              {rows.map((row, index) => (\n                // Labels may repeat (two Cc rows); the list is never reordered, so position is a stable key.\n                <div key={index} className=\"min-w-0 break-words\">\n                  <dt className=\"inline text-muted-foreground\">{withColon(row.label)}</dt>{' '}\n                  <dd className=\"inline text-foreground\">{row.value}</dd>\n                </div>\n              ))}\n            </dl>\n          ) : null}\n          {showField ? (\n            <Textarea ref={fieldRef} aria-label={bodyLabel} value={text} onChange={(event) => change(event.target.value)} className=\"min-h-24 bg-background\" />\n          ) : text ? (\n            <p className=\"whitespace-pre-wrap break-words text-ink-soft\">{text}</p>\n          ) : null}\n        </div>\n      ) : null}\n      {decided ? null : (\n        <div className=\"flex flex-wrap items-center gap-1.5\">\n          <Button type=\"button\" variant={destructive ? 'destructive' : 'default'} disabled={blank} onClick={() => { decidedHere.current = true; onApprove(hasBody ? text : undefined) }}>\n            {actionIcon}\n            {actionLabel}\n          </Button>\n          {canEdit ? (\n            <Button type=\"button\" variant=\"outline\" className=\"aria-pressed:bg-muted\" aria-pressed={editing} onClick={() => setEditing((was) => !was)}>\n              <Icon name=\"edit\" />\n              Edit\n            </Button>\n          ) : null}\n          <span className=\"flex-1\" />\n          {onDeny ? <Button type=\"button\" variant=\"ghost\" onClick={() => { decidedHere.current = true; onDeny() }}>{denyLabel}</Button> : null}\n        </div>\n      )}\n      {consequence && !decided ? (\n        <p className=\"flex items-center gap-1.5 text-xs break-words text-muted-foreground\">\n          <Icon name={destructive ? 'warning' : 'info'} className=\"size-icon-sm\" />\n          {consequence}\n        </p>\n      ) : null}\n      {/* On the page from the start so the outcome arrives into a live region. While empty it is absolutely\n          positioned: a real box that takes no grid row and no gap. With words in it the box is only as wide as\n          they are, with a little room on every side paid back in negative margin, so the focus ring it gets after a\n          decision hugs the words and neither the words nor the card move. */}\n      <div ref={statusRef} role=\"status\" tabIndex={-1} className=\"rounded-md outline-hidden focus-visible:ring-3 focus-visible:ring-ring/50 empty:absolute not-empty:w-fit not-empty:max-w-[calc(100%+0.75rem)] not-empty:-mx-1.5 not-empty:-my-0.5 not-empty:px-1.5 not-empty:py-0.5\">\n        {outcome ? <p className=\"text-xs break-words text-muted-foreground\">{outcome}</p> : null}\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:ui",
      "target": "components/ui/approval-card.tsx"
    }
  ],
  "docs": "Asks before an AI agent acts — an inline card that names the action, shows exactly what will happen, lets people edit it in place, and has a main button that says what it does. Do: Give the main button the action's own words: \"Send email\", \"Delete 3 drafts\". Don't: Label it \"Approve\", \"OK\" or \"Yes\" — people should not have to read the title to know what they are agreeing to. Do: Show the real thing: who it goes to, the subject, the text, and one line on the consequence. Don't: Ask for approval of a summary (\"Send the report?\") while hiding what will actually be sent. Do: Keep the buttons stock: solid ink for the action, destructive for anything that deletes or cannot be undone. Don't: Put the AI gradient on the action button — approving has to feel like any other decision. Do: Leave the proposal tile on the soft divider line (border-border). It is read-only content, told apart from the card by its fill. Don't: Outline it with the control line (border-input) — that line marks things people press or type in. Use alert-dialog when a person started a destructive action themselves and has to confirm it before anything else happens. Use agent-steps when you are showing what the agent is doing, not asking permission for it.",
  "type": "registry:ui"
}