# Insight Cards

Insights from an agent, one at a time, each with a small chart.

Paged insights from an agent: a header with the count and a pager, then one insight at a time. Each insight is a sentence (with entity chips and value pills), a small card with a legend and an inline SVG chart, and a follow-up button. The chart is drawn by a shared builder (insight-chart.ts) in every target, has a text alternative, and never animates. Pages stack in one cell, so the component is as tall as its tallest insight and paging never shifts what sits below it.

Kind: block · Category: Data · Status: beta · Targets: React, Vue, Svelte

## Add

```bash
npx fndn add insight-cards
```

It writes the folder `insight-cards/` into the project's ui folder (`index.ts`, `insight-cards.tsx`, `InsightCards.vue`, `InsightCards.svelte`, `insight-cards.recipe.ts`), and what it is built from: [Button](/components/button.md), [Count](/components/count.md), [Empty State](/components/empty-state.md), [Entity Chip](/components/entity-chip.md), [Pager](/components/pager.md), [Value Pill](/components/value-pill.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { InsightCards } from "@/components/ui/insight-cards";
```

```vue
import { InsightCards } from "@/components/ui/insight-cards";
```

```svelte
import { InsightCards } from "$lib/components/ui/insight-cards";
```

## Parts

In the DOM the root carries `data-slot="insight-cards"` and each part `data-slot="insight-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` | `section` | `insight-cards` |  | aria-roledescription=carousel, labelled by the title |
| `header` | `div` | `insight-cards-header` |  | Title (with a plain Count) and the pager: a Pager with loop, layout start, label 'Choose insight', buttons 'Previous insight' / 'Next insight'; its position is the role=status '2 of 3'. With no insights an empty-state row (centred) replaces the pages. |
| `title` | `span` | `insight-cards-title` |  | The title and a plain Count of the insights |
| `pages` | `div` | `insight-cards-pages` |  | One grid cell all pages share |
| `page` | `article` | `insight-cards-page` | repeats | role=group, aria-roledescription=slide; data-state=active\|inactive (inactive pages are visibility: hidden, so they keep their size but leave the tab order and the accessibility tree) |
| `summary` | `p` | `insight-cards-summary` |  | The insight as a sentence: text, EntityChip and ValuePill |
| `card` | `div` | `insight-cards-card` |  |  |
| `card-title` | `span` | `insight-cards-card-title` |  |  |
| `legend` | `ul` | `insight-cards-legend` |  |  |
| `legend-item` | `li` | `insight-cards-legend-item` | repeats |  |
| `swatch` | `span` | `insight-cards-swatch` |  | Series colour; data-tone |
| `legend-name` | `span` | `insight-cards-legend-name` |  | Swatch + label; title carries the full name |
| `legend-label` | `span` | `insight-cards-legend-label` |  | Series name; truncates at the end |
| `legend-value` | `span` | `insight-cards-legend-value` |  | Latest value (line, bar) or share; tabular, never truncated |
| `chart` | `svg` | `insight-cards-chart` |  | role=img with a generated aria-label; data-kind=line\|bar\|share. Shapes come from chartShapes() |
| `line` | `path` | `insight-cards-line` | optional, repeats |  |
| `bar` | `rect` | `insight-cards-bar` | optional, repeats |  |
| `segment` | `rect` | `insight-cards-segment` | optional, repeats |  |
| `rule` | `line` | `insight-cards-rule` | optional, repeats | data-kind=zero\|threshold |
| `action` | `button` | `insight-cards-action` | optional | Follow-up prompt; an outline sm Button |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `insights` | `{ id: string; title: string; summary: string \| Array<string \| { entity: string, color?: string } \| { value: string, tone?: 'neutral'\|'green'\|'orange'\|'red'\|'accent' }>; chart?: { kind: 'line'\|'bar'\|'share', series: { name, values: number[], tone?: 'accent'\|'orange'\|'red'\|'green'\|'neutral' }[], format?: 'number'\|'percent'\|'money', threshold?: number, label?: string }; action?: string }[]` |  | The insights, in order. Owned by the parent: pass a new array to change them. |
| `page` | `number` | `0` | Bindable (React: `defaultPage` and `onPageChange`; Vue: `v-model:page`; Svelte: `bind:page`). Index of the insight shown. Clamped to the list. |
| `title` | `string` | `"Insights"` |  |
| `emptyText` | `string` | `"No insights yet."` |  |
| `tone` | `"accent" \| "orange" \| "red" \| "green" \| "neutral"` | `"accent"` | Per series (chart.series[].tone): colour of its swatch and of its line, bars or segment. |

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

