# Diff Table

Changes an agent proposes to a table, accepted or rejected row by row.

Edits an agent proposes to tabular data, reviewed row by row before they are applied. Each changed row is the control: click it, or focus its include box and press Enter / Space, to include or exclude that addition or removal before applying. A native table; the checkbox role sits on the include box inside each changed row.

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

## Add

```bash
npx fndn add diff-table
```

It writes the folder `diff-table/` into the project's ui folder (`index.ts`, `diff-table.tsx`, `DiffTable.vue`, `DiffTable.svelte`, `diff-table.recipe.ts`), and what it is built from: [Button](/components/button.md), [Checkbox](/components/checkbox.md), [Empty State](/components/empty-state.md), [Status Pill](/components/status-pill.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { DiffTable } from "@/components/ui/diff-table";
```

```vue
import { DiffTable } from "@/components/ui/diff-table";
```

```svelte
import { DiffTable } from "$lib/components/ui/diff-table";
```

## Parts

In the DOM the root carries `data-slot="diff-table"` and each part `data-slot="diff-table-<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` | `diff-table` |  | max-width 380; data-enter once painted (an added row reveals only after that) |
| `card` | `div` | `diff-table-card` |  |  |
| `bar` | `div` | `diff-table-bar` |  | title + hint |
| `title` | `span` | `diff-table-title` |  |  |
| `hint` | `span` | `diff-table-hint` | optional | Gone once applied, and when no row changes |
| `table` | `table` | `diff-table-table` |  | Native table, fixed layout |
| `col` | `col` | `diff-table-col` | repeats | One per column (name, category, value); its width is the recipe col variant |
| `th` | `th` | `diff-table-th` | repeats | scope=col |
| `row` | `tr` | `diff-table-row` | repeats | data-key; its change (removed\|added\|unchanged), included and toggleable state are recipe variants |
| `cell` | `td` | `diff-table-cell` | repeats | Its column (name\|category\|value) is a recipe variant. The category is a status-pill (tone neutral, size sm) whose dot takes the row tone through dotTone (data-dot-tone=accent\|orange\|green; none for neutral) |
| `reveal` | `div` | `diff-table-reveal` | optional | Added rows only: the reveal wrapper of each cell (grid 0fr → 1fr on mount) |
| `pad` | `div` | `diff-table-pad` | optional | Added rows only: the cell padding, inside the clipping child of reveal |
| `value` | `span` | `diff-table-value` |  | Value text + include box (a checkbox: size md, tone red for a removal / green for an addition, aria-label on its input, roving tabindex on the inputs; disabled once applied) |
| `value-text` | `span` | `diff-table-value-text` |  | Truncates at the end; full value in title |
| `empty` | `td` | `diff-table-empty` | optional | No rows: one cell across the columns (in a plain tr) holding the real EmptyState (size block, icon table, labels.empty). With no changed row, Apply is not offered |
| `footer` | `div` | `diff-table-footer` |  |  |
| `summary` | `span` | `diff-table-summary` |  |  |
| `applied` | `span` | `diff-table-applied` | optional | The real StatusPill (tone green, with a mark), marked data-diff-table="applied", after apply; pops in and takes focus (tabindex=-1) |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `title` | `string` | `"Proposed changes"` |  |
| `columns` | `string[]` | `["Name","Category","Value"]` |  |
| `rows` | `{ key: string; name: string; category: string; tone: accent\|neutral\|orange\|green; value: string; change: removed\|added\|unchanged }[]` |  |  |
| `included` | `object` |  | Bindable (React: `defaultIncluded` and `onIncludedChange`; Vue: `v-model:included`; Svelte: `bind:included`). Record<key, boolean>; defaults to every changed row included |
| `accepted` | `boolean` | `false` | Bindable (React: `defaultAccepted` and `onAcceptedChange`; Vue: `v-model:accepted`; Svelte: `bind:accepted`).  |
| `labels` | `object` |  | { hint, remove, add, apply, removal, removals, addition, additions, edit, edits, applied, change, changes, empty } |

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

## Events

