# Context Cards

The passages an agent retrieved to answer a question, each with its source.

The passages an agent retrieved to answer a question, each with the document it came from. A header with a count badge over cards that each carry a title bar, the chunk body and a source chip. With appear the cards rise once, staggered, at mount; a card added later rises alone.

Kind: block · Category: Agent · Status: stable · Targets: React, Vue, Svelte

## Add

```bash
npx fndn add context-cards
```

It writes the folder `context-cards/` into the project's ui folder (`index.ts`, `context-cards.tsx`, `ContextCards.vue`, `ContextCards.svelte`, `context-cards.recipe.ts`), and what it is built from: [Count](/components/count.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { ContextCards } from "@/components/ui/context-cards";
```

```vue
import { ContextCards } from "@/components/ui/context-cards";
```

```svelte
import { ContextCards } from "$lib/components/ui/context-cards";
```

## Parts

In the DOM the root carries `data-slot="context-cards"` and each part `data-slot="context-cards-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `div` | `context-cards` |  |  |
| `header` | `div` | `context-cards-header` |  | The title, then the chunk count as our Count (boxed, tabular) |
| `title` | `span` | `context-cards-title` |  |  |
| `card` | `div` | `context-cards-card` | repeats | --fndn-row-index (set only on cards present at mount) staggers the entrance |
| `bar` | `div` | `context-cards-bar` |  |  |
| `card-title` | `span` | `context-cards-card-title` |  | lines icon + title; the title truncates at the end and carries it as title |
| `chars` | `span` | `context-cards-chars` |  |  |
| `body` | `p` | `context-cards-body` |  |  |
| `footer` | `div` | `context-cards-footer` |  |  |
| `source` | `a` | `context-cards-source` |  | source chip: badge + name + arrow; pops in after its card; presses |
| `badge` | `span` | `context-cards-badge` |  | 14px file-type square, tinted by data-tone; aria-hidden (the file name says it). Local: a three-letter type does not fit our avatar (two letters) |
| `source-name` | `span` | `context-cards-source-name` |  | file name; truncates at the end and carries it as title |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `title` | `string` | `"All chunks"` |  |
| `count` | `string` |  | Shown as given (tabular numbers). |
| `chunks` | `{ title: string; chars: string; body: string; source: string; href?: string; badge: string; tone: neutral\|red\|green\|orange\|accent }[]` |  | Cards present at the first render rise staggered with appear; later ones enter without delay. |
| `tone` | `"neutral" \| "red" \| "green" \| "orange" \| "accent"` | `"neutral"` | Per-chunk badge tint. |
| `appear` | `boolean` | `false` | Whether the header and the cards present at mount enter (the header fades in, the cards rise staggered). Off by default: set it on the set your code adds live, never on one rendered from history or with the page (a mount is not an arrival). Cards added after mount enter either way. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## States

`source-hover`, `source-press`, `focus-visible`

## Keyboard and accessibility

Notes:

- Source chips are links (Tab, Enter); with no href they point at '#'.
- Truncated titles and file names carry the full text as title.
- The badge is aria-hidden: the file name already says the type.

## Motion

- header: fndn-fade-in over duration.enter, together with the first card; only with appear (a plain mount shows everything at once)
- cards: with appear, fndn-fade-up over duration.enter, staggered by duration.stagger, capped at motion.stagger-max; only cards present at mount get --fndn-row-index; a card added after mount always enters, with no delay
- source chip: no entrance of its own; it arrives with its card
- source chip: hover background over duration.fast (gated); press darkens to color.hover-2 and scales to motion.press-scale

## Tokens

`color.accent`, `color.green`, `color.hover`, `color.ink`, `color.ink-2`, `color.ink-3`, `color.inset`, `color.line`, `color.on-accent`, `color.orange`, `color.red`, `color.surface`, `duration.base`, `duration.enter`, `duration.fast`, `duration.press`, `duration.stagger`, `easing.out-strong`, `motion.press-scale`, `motion.stagger-max`, `radius.card`, `radius.pill`, `shadow.btn`, `shadow.card`, `text.sm`, `text.xs`, `color.hover-2`

## Dependencies

- [Count](/components/count.md)

## Examples

### Sources behind a refund answer

React · `default.tsx`