## Events

| Event | Payload |
| --- | --- |
| `pageChange` | (page: number) |
| `action` | (id: string) the follow-up button of an insight was pressed |

## States

`hover`, `press`, `focus-visible`, `disabled`

## Keyboard and accessibility

Role: region (carousel) with a pager group and a status.

Keyboard:

- Tab reaches the previous and next buttons, then the follow-up button of the shown insight
- Enter / Space on previous or next change the page; focus stays on the button
- ArrowLeft / ArrowRight while focus is in the pager change the page (mirrored right-to-left); Home / End jump to the first and last
- Paging wraps around; with one insight or none the buttons are aria-disabled (they keep focus)

Notes:

- The position ('2 of 3') sits in a role=status region, so a page change is announced.
- Every chart is role=img with a text alternative generated from its data (or chart.label).
- Inactive pages are visibility: hidden: out of the tab order and the accessibility tree.

## Motion

- page change: instant. No crossfade (not even a short blur): the pager is used many times in a row and from the keyboard, and the content is data
- chart: never animates, on mount or on page change
- pager buttons and follow-up button: the shared Button press and gated hover

## Tokens

`color.surface`, `color.ink`, `color.ink-2`, `color.ink-3`, `color.line`, `color.line-strong`, `color.accent`, `color.orange`, `color.red`, `color.green`, `shadow.hairline`, `radius.card`, `text.xs`, `text.sm`, `radius.pill`

## Dependencies

- [Button](/components/button.md)
- [Count](/components/count.md)
- [Empty State](/components/empty-state.md)
- [Entity Chip](/components/entity-chip.md)
- [Pager](/components/pager.md)
- [Value Pill](/components/value-pill.md)

## Examples

### Weekly revenue insights

React · `default.tsx`

```tsx
import { InsightCards, type Insight } from "@/components/ui/insight-cards";

const insights: Insight[] = [
  {
    id: "mix",
    title: "Revenue by plan",
    summary: [
      { entity: "Enterprise" },
      " brings in ",
      { value: "54.2%", tone: "orange" },
      " of revenue from only 11 accounts.",
    ],
    chart: {
      kind: "share",
      series: [
        { name: "Enterprise", tone: "orange", values: [54.2] },
        { name: "Team", tone: "accent", values: [32.1] },
        { name: "Starter", tone: "neutral", values: [13.7] },
      ],
    },
    action: "What if Orbit Studio does not renew?",
  },
  {
    id: "growth",
    title: "Plan growth",
    summary: [
      { entity: "Team plan" },
      " MRR grew ",
      { value: "+11.1%", tone: "green" },
      " in eight weeks to ",
      { value: "$112,400" },
      ", while Starter stayed flat.",
    ],
    chart: {
      kind: "line",
      format: "percent",
      series: [
        { name: "Team", tone: "accent", values: [0, 1.7, 2.9, 4.5, 5.6, 7, 8.8, 11.1] },
        {
          name: "Starter",
          tone: "neutral",
          values: [0, 0.7, 0.2, 1.2, 0.5, 1, 0.2, 0.7],
        },
      ],
    },
    action: "Which accounts drove the growth?",
  },
  {
    id: "refunds",
    title: "Refund spike",
    summary: [
      "Refunds on ",
      { value: "Nov 12" },
      " reached ",
      { value: "$4,180", tone: "red" },
      ", about six times the daily average.",
    ],
    chart: {
      kind: "bar",
      format: "money",
      threshold: 1500,
      series: [{ name: "Refunds", tone: "red", values: [620, 910, 740, 880, 1020, 4180, 960] }],
    },
    action: "Show the refunds from Nov 12",
  },
];

export default function Default() {
  return <InsightCards title="This week" insights={insights} style={{ width: 344 }} />;
}
```