| Event | Payload |
| --- | --- |
| `toggle` | (key, included) |
| `apply` | (included: Record<string, boolean>) |

## States

`removed`, `added`, `included`, `excluded`, `accepted`, `row-hover`, `row-press`, `focus-visible`, `disabled`

## Keyboard and accessibility

Role: table; checkbox per changed row.

Keyboard:

- Tab reaches the include boxes once (roving tabindex), then the Apply button
- Enter / Space toggle the focused row's edit
- ArrowDown / ArrowUp move to the next / previous changed row; Home / End to the first / last
- Enter / Space on Apply applies; focus moves to the applied pill

Notes:

- The table keeps native semantics (table, th scope=col, tr, td). Each changed row holds a checkbox (the native input inside the checkbox component), named "Remove <name>" or "Add <name>", so a screen reader reads the row as a table row and the box as a checkbox.
- The focus ring is the checkbox's own, on the include box, while it has keyboard focus.
- After Apply the boxes stay readable but are disabled and leave the tab order.

## Motion

- row tint, text colour and the category pill: colour / opacity over duration.base from the pointer; instant from the keyboard (kbd-instant), like the include box
- row hover (toggleable rows, fine pointers): a 4% ink layer, instant both ways; the press darkens the fill beneath to 7% over duration.base
- include box: the checkbox's own recipe (fill leads, the check is drawn, shorter exit)
- added row: reveal recipe (grid-template-rows over duration.reveal, opacity over duration.base, through @starting-style) only for a row added after the table's first paint (data-enter on the root, lib/paint.ts); the rows it mounts with are simply there; no timers
- applied pill: the status-pill's pop-in (mark) over duration.popup, once
- Apply button: the button's own press

## Tokens

`color.surface`, `color.ink`, `color.ink-2`, `color.ink-3`, `color.line`, `color.accent`, `color.green`, `color.green-tint`, `color.red`, `color.red-tint`, `color.orange`, `shadow.card`, `radius.card`, `text.2xs`, `text.xs`, `text.sm`, `easing.out-strong`, `duration.base`, `duration.reveal`

## Dependencies

- [Button](/components/button.md)
- [Checkbox](/components/checkbox.md)
- [Empty State](/components/empty-state.md)
- [Status Pill](/components/status-pill.md)

## Examples

### Review the agent's price change

React · `default.tsx`

```tsx
import type { ComponentProps } from "react";
import { DiffTable } from "@/components/ui/diff-table";

type Props = ComponentProps<typeof DiffTable>;

const columns: Props["columns"] = ["Plan", "Billing", "Price"];

const rows: Props["rows"] = [
  {
    key: "team-49",
    name: "Team",
    category: "Monthly",
    tone: "accent",
    value: "$49 per seat",
    change: "removed",
  },
  {
    key: "team-59",
    name: "Team",
    category: "Monthly",
    tone: "accent",
    value: "$59 per seat",
    change: "added",
  },
  {
    key: "business",
    name: "Business",
    category: "Monthly",
    tone: "accent",
    value: "$99 per seat",
    change: "unchanged",
  },
];

export default function ProposedPriceChanges() {
  return <DiffTable title="Proposed price changes" columns={columns} rows={rows} />;
}
```

Vue · `default.vue`

```vue
<script setup lang="ts">
import { DiffTable, type DiffTableRow } from "@/components/ui/diff-table";

const columns: [string, string, string] = ["Plan", "Billing", "Price"];

const rows: DiffTableRow[] = [
  {
    key: "team-49",
    name: "Team",
    category: "Monthly",
    tone: "accent",
    value: "$49 per seat",
    change: "removed",
  },
  {
    key: "team-59",
    name: "Team",
    category: "Monthly",
    tone: "accent",
    value: "$59 per seat",
    change: "added",
  },
  {
    key: "business",
    name: "Business",
    category: "Monthly",
    tone: "accent",
    value: "$99 per seat",
    change: "unchanged",
  },
];
</script>

<template>
  <DiffTable title="Proposed price changes" :columns="columns" :rows="rows" />
</template>
```

Svelte · `default.svelte`