```tsx
import { ContextCards, type ContextChunk } from "@/components/ui/context-cards";

const chunks: ContextChunk[] = [
  {
    title: "Refund window",
    chars: "412 characters",
    body: "Annual plans: full refund within 30 days of renewal.",
    source: "Billing Policy 2026.pdf",
    badge: "PDF",
    tone: "red",
  },
  {
    title: "Who approves refunds",
    chars: "236 characters",
    body: "Refunds over $500 need sign-off from Finance.",
    source: "Support Playbook.docx",
    badge: "DOC",
    tone: "accent",
  },
];

export default function Default() {
  return <ContextCards title="Sources" count="2" chunks={chunks} />;
}
```

Vue · `default.vue`

```vue
<script setup lang="ts">
import { ContextCards, type ContextChunk } from "@/components/ui/context-cards";

const chunks: ContextChunk[] = [
  {
    title: "Refund window",
    chars: "412 characters",
    body: "Annual plans: full refund within 30 days of renewal.",
    source: "Billing Policy 2026.pdf",
    badge: "PDF",
    tone: "red",
  },
  {
    title: "Who approves refunds",
    chars: "236 characters",
    body: "Refunds over $500 need sign-off from Finance.",
    source: "Support Playbook.docx",
    badge: "DOC",
    tone: "accent",
  },
];
</script>

<template>
  <ContextCards title="Sources" count="2" :chunks="chunks" />
</template>
```

Svelte · `default.svelte`

```svelte
<script lang="ts">
  import { ContextCards, type ContextChunk } from "$lib/components/ui/context-cards";

  const chunks: ContextChunk[] = [
    {
      title: "Refund window",
      chars: "412 characters",
      body: "Annual plans: full refund within 30 days of renewal.",
      source: "Billing Policy 2026.pdf",
      badge: "PDF",
      tone: "red",
    },
    {
      title: "Who approves refunds",
      chars: "236 characters",
      body: "Refunds over $500 need sign-off from Finance.",
      source: "Support Playbook.docx",
      badge: "DOC",
      tone: "accent",
    },
  ];
</script>

<ContextCards title="Sources" count="2" {chunks} />
```

### Sources arriving during an incident question

React · `streaming.tsx`

```tsx
import { useEffect, useState } from "react";
import { ContextCards, type ContextChunk } from "@/components/ui/context-cards";

const sources: ContextChunk[] = [
  {
    title: "Timeline, 14:05 to 14:31",
    chars: "880 characters",
    body: "Bookings failed with 503s for 26 minutes after the Postgres primary ran out of connections; the pool was raised from 80 to 160.",
    source: "INC-482 Postmortem.md",
    badge: "MD",
    tone: "neutral",
  },
  {
    title: "Connection pool runbook",
    chars: "1,140 characters",
    body: "If active connections stay above 90% for five minutes, restart the PgBouncer pods one at a time and page the on-call engineer.",
    source: "Runbooks / Database.md",
    badge: "MD",
    tone: "neutral",
  },
  {
    title: "Error rate by endpoint",
    chars: "2,310 characters",
    body: "POST /bookings: 18.4% errors at 14:12, 0.2% at 14:35. GET /availability stayed under 0.5% throughout.",
    source: "api-errors-2026-11-12.csv",
    badge: "CSV",
    tone: "green",
  },
];

export default function Streaming() {
  /* retrieval returns one source at a time while the answer streams */
  const [shown, setShown] = useState(1);
  useEffect(() => {
    if (shown >= sources.length) return;
    const timer = window.setTimeout(() => setShown(shown + 1), 1000);
    return () => clearTimeout(timer);
  }, [shown]);
  return <ContextCards title="Sources" count={String(shown)} chunks={sources.slice(0, shown)} />;
}
```

Vue · `streaming.vue`

```vue
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from "vue";
import { ContextCards, type ContextChunk } from "@/components/ui/context-cards";

const sources: ContextChunk[] = [
  {
    title: "Timeline, 14:05 to 14:31",
    chars: "880 characters",
    body: "Bookings failed with 503s for 26 minutes after the Postgres primary ran out of connections; the pool was raised from 80 to 160.",
    source: "INC-482 Postmortem.md",
    badge: "MD",
    tone: "neutral",
  },
  {
    title: "Connection pool runbook",
    chars: "1,140 characters",
    body: "If active connections stay above 90% for five minutes, restart the PgBouncer pods one at a time and page the on-call engineer.",
    source: "Runbooks / Database.md",
    badge: "MD",
    tone: "neutral",
  },
  {
    title: "Error rate by endpoint",
    chars: "2,310 characters",
    body: "POST /bookings: 18.4% errors at 14:12, 0.2% at 14:35. GET /availability stayed under 0.5% throughout.",
    source: "api-errors-2026-11-12.csv",
    badge: "CSV",
    tone: "green",
  },
];

/* retrieval returns one source at a time while the answer streams */
const shown = ref(1);
let timer = 0;
const tick = () => {
  if (shown.value < sources.length) timer = window.setTimeout(() => { shown.value++; tick(); }, 1000);
};
onMounted(tick);
onBeforeUnmount(() => clearTimeout(timer));
</script>

<template>
  <ContextCards title="Sources" :count="String(shown)" :chunks="sources.slice(0, shown)" />
</template>
```