Vue · `default.vue`

```vue
<script setup lang="ts">
import { InsightCards, type Insight } from "@/components/ui/insight-cards";

const insights: Insight[] = [
  {
    id: "mix",
    title: "Revenue by plan",
    summary: [
      { entity: "Enterprise" },
      " brings in ",
      { value: "54.2%", tone: "orange" },
      " of revenue from only 11 accounts.",
    ],
    chart: {
      kind: "share",
      series: [
        { name: "Enterprise", tone: "orange", values: [54.2] },
        { name: "Team", tone: "accent", values: [32.1] },
        { name: "Starter", tone: "neutral", values: [13.7] },
      ],
    },
    action: "What if Orbit Studio does not renew?",
  },
  {
    id: "growth",
    title: "Plan growth",
    summary: [
      { entity: "Team plan" },
      " MRR grew ",
      { value: "+11.1%", tone: "green" },
      " in eight weeks to ",
      { value: "$112,400" },
      ", while Starter stayed flat.",
    ],
    chart: {
      kind: "line",
      format: "percent",
      series: [
        { name: "Team", tone: "accent", values: [0, 1.7, 2.9, 4.5, 5.6, 7, 8.8, 11.1] },
        {
          name: "Starter",
          tone: "neutral",
          values: [0, 0.7, 0.2, 1.2, 0.5, 1, 0.2, 0.7],
        },
      ],
    },
    action: "Which accounts drove the growth?",
  },
  {
    id: "refunds",
    title: "Refund spike",
    summary: [
      "Refunds on ",
      { value: "Nov 12" },
      " reached ",
      { value: "$4,180", tone: "red" },
      ", about six times the daily average.",
    ],
    chart: {
      kind: "bar",
      format: "money",
      threshold: 1500,
      series: [{ name: "Refunds", tone: "red", values: [620, 910, 740, 880, 1020, 4180, 960] }],
    },
    action: "Show the refunds from Nov 12",
  },
];
</script>

<template>
  <InsightCards title="This week" :insights="insights" style="width: 344px" />
</template>
```

Svelte · `default.svelte`

```svelte
<script lang="ts">
  import { InsightCards, type Insight } from "$lib/components/ui/insight-cards";

  const insights: Insight[] = [
    {
      id: "mix",
      title: "Revenue by plan",
      summary: [
        { entity: "Enterprise" },
        " brings in ",
        { value: "54.2%", tone: "orange" },
        " of revenue from only 11 accounts.",
      ],
      chart: {
        kind: "share",
        series: [
          { name: "Enterprise", tone: "orange", values: [54.2] },
          { name: "Team", tone: "accent", values: [32.1] },
          { name: "Starter", tone: "neutral", values: [13.7] },
        ],
      },
      action: "What if Orbit Studio does not renew?",
    },
    {
      id: "growth",
      title: "Plan growth",
      summary: [
        { entity: "Team plan" },
        " MRR grew ",
        { value: "+11.1%", tone: "green" },
        " in eight weeks to ",
        { value: "$112,400" },
        ", while Starter stayed flat.",
      ],
      chart: {
        kind: "line",
        format: "percent",
        series: [
          { name: "Team", tone: "accent", values: [0, 1.7, 2.9, 4.5, 5.6, 7, 8.8, 11.1] },
          {
            name: "Starter",
            tone: "neutral",
            values: [0, 0.7, 0.2, 1.2, 0.5, 1, 0.2, 0.7],
          },
        ],
      },
      action: "Which accounts drove the growth?",
    },
    {
      id: "refunds",
      title: "Refund spike",
      summary: [
        "Refunds on ",
        { value: "Nov 12" },
        " reached ",
        { value: "$4,180", tone: "red" },
        ", about six times the daily average.",
      ],
      chart: {
        kind: "bar",
        format: "money",
        threshold: 1500,
        series: [{ name: "Refunds", tone: "red", values: [620, 910, 740, 880, 1020, 4180, 960] }],
      },
      action: "Show the refunds from Nov 12",
    },
  ];
</script>

<InsightCards title="This week" {insights} style="width: 344px" />
```

