# Data Grid (Notchset): prompt.md (v1.0.0)

- id: `data-grid` · version 1.0.0 · component · pro (Pro)
- category: Data
- build: Base UI (one set of files; its dependencies follow the build)
- install (this build): `npx shadcn@latest add @beautiful-ui-pro/data-grid`
- npm dependencies: none
- registry dependencies: utils, https://beautiful-ui.dev/r/notchset-foundation.json
- docs: https://beautiful-ui.dev/components/data-grid
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

A spreadsheet surface with sorting, range selection, in-place editing with undo and redo, copy as TSV, CSV export and a status bar that sums the selection.

## Build it
- Stack: React 19 (`ref` is a plain prop), TypeScript, Tailwind CSS v4 utilities, a shadcn-initialised project with the `@/*` alias.
- Packages: none beyond React.
- Files: `components/ui/notchset/data-grid.tsx`; shared code: `lib/beautiful-ui/notchset/instrument.tsx`, `lib/beautiful-ui/notchset/root.ts`, `lib/beautiful-ui/notchset/calendar.tsx`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `notchset-foundation`.
- Builds: one set of files for both, but its dependencies come in Base UI and Radix builds. Install the one that matches the project (see Install): a free item's bare URL installs the Base UI build of it and its dependencies.
- Exports to keep: `DataGrid`, `matchRow`, and every exported type.
- CSS: the install adds the notchset foundation (tokens, keyframes, motion levels) to your global stylesheet once. Nothing to import by hand.
- Re-running `add` (or `--overwrite`) re-applies those rules: put overrides in your own CSS, never in the installed rules.
- Tokens: retheme with the `--notchset-*` custom properties (`--notchset-check`, `--notchset-control-edge`, `--notchset-draw-from`, `--notchset-ease-bloom`, `--notchset-ease-travel`, `--notchset-fade`, `--notchset-focus-color`, `--notchset-focus-inset`, `--notchset-life-from`, `--notchset-life-ms`, `--notchset-node-blink`, `--notchset-node-bloom`, `--notchset-node-delay`, `--notchset-plate-color`, `--notchset-rise-from`, `--notchset-rule`, `--notchset-scroll`, `--notchset-signal`, `--notchset-sweep-to`). Never add Tailwind colour classes inside the component.

```tsx
import { DataGrid, type DataGridColumn } from "@/components/ui/notchset/data-grid";
```

## Parts

| Part | data-slot | What it is for |
|---|---|---|
| `DataGrid` | `data-grid` | The grid. |
| `matchRow` | — | The search rule, for a header count. |

Style a part with `[data-slot="<slot>"]` selectors or its `className`; keep the attributes when editing.

## Sound
- Keep every `data-slot` and `data-sound` attribute: the sound layer reads them.
- Installing this item adds no audio. Nothing plays until the app mounts `SoundProvider` once (install: `npx shadcn@latest add https://beautiful-ui.dev/r/notchset-sound.json`, import from `@/components/ui/notchset/sound-provider`); `useSound()` gives `muted` and `setMuted` for a mute control. Without a provider the audio engine never loads.

## Match the original
- Read `components/ui/notchset/data-grid.tsx` as the reference implementation before changing or recreating anything, and match it: sizes, colours per theme, motion timings, copy and behaviour.
- If you deviate (a prop you can't honour, a style you changed, a dependency you swapped), say so in your reply, part by part.
- Keep the accessibility contract, the keyboard map and the motion levels listed below.

## Use it when
- data grid, spreadsheet, editable table, inline edit, range selection, CSV export, Notchset
- Thousands of rows people edit and select across

### Not when
- Read-only lists: use Data Table

## Mistakes
- Pass stable rowId and derive functions so the view is not rebuilt each render

## Usage

```tsx
"use client";

import { DataGrid, type DataGridColumn } from "@/components/ui/notchset/data-grid";

type EvalCase = { id: string; input: string; score: number; status: string };

const columns: DataGridColumn<EvalCase>[] = [
  { key: "id", label: "CASE", width: 92 },
  { key: "input", label: "INPUT", width: 260, editable: true },
  { key: "score", label: "SCORE", width: 80, type: "number", editable: true, min: 0, max: 100 },
  { key: "status", label: "STATUS", width: 92, dot: (r) => (r.status === "PASS" ? "ink" : "signal") },
];
const cases: EvalCase[] = [
  { id: "pc-0001", input: "Summarise the migration evals", score: 91, status: "PASS" },
  { id: "pc-0002", input: "Find the cheapest model for triage", score: 72, status: "FAIL" },
];
// Stable functions: the grid rebuilds its view when they change.
const rowId = (r: EvalCase) => r.id;
const derive = (r: EvalCase) => ({ ...r, status: r.score >= 80 ? "PASS" : "FAIL" });

export function EvalCases() {
  return <DataGrid columns={columns} rows={cases} rowId={rowId} derive={derive} csvName="cases.csv" />;
}
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `columns` | `{ key, label, width, type?, editable?, min?, max?, format?, muted?, dot? }[]` |  | Columns; the first is sticky. |
| `rows / rowId` | `T[] / (row) => string` |  | Data and identity. |
| `query / derive / csvName` | `string / (row) => row / string` |  | Search, recomputed fields, export name. |

Full docs: https://beautiful-ui.dev/components/data-grid

## Customising
- Colours: the component reads your shadcn tokens (`--background`, `--foreground`, `--border` …), refined by the `--notchset-*` tokens. The signal colour is `--notchset-signal` (it falls back to `--destructive`). Set tokens on `:root`, or on any container to retheme one area.
- Dark mode follows the `.dark` class on an ancestor (the shadcn and next-themes convention).
- Update later by re-running the install with `--overwrite` (review the diff if you edited it). Changelog: https://beautiful-ui.dev/r/changelog.json

## Keyboard

| Keys | Action |
|---|---|
| Arrows / Shift+arrows | Move / extend the selection |
| Enter, F2 or typing | Edit the cell |
| ⌘Z / ⇧⌘Z | Undo / redo |
| ⌘C | Copy the selection as TSV |
| PgUp / PgDn | Change page |

## Performance

- Pages of 50 rows; only visible rows render.

## Responsive

- Scrolls both ways inside a 356px frame.

## Motion inventory

| Interaction | What moves |
|---|---|
| Selection | The 2px box glides between positions (110ms) |

## Accessibility contract (preserve when editing)
- role=grid with row and column indexes, sortable column headers and aria-selected cells

## Install

```bash
npx shadcn@latest add @beautiful-ui-pro/data-grid
```

Pro item: needs the `@beautiful-ui-pro` registry in `components.json` and `BEAUTIFUL_UI_TOKEN` in `.env.local` (https://beautiful-ui.dev/account). Setup: https://beautiful-ui.dev/docs/pro. Your components.json `style` picks the build: radix-*, new-york and default get Radix, base-* gets Base UI.

## Credits
- Built on shadcn/ui (https://ui.shadcn.com)

The notchset foundation (the tokens listed above, keyframes and motion levels) installs once with the first component; its CSS is public at https://beautiful-ui.dev/r/notchset-foundation.json.