```svelte
<script lang="ts">
  import { DiffTable, type DiffTableRow } from "$lib/components/ui/diff-table";

  const columns: [string, string, string] = ["Plan", "Billing", "Price"];

  const rows: DiffTableRow[] = [
    {
      key: "team-49",
      name: "Team",
      category: "Monthly",
      tone: "accent",
      value: "$49 per seat",
      change: "removed",
    },
    {
      key: "team-59",
      name: "Team",
      category: "Monthly",
      tone: "accent",
      value: "$59 per seat",
      change: "added",
    },
    {
      key: "business",
      name: "Business",
      category: "Monthly",
      tone: "accent",
      value: "$99 per seat",
      change: "unchanged",
    },
  ];
</script>

<DiffTable title="Proposed price changes" columns={columns} rows={rows} />
```

### Keep the Business price for now

React · `business-held-back.tsx`

```tsx
import type { ComponentProps } from "react";
import { DiffTable } from "@/components/ui/diff-table";

type Props = ComponentProps<typeof DiffTable>;

const columns: Props["columns"] = ["Plan", "Billing", "Price"];

const rows: Props["rows"] = [
  {
    key: "team-49",
    name: "Team",
    category: "Monthly",
    tone: "accent",
    value: "$49 per seat",
    change: "removed",
  },
  {
    key: "team-59",
    name: "Team",
    category: "Monthly",
    tone: "accent",
    value: "$59 per seat",
    change: "added",
  },
  {
    key: "team-annual",
    name: "Team",
    category: "Annual",
    tone: "green",
    value: "$490 per seat",
    change: "unchanged",
  },
  {
    key: "business-99",
    name: "Business",
    category: "Monthly",
    tone: "accent",
    value: "$99 per seat",
    change: "removed",
  },
  {
    key: "business-119",
    name: "Business",
    category: "Monthly",
    tone: "accent",
    value: "$119 per seat",
    change: "added",
  },
];

export default function BusinessHeldBack() {
  return (
    <DiffTable
      title="Proposed price changes"
      columns={columns}
      rows={rows}
      defaultIncluded={{ "business-99": false, "business-119": false }}
    />
  );
}
```

Vue · `business-held-back.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { DiffTable, type DiffTableRow } from "@/components/ui/diff-table";

const columns: [string, string, string] = ["Plan", "Billing", "Price"];

const rows: DiffTableRow[] = [
  {
    key: "team-49",
    name: "Team",
    category: "Monthly",
    tone: "accent",
    value: "$49 per seat",
    change: "removed",
  },
  {
    key: "team-59",
    name: "Team",
    category: "Monthly",
    tone: "accent",
    value: "$59 per seat",
    change: "added",
  },
  {
    key: "team-annual",
    name: "Team",
    category: "Annual",
    tone: "green",
    value: "$490 per seat",
    change: "unchanged",
  },
  {
    key: "business-99",
    name: "Business",
    category: "Monthly",
    tone: "accent",
    value: "$99 per seat",
    change: "removed",
  },
  {
    key: "business-119",
    name: "Business",
    category: "Monthly",
    tone: "accent",
    value: "$119 per seat",
    change: "added",
  },
];

const included = ref({ "business-99": false, "business-119": false });
</script>

<template>
  <DiffTable
    title="Proposed price changes"
    :columns="columns"
    :rows="rows"
    v-model:included="included"
  />
</template>
```

Svelte · `business-held-back.svelte`

```svelte
<script lang="ts">
  import { DiffTable, type DiffTableRow } from "$lib/components/ui/diff-table";

  const columns: [string, string, string] = ["Plan", "Billing", "Price"];

  const rows: DiffTableRow[] = [
    {
      key: "team-49",
      name: "Team",
      category: "Monthly",
      tone: "accent",
      value: "$49 per seat",
      change: "removed",
    },
    {
      key: "team-59",
      name: "Team",
      category: "Monthly",
      tone: "accent",
      value: "$59 per seat",
      change: "added",
    },
    {
      key: "team-annual",
      name: "Team",
      category: "Annual",
      tone: "green",
      value: "$490 per seat",
      change: "unchanged",
    },
    {
      key: "business-99",
      name: "Business",
      category: "Monthly",
      tone: "accent",
      value: "$99 per seat",
      change: "removed",
    },
    {
      key: "business-119",
      name: "Business",
      category: "Monthly",
      tone: "accent",
      value: "$119 per seat",
      change: "added",
    },
  ];

  let included = $state({ "business-99": false, "business-119": false });
</script>

<DiffTable title="Proposed price changes" columns={columns} rows={rows} bind:included={included} />
```

