# Chat card

A card in the agent's answer for something outside the chat: the browser tab it works in, a file it made, a page or a pull request it changed. Its picture sits beside its name and opens whole; while the agent works the picture holds the light and the change lands in it.

Tier: pro. Type: component. Category: ai. Tags: agent, chat, run, motion.

## Install

```bash
npx shadcn@latest add @pixilui-pro/chat-card
```

One-time setup: add the registry to `components.json`:

```json
{
  "registries": {
    "@pixilui": "https://pixilui.com/r/{name}.json",
    "@pixilui-pro": {
      "url": "https://pixilui.com/r/pro/{name}.json",
      "headers": { "Authorization": "Bearer ${PIXILUI_TOKEN}" }
    }
  }
}
```

Pro items need a license. Create a token on https://pixilui.com/account and set `PIXILUI_TOKEN` in `.env.local`; the CLI sends it as a bearer header.

Files: `components/pixilui/chat-card.tsx`.

## Preview

Live preview: https://pixilui.com/components/chat-card

Knobs:

- `kind`: `pull request`, `file`, `Notion page`, `sheet`, `browser tab`, `plain`
- `ending`: `done`, `stopped`, `failed`, `gone`

Signature: The pull request's diff lands block by block under the held light, the checks run, and the card rings out as its meta reads checks passed.

Styles: `lively` (default), `quiet`, set with `data-style` on <html>. The item reads the style through the foundation; it needs no prop.

## Code

Pro source is available to license holders.

## Usage

When to use:

- Something the agent made or changed in another app: a file, a Notion page, a pull request, a sheet, with its picture.
- The browser tab the agent works in, with its cursor, and a hand-off when the site needs the person (Take over, Hand back).
- A thing that didn't end done: stopped, failed or gone, said in its meta.

When not to use:

- A link inside running text: keep it a link.
- A source behind a claim: use the reasoning trail's citation chip.
- A generic link preview with no picture of the thing.

```tsx
import { useRef, useState } from "react";
import { Button } from "@/components/pixilui/button";
import { ChatCard, type ChatCardHandle } from "@/components/pixilui/chat-card";
import { ChatCardPicturesStyle, chatCardMarks, examplePictures } from "@/components/pixilui/chat-card.examples";

// The first option of each knob is the demo's default; the docs preview starts there.
export const knobs = {
  kind: ["pull request", "file", "Notion page", "sheet", "browser tab", "plain"],
  ending: ["done", "stopped", "failed", "gone"],
} as const;

const KIND = { "pull request": "pr", file: "file", "Notion page": "notion", sheet: "sheet", "browser tab": "browser", plain: "plain" } as const;
const ANSWER = { fontSize: "var(--pixilui-text-answer)", lineHeight: "var(--pixilui-text-answer-leading)", letterSpacing: "var(--pixilui-text-answer-tracking)" };

/** A card in the agent's answer: the thing's picture builds under the held light as the work lands, then it rings out, or ends stopped, failed or gone. */
export default function ChatCardDemo({ kind = "pull request", ending = "done" }: KnobValues<typeof knobs>) {
  const ref = useRef<ChatCardHandle>(null);
  const [run, setRun] = useState(0);
  const k = KIND[kind];
  const play = async () => {
    const c = ref.current?.card;
    if (!c || !c.work) return;
    void c.light(true);
    const halt = ending === "stopped" ? setTimeout(() => c.halt?.(), 900) : undefined;
    const r = await c.work({ fail: ending === "failed" });
    clearTimeout(halt);
    if (r === "failed") {
      void c.light(false);
      void c.ring({ fam: "fail" });
      c.end("failed", c.failWord ?? "failed");
    } else if (r === "stopped") c.end("stopped", "stopped");
    else {
      void c.light(false);
      void c.ring();
      if (ending === "gone") c.end("gone", "deleted");
    }
  };
  return (
    <div className="grid w-full max-w-xl gap-3 rounded-panel bg-surface p-5 elevation-raised">
      <ChatCardPicturesStyle />
      <p className="m-0 text-foreground" style={ANSWER}>
        {k === "browser" ? "Refunding the second charge in your Stripe, in the tab beside this chat." : k === "plain" ? "The refund policy is in your docs." : "Raised the refund limit to $500 where the team will see it."}
      </p>
      <ChatCard
        key={`${kind}${ending}${run}`}
        ref={ref}
        kind={k}
        blank={k !== "browser" && k !== "plain"}
        title={k === "plain" ? "refund-policy.md" : k === "browser" ? "Payments – Northbeam" : undefined}
        meta={k === "plain" ? "Markdown · 4 KB" : k === "browser" ? "dashboard.stripe.com" : undefined}
        tile={k === "plain" ? "file" : undefined}
        mark={k === "browser" ? "stripe" : undefined}
        badge={k === "browser" ? "chrome" : undefined}
        page={k === "browser" ? examplePictures().tab!.page() : undefined}
        paint={k === "browser" ? examplePictures().tab!.paint : undefined}
        pictures={examplePictures()}
        marks={chatCardMarks}
        onReady={(c) => {
          if (k === "browser") c.freeze({ scene: "list", filtered: true, query: "Lena Ortiz", at: "row-b", light: true, meta: "dashboard.stripe.com" });
          else if (k !== "plain") setTimeout(() => void play(), 400);
        }}
      />
      {k !== "browser" && k !== "plain" ? (
        <div>
          <Button variant="secondary-2" size="sm" onClick={() => setRun((r) => r + 1)}>
            Replay
          </Button>
        </div>
      ) : null}
    </div>
  );
}
```