Svelte · `streaming.svelte`

```svelte
<script lang="ts">
  import { onMount } from "svelte";
  import { ContextCards, type ContextChunk } from "$lib/components/ui/context-cards";

  const sources: ContextChunk[] = [
    {
      title: "Timeline, 14:05 to 14:31",
      chars: "880 characters",
      body: "Bookings failed with 503s for 26 minutes after the Postgres primary ran out of connections; the pool was raised from 80 to 160.",
      source: "INC-482 Postmortem.md",
      badge: "MD",
      tone: "neutral",
    },
    {
      title: "Connection pool runbook",
      chars: "1,140 characters",
      body: "If active connections stay above 90% for five minutes, restart the PgBouncer pods one at a time and page the on-call engineer.",
      source: "Runbooks / Database.md",
      badge: "MD",
      tone: "neutral",
    },
    {
      title: "Error rate by endpoint",
      chars: "2,310 characters",
      body: "POST /bookings: 18.4% errors at 14:12, 0.2% at 14:35. GET /availability stayed under 0.5% throughout.",
      source: "api-errors-2026-11-12.csv",
      badge: "CSV",
      tone: "green",
    },
  ];

  /* retrieval returns one source at a time while the answer streams */
  let shown = $state(1);
  onMount(() => {
    let timer = 0;
    const tick = () => {
      if (shown < sources.length) timer = window.setTimeout(() => { shown++; tick(); }, 1000);
    };
    tick();
    return () => clearTimeout(timer);
  });
</script>

<ContextCards title="Sources" count={String(shown)} chunks={sources.slice(0, shown)} />
```

### Every chunk found before a renewal call

React · `search-results.tsx`

```tsx
import { ContextCards, type ContextChunk } from "@/components/ui/context-cards";

const chunks: ContextChunk[] = [
  {
    title: "Renewal terms",
    chars: "640 characters",
    body: "The agreement renews on January 4 for 12 months at $2,400 per month unless either party gives 60 days' written notice.",
    source: "Kestrel Logistics – Master Services Agreement (signed 2025-01-04).pdf",
    href: "https://example.com/docs/kestrel-msa.pdf",
    badge: "PDF",
    tone: "red",
  },
  {
    title: "Seat usage, last 90 days",
    chars: "1,250 characters",
    body: "Active seats fell from 180 to 128; the Denver and Reno depots stopped booking dock slots in September.",
    source: "kestrel-usage-q3.csv",
    href: "https://example.com/exports/kestrel-usage-q3.csv",
    badge: "CSV",
    tone: "green",
  },
  {
    title: "Volume discount table",
    chars: "530 characters",
    body: "Accounts with 100 to 249 seats get 12% off list; 250 seats and above get 18% and a named support contact.",
    source: "Pricing 2026.xlsx",
    href: "https://example.com/sheets/pricing-2026.xlsx",
    badge: "XLSX",
    tone: "green",
  },
  {
    title: "Last check-in call",
    chars: "910 characters",
    body: "Their operations lead asked for SMS reminders to drivers and a cheaper plan for seasonal depots.",
    source: "Call notes – Sofia Alvarez.docx",
    href: "https://example.com/docs/kestrel-call-notes.docx",
    badge: "DOC",
    tone: "accent",
  },
  {
    title: "Open support tickets",
    chars: "380 characters",
    body: "Two open tickets: calendar sync delays for the Reno depot (high) and an invoice address change (low).",
    source: "Support export.csv",
    href: "https://example.com/exports/support.csv",
    badge: "CSV",
    tone: "green",
  },
  {
    title: "Roadmap commitment",
    chars: "270 characters",
    body: "SMS reminders ship in Q1; Kestrel is on the beta list.",
    source: "Roadmap.md",
    href: "https://example.com/docs/roadmap.md",
    badge: "MD",
    tone: "neutral",
  },
];

export default function SearchResults() {
  return <ContextCards title="All chunks" count="32" chunks={chunks} />;
}
```