### Price change applied

React · `applied.tsx`

```tsx
import type { ComponentProps } from "react";
import { DiffTable } from "@/components/ui/diff-table";

type Props = ComponentProps<typeof DiffTable>;

const columns: Props["columns"] = ["Plan", "Billing", "Price"];

const rows: Props["rows"] = [
  {
    key: "team-49",
    name: "Team",
    category: "Monthly",
    tone: "accent",
    value: "$49 per seat",
    change: "removed",
  },
  {
    key: "team-59",
    name: "Team",
    category: "Monthly",
    tone: "accent",
    value: "$59 per seat",
    change: "added",
  },
  {
    key: "business",
    name: "Business",
    category: "Monthly",
    tone: "accent",
    value: "$99 per seat",
    change: "unchanged",
  },
];

export default function PriceChangesApplied() {
  return <DiffTable title="Proposed price changes" columns={columns} rows={rows} defaultAccepted />;
}
```

Vue · `applied.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { DiffTable, type DiffTableRow } from "@/components/ui/diff-table";

const columns: [string, string, string] = ["Plan", "Billing", "Price"];

const rows: DiffTableRow[] = [
  {
    key: "team-49",
    name: "Team",
    category: "Monthly",
    tone: "accent",
    value: "$49 per seat",
    change: "removed",
  },
  {
    key: "team-59",
    name: "Team",
    category: "Monthly",
    tone: "accent",
    value: "$59 per seat",
    change: "added",
  },
  {
    key: "business",
    name: "Business",
    category: "Monthly",
    tone: "accent",
    value: "$99 per seat",
    change: "unchanged",
  },
];

const accepted = ref(true);
</script>

<template>
  <DiffTable
    title="Proposed price changes"
    :columns="columns"
    :rows="rows"
    v-model:accepted="accepted"
  />
</template>
```

Svelte · `applied.svelte`

```svelte
<script lang="ts">
  import { DiffTable, type DiffTableRow } from "$lib/components/ui/diff-table";

  const columns: [string, string, string] = ["Plan", "Billing", "Price"];

  const rows: DiffTableRow[] = [
    {
      key: "team-49",
      name: "Team",
      category: "Monthly",
      tone: "accent",
      value: "$49 per seat",
      change: "removed",
    },
    {
      key: "team-59",
      name: "Team",
      category: "Monthly",
      tone: "accent",
      value: "$59 per seat",
      change: "added",
    },
    {
      key: "business",
      name: "Business",
      category: "Monthly",
      tone: "accent",
      value: "$99 per seat",
      change: "unchanged",
    },
  ];

  let accepted = $state(true);
</script>

<DiffTable title="Proposed price changes" columns={columns} rows={rows} bind:accepted={accepted} />
```

### Nothing to change

React · `no-changes.tsx`

```tsx
import type { ComponentProps } from "react";
import { DiffTable } from "@/components/ui/diff-table";

type Props = ComponentProps<typeof DiffTable>;

const columns: Props["columns"] = ["Plan", "Billing", "Price"];

const labels: Props["labels"] = { empty: "Prices already match the plan sheet" };

export default function NoPriceChanges() {
  return <DiffTable title="Proposed price changes" columns={columns} rows={[]} labels={labels} />;
}
```

Vue · `no-changes.vue`

```vue
<script setup lang="ts">
import { DiffTable } from "@/components/ui/diff-table";

const columns: [string, string, string] = ["Plan", "Billing", "Price"];

const labels = { empty: "Prices already match the plan sheet" };
</script>

<template>
  <DiffTable title="Proposed price changes" :columns="columns" :rows="[]" :labels="labels" />
</template>
```