### Account at risk before renewal

React · `churn-risk.tsx`

```tsx
import { InsightCards, type Insight } from "@/components/ui/insight-cards";

const insights: Insight[] = [
  {
    id: "tidewater",
    title: "Bookings falling",
    summary: [
      { entity: "Tidewater Realty" },
      " booked ",
      { value: "-38%", tone: "red" },
      " fewer viewings over eight weeks; the contract renews on ",
      { value: "Jan 4" },
      ".",
    ],
    chart: {
      kind: "line",
      format: "number",
      series: [
        {
          name: "Bookings per week",
          tone: "red",
          values: [412, 398, 371, 344, 309, 288, 270, 255],
        },
      ],
    },
    action: "Draft a check-in email for Sofia",
  },
];

export default function ChurnRisk() {
  return <InsightCards title="Account health" insights={insights} style={{ width: 344 }} />;
}
```

Vue · `churn-risk.vue`

```vue
<script setup lang="ts">
import { InsightCards, type Insight } from "@/components/ui/insight-cards";

const insights: Insight[] = [
  {
    id: "tidewater",
    title: "Bookings falling",
    summary: [
      { entity: "Tidewater Realty" },
      " booked ",
      { value: "-38%", tone: "red" },
      " fewer viewings over eight weeks; the contract renews on ",
      { value: "Jan 4" },
      ".",
    ],
    chart: {
      kind: "line",
      format: "number",
      series: [
        {
          name: "Bookings per week",
          tone: "red",
          values: [412, 398, 371, 344, 309, 288, 270, 255],
        },
      ],
    },
    action: "Draft a check-in email for Sofia",
  },
];
</script>

<template>
  <InsightCards title="Account health" :insights="insights" style="width: 344px" />
</template>
```

Svelte · `churn-risk.svelte`

```svelte
<script lang="ts">
  import { InsightCards, type Insight } from "$lib/components/ui/insight-cards";

  const insights: Insight[] = [
    {
      id: "tidewater",
      title: "Bookings falling",
      summary: [
        { entity: "Tidewater Realty" },
        " booked ",
        { value: "-38%", tone: "red" },
        " fewer viewings over eight weeks; the contract renews on ",
        { value: "Jan 4" },
        ".",
      ],
      chart: {
        kind: "line",
        format: "number",
        series: [
          {
            name: "Bookings per week",
            tone: "red",
            values: [412, 398, 371, 344, 309, 288, 270, 255],
          },
        ],
      },
      action: "Draft a check-in email for Sofia",
    },
  ];
</script>

<InsightCards title="Account health" {insights} style="width: 344px" />
```

### First week, nothing to report yet

React · `empty.tsx`

```tsx
import { InsightCards } from "@/components/ui/insight-cards";

export default function Empty() {
  return (
    <InsightCards
      title="This week"
      insights={[]}
      emptyText="No insights yet. They appear after your first full week of bookings."
      style={{ width: 344 }}
    />
  );
}
```

Vue · `empty.vue`

```vue
<script setup lang="ts">
import { InsightCards } from "@/components/ui/insight-cards";
</script>

<template>
  <InsightCards
    title="This week"
    :insights="[]"
    empty-text="No insights yet. They appear after your first full week of bookings."
    style="width: 344px"
  />
</template>
```

Svelte · `empty.svelte`

```svelte
<script lang="ts">
  import { InsightCards } from "$lib/components/ui/insight-cards";
</script>

<InsightCards
  title="This week"
  insights={[]}
  emptyText="No insights yet. They appear after your first full week of bookings."
  style="width: 344px"
/>
```

## Recipe

`insight-cards.recipe.ts`:

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