## Examples

None.

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `kind` | `string` | `"plain"` | plain (a link), browser (the tab the agent works in), or a thing in pictures.kinds (file, notion, pr, sheet in the examples). |
| `title` | `string` |  | Its name. |
| `meta` | `string` |  | Where it lives. |
| `href` | `string` |  | Where it opens. |
| `tile` | `string` |  | A plain card's tile: an icon id (file, browse). |
| `mark` | `string` |  | A product's favicon in the tile, by its mark id (stripe), in place of an icon. |
| `badge` | `string` |  | The app it is open in, on the tile (a mark id: chrome). |
| `action` | `ChatCardAction` |  | A plain card's button in place of the arrow. |
| `size` | `"small" \| "big"` |  | A live card's size. |
| `blank` | `boolean` |  | A thing card starts unmade (the work lands in it). |
| `page` | `string` |  | A browser card's picture: its markup (the Stripe tab in the examples). |
| `paint` | `ChatCardLiveOptions["paint"]` |  | Sets a frozen browser picture's own state (the examples' tab.paint). |
| `you` | `string` |  | Your name, for your coin by your cursor. |
| `open` | `ChatCardLiveOptions["open"]` |  | The Open (or Download) button. |
| `pictures` | `ChatCardPictures` |  | The pictures (the examples' chatCardPictures). |
| `marks` | `Record<string, () => string>` |  | Product marks by id (Chrome, Stripe, Notion, GitHub, Google Drive), as markup; each call is a fresh copy. |
| `onReady` | `(card: ChatCardLiveCard & Partial<ChatCardThingCard>) => void` |  | Builds the card's first moment (a frozen state: card.freeze, card.end). |

Also accepts every native `<div>` attribute except `title`, and a ref to it.

## Keyboard

- `Tab`: Reaches the card's row, then Open or Download, then Take over or Hand back when the tab asks.
- `Enter` + `Space`: Expands or collapses a live card from its row; opens a plain card's link.

## Accessibility

- A plain card's row is a link; a live card's is a button with aria-expanded, labelled by its name and where it lives.
- The picture is role img with a label; the picture, the light and the cursors are aria-hidden.
- Open and Download are named links with the locked tooltip; on touch every button reaches 44.
- Reduced motion: the glide, the typing, the cursors and the swaps happen at once; a run settles to the same end.

## Motion

- Small to big and back: the view grows out of the picture (FLIP, 280ms on the out curve) and the card's height follows.
- The agent's hands on the tab: the Aurora light blooms from the picture and holds; done rings it out (the browser tab adds the pop).
- Cursors glide, shorter trips quicker (520ms at most); a click dips the arrow and opens a ring; you type slower and unevenly than the agent.
- Gone: the picture drains to grey at half strength and Open fades out. The name and meta change with the quiet swap.

## Responsive

- A lone card is 360 wide at most, a live card 480; under 420 a small card is its row alone, and at 360 long names truncate before the state words.

## Performance

- The held light is one canvas per working card on aurora-light's shared clock, rebuilt once a resize settles; nothing runs on a card at rest.

## Notes for AI

- <ChatCard kind="pr" blank pictures={pictures} onReady={(card) => card.work().then(() => card.ring())} />: the ref's card has the lock's run methods (work, halt, ring, end, freeze, size, light, the cursors).
- kind is plain (a link), browser (the tab: page and paint are its picture) or a thing in pictures.kinds; the examples' chatCardPictures are the Stripe tab, a file, Notion, GitHub and Sheets.
- card.end("stopped" | "failed" | "gone", word) says why it didn't end done, in the meta; the state words never truncate.
- The pictures are demo content (examples), never the card: bring your own picture markup and its work for your app.
- Per-style rule: quiet is compact (pad 10, gap 10, view inset 4) and the light wears one hue per meaning.

## Related

- [Aurora light](https://pixilui.com/components/aurora-light/markdown): Soft light for an element's moment, in our glass colors: the glim crosses a card when work arrives, the rim blooms out of what you pressed and holds while the agent works, the ring pops for a moment that matters.
- [Reasoning trail](https://pixilui.com/components/reasoning-trail/markdown): The agent's thinking chain in a chat: steps on one hairline with their thoughts and sources, streamed with a soft edge, folding into one line when the answer starts, any retry or failure kept.
- [Tool call](https://pixilui.com/components/tool-call/markdown): One tool call in the agent's answer: its row names the call (the tool's real logo, the function as a code tag, the time) and folds its Arguments and Result. A secret in the arguments renders masked, and Copy copies the mask.