Svelte · `no-changes.svelte`

```svelte
<script lang="ts">
  import { DiffTable } from "$lib/components/ui/diff-table";

  const columns: [string, string, string] = ["Plan", "Billing", "Price"];

  const labels = { empty: "Prices already match the plan sheet" };
</script>

<DiffTable title="Proposed price changes" columns={columns} rows={[]} labels={labels} />
```

## Recipe

`diff-table.recipe.ts`:

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

/* diff-table — AI-proposed edits in tabular data. Each changed row is the control: click it, or
 * focus its include box and press Enter / Space, to include or exclude that edit before applying.
 * Native table semantics. The include box is the real Checkbox (size md, tone red for a removal,
 * green for an addition, aria-label on its input); the category is a small neutral StatusPill whose
 * dot takes the row's tone; "applied" is a green StatusPill with a mark; Apply is the real Button.
 *
 * The root is a size container with a definite width (380px, or less when its container is
 * narrower), so its width never comes from its content. In a phone-width card (container ≤ 340px)
 * the category column takes a little more and the cells an 8px inset, so a category pill
 * ("Enterprise", "年間契約") is shown whole and a one-word name ("Kubernetes") is not split.
 *
 * The row, cell, value-text and pill parts take the row's state as variants (change, included,
 * toggleable): the adapter knows it, and the rules read in one place.
 *
 * Motion (`docs motion`), all here:
 *   tint     a row's tint and its text colour change at duration.base (colour only)
 *   hover    a layer over the row, instant both ways (the tables' one hover); the press eases
 *   reveal   an added row arrives with the reveal recipe (grid rows 0fr → 1fr at duration.reveal
 *            easing.out-strong, opacity at duration.base), but only once the table has been
 *            painted: data-enter lands on the root after its first paint (lib/paint.ts), so the rows
 *            the table mounts with are simply there. Not a disclosure (no trigger, no open state),
 *            so it is not the collapsible.
 */

/* Spelled out in full below (Tailwind reads whole class names only):
 *   [@container(max-width:340px)]:          the phone-width card
 *   [&_[data-slot=status-pill]]:            the category StatusPill inside a cell
 *   [&>[data-slot=button]]:                 the Apply Button in the footer
 *   [[data-slot=diff-table][data-enter]_&]: inside a painted table only */