Vue · `search-results.vue`

```vue
<script setup lang="ts">
import { ContextCards, type ContextChunk } from "@/components/ui/context-cards";

const chunks: ContextChunk[] = [
  {
    title: "Renewal terms",
    chars: "640 characters",
    body: "The agreement renews on January 4 for 12 months at $2,400 per month unless either party gives 60 days' written notice.",
    source: "Kestrel Logistics – Master Services Agreement (signed 2025-01-04).pdf",
    href: "https://example.com/docs/kestrel-msa.pdf",
    badge: "PDF",
    tone: "red",
  },
  {
    title: "Seat usage, last 90 days",
    chars: "1,250 characters",
    body: "Active seats fell from 180 to 128; the Denver and Reno depots stopped booking dock slots in September.",
    source: "kestrel-usage-q3.csv",
    href: "https://example.com/exports/kestrel-usage-q3.csv",
    badge: "CSV",
    tone: "green",
  },
  {
    title: "Volume discount table",
    chars: "530 characters",
    body: "Accounts with 100 to 249 seats get 12% off list; 250 seats and above get 18% and a named support contact.",
    source: "Pricing 2026.xlsx",
    href: "https://example.com/sheets/pricing-2026.xlsx",
    badge: "XLSX",
    tone: "green",
  },
  {
    title: "Last check-in call",
    chars: "910 characters",
    body: "Their operations lead asked for SMS reminders to drivers and a cheaper plan for seasonal depots.",
    source: "Call notes – Sofia Alvarez.docx",
    href: "https://example.com/docs/kestrel-call-notes.docx",
    badge: "DOC",
    tone: "accent",
  },
  {
    title: "Open support tickets",
    chars: "380 characters",
    body: "Two open tickets: calendar sync delays for the Reno depot (high) and an invoice address change (low).",
    source: "Support export.csv",
    href: "https://example.com/exports/support.csv",
    badge: "CSV",
    tone: "green",
  },
  {
    title: "Roadmap commitment",
    chars: "270 characters",
    body: "SMS reminders ship in Q1; Kestrel is on the beta list.",
    source: "Roadmap.md",
    href: "https://example.com/docs/roadmap.md",
    badge: "MD",
    tone: "neutral",
  },
];
</script>

<template>
  <ContextCards title="All chunks" count="32" :chunks="chunks" />
</template>
```

Svelte · `search-results.svelte`

```svelte
<script lang="ts">
  import { ContextCards, type ContextChunk } from "$lib/components/ui/context-cards";

  const chunks: ContextChunk[] = [
    {
      title: "Renewal terms",
      chars: "640 characters",
      body: "The agreement renews on January 4 for 12 months at $2,400 per month unless either party gives 60 days' written notice.",
      source: "Kestrel Logistics – Master Services Agreement (signed 2025-01-04).pdf",
      href: "https://example.com/docs/kestrel-msa.pdf",
      badge: "PDF",
      tone: "red",
    },
    {
      title: "Seat usage, last 90 days",
      chars: "1,250 characters",
      body: "Active seats fell from 180 to 128; the Denver and Reno depots stopped booking dock slots in September.",
      source: "kestrel-usage-q3.csv",
      href: "https://example.com/exports/kestrel-usage-q3.csv",
      badge: "CSV",
      tone: "green",
    },
    {
      title: "Volume discount table",
      chars: "530 characters",
      body: "Accounts with 100 to 249 seats get 12% off list; 250 seats and above get 18% and a named support contact.",
      source: "Pricing 2026.xlsx",
      href: "https://example.com/sheets/pricing-2026.xlsx",
      badge: "XLSX",
      tone: "green",
    },
    {
      title: "Last check-in call",
      chars: "910 characters",
      body: "Their operations lead asked for SMS reminders to drivers and a cheaper plan for seasonal depots.",
      source: "Call notes – Sofia Alvarez.docx",
      href: "https://example.com/docs/kestrel-call-notes.docx",
      badge: "DOC",
      tone: "accent",
    },
    {
      title: "Open support tickets",
      chars: "380 characters",
      body: "Two open tickets: calendar sync delays for the Reno depot (high) and an invoice address change (low).",
      source: "Support export.csv",
      href: "https://example.com/exports/support.csv",
      badge: "CSV",
      tone: "green",
    },
    {
      title: "Roadmap commitment",
      chars: "270 characters",
      body: "SMS reminders ship in Q1; Kestrel is on the beta list.",
      source: "Roadmap.md",
      href: "https://example.com/docs/roadmap.md",
      badge: "MD",
      tone: "neutral",
    },
  ];
</script>

<ContextCards title="All chunks" count="32" {chunks} />
```