/* insight-cards — paged insights: header + pager, then one insight (sentence, chart card, follow-up).
 * Pages share one grid cell: the component is as tall as its tallest insight, so paging never
 * moves what sits below it. Inactive pages are visibility: hidden (out of the tab order and the
 * accessibility tree). Nothing here animates except the shared button press and gated hover:
 * page changes are instant and charts are data. Composed: count (title), pager (header),
 * empty-state (no insights), entity-chip and value-pill (in the sentence).
 *
 * Author text takes its direction from its own first letter (plaintext), so English in a
 * right-to-left page (and the reverse) keeps its punctuation in place. */

export const insightCards = tv({
  slots: {
    base: "flex flex-col w-full max-w-[344px] min-w-0 text-ink",
    header: "flex items-center justify-between gap-2 min-w-0",
    title: "flex items-baseline gap-1.5 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap text-sm font-semibold",
    pages: "grid min-w-0",
    page: "[grid-area:1/1] flex flex-col items-start gap-2 min-w-0 pt-1.5",
    summary: "self-stretch m-0 min-w-0 text-dense leading-[1.6] text-ink-2 wrap-anywhere [unicode-bidi:plaintext]",
    card: "flex flex-col gap-2.5 self-stretch min-w-0 p-3 rounded-card bg-surface shadow-hairline",
    cardTitle: "min-w-0 text-xs font-medium leading-[1.35] text-ink wrap-anywhere [unicode-bidi:plaintext]",
    legend: "flex flex-wrap gap-x-4 gap-y-1.5 min-w-0 m-0 p-0 list-none",
    legendItem: "flex flex-[1_1_96px] flex-col gap-0.5 min-w-0",
    legendName: "flex items-center gap-1.5 min-w-0 text-[11.5px] leading-[1.3] text-ink-2",
    legendLabel: "min-w-0 overflow-hidden text-ellipsis whitespace-nowrap [unicode-bidi:plaintext]",
    swatch: [
      "shrink-0 size-2 rounded-pill bg-accent",
    ],
    /* numbers are never truncated: a huge one wraps at its group separators instead. Signed
     * numbers read left-to-right in either direction; the box still sits at the start */
    legendValue: [
      "self-start text-[15px] font-semibold tracking-[-0.01em] leading-[1.2] tabular-nums text-ink wrap-anywhere",
      "[direction:ltr] [unicode-bidi:isolate]",
    ],
    /* the plot is stretched to this box; strokes keep their width */
    chart: "block w-full h-24 overflow-visible",
    line: [
      "fill-none stroke-accent stroke-2 [stroke-linecap:round] [stroke-linejoin:round] [vector-effect:non-scaling-stroke]",
    ],
    bar: "fill-accent",
    segment: "fill-accent",
    /* follow-up: the real Button (outline, sm) whose label may wrap; these classes go to its
     * root through className (whitespace and leading replace the button's own), the label inherits them */
    action: "max-w-full whitespace-normal text-start leading-[1.3] wrap-anywhere [unicode-bidi:plaintext]",
    rule: "stroke-line stroke-1 [vector-effect:non-scaling-stroke]",
  },
  variants: {
    /* the page shown; the others keep their room in the cell, unseen */
    active: { false: { page: "invisible" } },
    /* a series' colour: its swatch, line, bars or share segment */
    tone: {
      accent: {},
      orange: { swatch: "bg-orange", line: "stroke-orange", bar: "fill-orange", segment: "fill-orange" },
      red: { swatch: "bg-red", line: "stroke-red", bar: "fill-red", segment: "fill-red" },
      green: { swatch: "bg-green", line: "stroke-green", bar: "fill-green", segment: "fill-green" },
      neutral: { swatch: "bg-ink-3", line: "stroke-ink-3", bar: "fill-line-strong", segment: "fill-line-strong" },
    },
    /* the chart: a share is one 12px bar */
    kind: { line: {}, bar: {}, share: { chart: "h-3" } },
    /* a rule: the zero line, or a dashed threshold */
    rule: { zero: {}, threshold: { rule: "stroke-line-strong [stroke-dasharray:3_3]" } },
  },
});

export type InsightCardsRecipeProps = VariantProps<typeof insightCards>;
```