export const diffTable = tv({
  slots: {
    base: "@container w-[380px] max-w-full min-w-0",
    card: "relative overflow-hidden rounded-card bg-surface shadow-card",
    bar: "flex min-h-10 items-center justify-between gap-3 px-3 py-2.5 border-b border-line",
    title: "min-w-0 text-dense font-medium leading-[1.3] text-ink wrap-anywhere",
    hint: "shrink-0 text-2xs leading-[1.3] text-ink-2",
    table: "w-full table-fixed border-collapse text-start",
    /* its <col> elements: name · category · value (widths in the col variant) */
    col: "",
    th: [
      "px-3 py-2.5 border-b border-line overflow-hidden text-ellipsis whitespace-nowrap",
      "text-xs font-medium text-start text-ink-2",
      "[@container(max-width:340px)]:px-2",
    ],
    /* tint changes are colour only; --_bg is the row's own fill, which hover and press darken.
     * Toggled from the keyboard (Space on its include box) the row, its text and its pill change at
     * once, like the Checkbox they hold (kbd-instant zeroes only the element it sits on). */
    row: "kbd-instant border-b border-line last:border-b-0 [--_bg:var(--fndn-surface)] bg-(--_bg) motion-colors-base",
    /* the category is a StatusPill; a removal dims it with the row */
    cell: [
      "kbd-instant px-3 py-2.5 text-dense leading-[1.4] align-middle text-ink-2 motion-colors-base",
      "[@container(max-width:340px)]:px-2",
      "[&_[data-slot=status-pill]]:align-middle [&_[data-slot=status-pill]]:motion-opacity-base [&_[data-slot=status-pill]]:kbd-instant",
    ],
    /* an added row's cell content: reveal → clipping child → pad (the cell's padding) */
    reveal: [
      "grid grid-rows-[1fr] opacity-100 [&>*]:min-h-0 [&>*]:overflow-hidden",
      "[[data-slot=diff-table][data-enter]_&]:motion-size-reveal [[data-slot=diff-table][data-enter]_&]:motion-opacity-base",
      "starting:[[data-slot=diff-table][data-enter]_&]:grid-rows-[0fr] starting:[[data-slot=diff-table][data-enter]_&]:opacity-0",
    ],
    pad: "px-3 py-2.5 [@container(max-width:340px)]:px-2",
    /* the value and its include Checkbox */
    value: "flex min-w-0 items-center justify-between gap-2 [&>[data-slot=checkbox]]:shrink-0",
    /* author text keeps its own direction and is cut at its own end; the layout follows the page */
    valueText: [
      "min-w-0 overflow-hidden text-ellipsis whitespace-nowrap",
      "no-underline decoration-[color-mix(in_srgb,var(--fndn-red)_50%,transparent)]",
      "[unicode-bidi:plaintext] [text-align:match-parent]",
    ],
    /* the summary follows the row-level selection; Apply is the real Button */
    footer: [
      "flex min-h-12 items-center justify-between gap-3 py-2.5 ps-3 pe-2.5 border-t border-line",
      "[&>[data-slot=button]]:text-xs [&>[data-slot=button]]:tabular-nums",
    ],
    summary: "min-w-0 [unicode-bidi:plaintext] text-[11.5px] tabular-nums text-ink-2",
    /* the accepted state is rare and final: a green StatusPill with a mark, which pops in once */
    applied: "tabular-nums [unicode-bidi:plaintext]",
    /* no rows: an EmptyState block across the columns */
    empty: "p-0",
  },
  variants: {
    col: {
      name: {
        col: "w-[34%] [@container(max-width:340px)]:w-[32%]",
        cell: "text-sm font-medium tabular-nums text-ink wrap-anywhere [unicode-bidi:plaintext] [text-align:match-parent]",
      },
      category: { col: "w-[30%] [@container(max-width:340px)]:w-[33%]" },
      value: { col: "w-[36%] [@container(max-width:340px)]:w-[35%]" },
    },
    change: {
      removed: {},
      added: { cell: ["p-0 [@container(max-width:340px)]:px-0 text-sm text-ink-3", "[&_[data-slot=status-pill]]:bg-surface"] },
      unchanged: {},
    },
    included: { true: {}, false: {} },
    toggleable: {
      true: {
        row: [
          "cursor-pointer select-none touch-manipulation",
          /* hover: a 4% ink layer over the fill, lit and unlit at once (the tables' one hover); the
           * press darkens the fill beneath it over duration.base, to 7% ink in all
           * (1 - 0.93 / 0.96 = 3.125% under the 4% layer) */
          "hover:[background-image:linear-gradient(color-mix(in_srgb,var(--fndn-ink)_4%,transparent),color-mix(in_srgb,var(--fndn-ink)_4%,transparent))]",
          "active:bg-[color-mix(in_srgb,var(--_bg),var(--fndn-ink)_3.125%)]",
          /* no hover layer without a fine pointer (touch): the press goes the whole 7% itself */
          "[@media_not_((hover:hover)_and_(pointer:fine))]:active:bg-[color-mix(in_srgb,var(--_bg),var(--fndn-ink)_7%)]",
        ],
      },
    },
  },
  compoundVariants: [
    /* removed, included → red tint, red text, struck value, dimmed pill */
    { change: "removed", included: true, class: { row: "[--_bg:var(--fndn-red-tint)]", cell: "text-red", valueText: "line-through" } },
    { change: "removed", included: true, class: { cell: "[&_[data-slot=status-pill]]:opacity-55" } },
    /* added, included → green; added, excluded → muted */
    { change: "added", included: true, class: { row: "[--_bg:var(--fndn-green-tint)]", cell: "text-green" } },
  ],
});

export type DiffTableRecipeProps = VariantProps<typeof diffTable>;
```