## Recipe

`context-cards.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* context-cards — retrieved knowledge chunks with their sources. The chunk count is our count
 * (boxed), rendered by the adapter.
 *
 * A mount is not an arrival (`docs motion`): a plain mount shows everything at once. With
 * appear (the host's prop, for a set its code adds live) the header fades in with the first card
 * and the cards rise in a capped stagger (--fndn-row-index, set only on cards present at mount).
 * A card that arrives after mount always enters, with no delay.
 *
 * Author text takes its direction from its own first letter (plaintext), so Hebrew in a
 * left-to-right page keeps its punctuation in place. */

export const contextCards = tv({
  slots: {
    base: "flex w-full max-w-[380px] flex-col gap-2",
    header: [
      "flex min-w-0 items-center gap-2 px-0.5",
      "animate-[fndn-fade-in_var(--fndn-duration-enter)_var(--fndn-easing-out-strong)_both]",
    ],
    title: "min-w-0 overflow-hidden text-ellipsis whitespace-nowrap text-sm font-semibold text-ink [unicode-bidi:plaintext]",
    card: [
      "min-w-0 overflow-hidden rounded-card bg-surface shadow-card",
      "animate-[fndn-fade-up_var(--fndn-duration-enter)_var(--fndn-easing-out-strong)_calc(min(var(--fndn-row-index,0),var(--fndn-motion-stagger-max))*var(--fndn-duration-stagger))_both]",
    ],
    bar: "flex min-w-0 items-center gap-2.5 px-3 py-2.5 border-b border-solid border-b-line",
    cardTitle: [
      "flex min-w-0 items-center gap-1.5 text-sm font-medium leading-[18px] text-ink",
      "[&>[data-slot=icon]]:size-[11px] [&>[data-slot=icon]]:text-[11px] [&>[data-slot=icon]]:text-ink-3",
      "[&>span]:min-w-0 [&>span]:overflow-hidden [&>span]:text-ellipsis [&>span]:whitespace-nowrap [&>span]:[unicode-bidi:plaintext]",
    ],
    chars: "shrink-0 ms-auto text-xs leading-[18px] text-ink-2 tabular-nums whitespace-nowrap [unicode-bidi:plaintext]",
    body: "m-0 pt-2 px-3 pb-1 text-dense leading-[1.625] text-ink-2 wrap-anywhere [unicode-bidi:plaintext]",
    footer: "flex min-w-0 px-3 pb-3 pt-0",
    /* source chip: arrives with its card (one entrance per card); presses like a chip */
    source: [
      "inline-flex min-w-0 max-w-full h-6 items-center gap-1.5 ps-[5px] pe-2",
      "rounded-pill bg-inset shadow-btn text-ink-2 text-xs font-medium leading-none no-underline",
      "hover:bg-hover hover:text-ink active:bg-hover-2 active:text-ink",
      "motion-colors-fast motion-transform-press active:scale-press",
      "[&>[data-slot=icon]]:size-[9px] [&>[data-slot=icon]]:text-[9px]",
    ],
    sourceName: "min-w-0 overflow-hidden text-ellipsis whitespace-nowrap [unicode-bidi:plaintext]",
    /* 14px file-type square, tinted by its tone; a four-letter type (DOCX, XLSX) widens it a
     * little rather than being cut. fndn-check-ok: a three-letter file type (PDF, CSV) does
     * not fit our avatar, which holds two letters */
    badge: [
      "inline-flex shrink-0 min-w-3.5 h-3.5 items-center justify-center overflow-hidden rounded-[4px]",
      "bg-ink-3 text-on-accent text-[6.5px] font-bold tracking-[-0.2px] leading-none whitespace-nowrap",
    ],
  },
  variants: {
    /* appear=false (the default): what is present at mount is simply there; a card added later
     * still enters. Set per part by the adapter. */
    appear: { true: {}, false: { header: "animate-none", card: "animate-none" } },
    /* the file-type square's tint */
    tone: {
      neutral: {},
      red: { badge: "bg-red" },
      green: { badge: "bg-green" },
      orange: { badge: "bg-orange" },
      accent: { badge: "bg-accent" },
    },
  },
});

export type ContextCardsRecipeProps = VariantProps<typeof contextCards>;
```
