strata-react 0.1.5 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,12 +20,32 @@ Storybook 10 · Playwright Chromium + pixelmatch visual regression · GitHub Act
20
20
 
21
21
  ## Install
22
22
 
23
- Not on npm yet. Install from GitHub (the `prepare` script builds it):
24
-
25
23
  ```bash
26
- npm install github:jburnhams/strata-react react react-dom react-router @tanstack/react-query tailwindcss @tailwindcss/vite
24
+ npm install strata-react react react-dom react-router @tanstack/react-query
25
+ npm install -D tailwindcss @tailwindcss/vite
27
26
  ```
28
27
 
28
+ The npm package is built: nothing runs on install. It needs **Node 26 or later**, for apps as
29
+ well as for this repo; an older Node gets an `EBADENGINE` warning, so upgrade it. Strata's own dependencies
30
+ (TanStack Table and Virtual, class-variance-authority, clsx, tailwind-merge, lucide-react, Radix
31
+ Slot) come with it, so an app does not list them.
32
+
33
+ **Peers.** What an app installs follows from what it imports, and the integration suite checks
34
+ it against the built files:
35
+
36
+ | Import | Needs | Why |
37
+ |---|---|---|
38
+ | `strata-react` | `react`, `react-dom`, `react-router`, `@tanstack/react-query`, `tailwindcss` | The stack is fixed: `DataTable` and `Tabs` keep sort and tab in the URL, `AppShell` links with `NavLink`, every remote read is `useLoad`. The barrel imports both libraries, so an app that uses only a `Button` still installs them (both are needed for anything past a static page) |
39
+ | `strata-react/testing` | the above, plus `@testing-library/react` | `renderWithStrata` wraps Testing Library's `render` |
40
+ | `strata-react/visual`, `strata-visual` | `playwright` (exact version), `msw`, `vite` | The screenshot runner; see [Visual regression for apps](#visual-regression-for-apps) |
41
+
42
+ The last three are optional peers: an app that never imports those entries never needs them.
43
+
44
+ **An unreleased commit** can be installed from GitHub with
45
+ `npm install github:jburnhams/strata-react#<sha>`. npm then runs `prepare`, which installs every
46
+ dev dependency and builds the package, so it is slow and also needs Node 26.
47
+ Use it to try a fix before it is released, then move back to the npm version.
48
+
29
49
  ## Set up an app
30
50
 
31
51
  ```css
@@ -36,6 +56,13 @@ npm install github:jburnhams/strata-react react react-dom react-router @tanstack
36
56
  @import "./theme.css"; /* your status roles, faces and subject colours, with reasons */
37
57
  ```
38
58
 
59
+ No `@source` line for the library is needed. Tailwind's automatic detection skips `node_modules`,
60
+ so `strata.css` names the built components itself (`@source "./*.js"`, relative to the installed
61
+ file), and importing it is enough for every class they use to be generated. The integration suite
62
+ checks this on a copy installed as real files under an app's git-ignored `node_modules`. An app
63
+ that sets `source(none)` on its Tailwind import still gets them, since that turns off only
64
+ automatic detection.
65
+
39
66
  `theme.css` supplies what Strata names but does not choose: `--success`, `--success-subtle`,
40
67
  `--warning…`, `--danger…`, `--info…` (pale tint + dark ink of one hue, ink at least 6:1),
41
68
  `--font-sans` / `--font-display` in an `@theme` block, and optionally `--title-weight`,
@@ -89,20 +116,101 @@ function KilnRoom() {
89
116
 
90
117
  | Group | Exports | Notes |
91
118
  |---|---|---|
92
- | Actions | `Button`, `IconButton`, `AsyncButton`, `useAsyncAction` | Default is `outline`; one filled button per view; `IconButton` requires `label`; `AsyncButton` keeps one width through idle, pending, done and error, and announces `error` with its retry label; `useAsyncAction` returns `{ phase, run, error }` with a stable `run`, and describes an `HttpError` in a sentence (`describeActionError`, or the product's own `describeError`) |
93
- | Form | `Field`, `Input`, `Textarea`, `NativeSelect`, `ChoiceGroup` | `Field` wires label, hint, error, `aria-describedby`, `aria-invalid` |
119
+ | Actions | `Button`, `IconButton`, `RowAction`, `AsyncButton`, `useAsyncAction` | Default is `outline`; one filled button per view; `IconButton` requires `label`; `RowAction` is named for its row ("Withdraw Tom Ellery"); `AsyncButton` keeps one width through idle, pending, done and error, and announces `error` with its retry label; `useAsyncAction` returns `{ phase, run, error }` with a stable `run`, and describes an `HttpError` in a sentence (`describeActionError`, or the product's own `describeError`) |
120
+ | Form | `Field`, `Input`, `Textarea`, `NativeSelect`, `ChoiceGroup`, `Checkbox` | `Field` wires label, hint, error, `aria-describedby`, `aria-invalid`; `Checkbox` requires `label` and is one target with it, and has a mixed state |
94
121
  | Status and figures | `Status`, `Metric`, `MetricStrip` | A status is always a word; figures have no icons or sparklines |
95
- | Data | `DataView`, `Load<T>`, `EmptyState`, `Skeleton`, `DataTable`, `TableSkeleton`, `VirtualList`, `LineChart` | `DataView` requires skeleton and empty; tables and lists virtualise from 100 rows; charts label values directly |
96
- | Data loading | `StrataQueryProvider`, `createQueryClient`, `useLoad`, `toLoad`, `fetchJson`, `HttpError` | TanStack Query in, `Load<T>` out |
122
+ | Data | `DataView`, `Load<T>`, `EmptyState`, `Skeleton`, `DataTable`, `TableSkeleton`, `VirtualList`, `InfiniteList`, `LineChart` | `DataView` requires skeleton and empty; tables and lists virtualise from 100 rows; `InfiniteList` loads the next page on approach, with a skeleton for it, a Try again row when it fails and a Show more button for the keyboard; charts label values directly |
123
+ | Selection | `useSelection`, `BulkBar`, `DataTable`'s `selection` (`RowSelection<T>`) | Opt-in checkbox column with "Select all shown" that respects `isSelectable`; the selection drops rows that are gone; `BulkBar` announces the count politely |
124
+ | Data loading | `StrataQueryProvider`, `createQueryClient`, `useLoad`, `useInfiniteLoad`, `toLoad`, `fetchJson`, `HttpError` | TanStack Query in, `Load<T>` out; `useInfiniteLoad` works out the cursor itself (after the last item held), merges pages by key and can `dismiss` an item at once |
97
125
  | Page and navigation | `AppShell`, `SideNav`, `Breadcrumb`, `Tabs`, `PageHeader` | React Router; tab and sort state in the URL |
126
+ | Keyboard | `useHotkeys`, `KeysLegend`, `Shortcut`, `useActiveItem`, `ActiveList`, `isTypingTarget` | For queues worked from the keyboard; one shortcut list drives the handler and the legend; keys never fire while typing; answering moves focus to the next item |
98
127
  | Theme | `ThemeProvider`, `useColorScheme`, `useSystemColorScheme`, `ColorSchemeChoice`, `colorSchemeScript` | System, light or dark; sets `.dark`, persists in localStorage when it can; no picker beyond the settings-page radio group |
99
- | Feedback | `UndoBar`, `useUndoable`, `Done` | Undo before confirm; `Done` is the one celebration, and it must say what happens next |
128
+ | Feedback | `UndoBar`, `useUndoable`, `Done` | Undo before confirm; the hook owns which rows are out of view (`isRemoved`), a failed commit brings the row back with Try again in the same bar, and `flush()` commits before a dependent action; `Done` is the one celebration, and it must say what happens next |
100
129
  | Helpers | `cn`, `format`, `createFormat`, `NBSP` | `cn` knows `type-*`; all numbers and dates through `Intl`; `format.integer(n)`, `.decimal(n)`, `.percent(n)` are callable and keep Intl's methods; units and counts join with a non-breaking space |
101
130
  | Testing | `strata-react/testing`: `renderWithStrata`, `createTestQueryClient`, `installLayoutShims`, `installFakeIntersectionObserver` | Router + query client around Testing Library's `render`; a fixed box and ResizeObserver so measuring components render in jsdom; an IntersectionObserver the test fires with `scrollToEnd()` or `intersect(el)`. Role names keep the non-breaking space from `format.count`, so match them with the same call or a `\s` regex |
131
+ | Visual regression | `strata-react/visual` and the `strata-visual` command | Screenshots an app's Storybook and its routes in each MSW state, light and dark, against baselines in the app's repo |
102
132
 
103
133
  Specs for the components not built yet (dialogs, sheets, menus, toasts, command menu, prose)
104
134
  are in ux-research `ui-library/components.md`.
105
135
 
136
+ ## Visual regression for apps
137
+
138
+ `strata-visual` is the runner strata-react tests itself with: Playwright Chromium screenshots,
139
+ pixelmatch comparison, light and dark, frozen animations, committed baselines. An app points it at
140
+ its Storybook build, its routes, or both. Route mode is for apps whose screens have no stories:
141
+ each route is taken in each server state, and the state is set by MSW handlers that answer the
142
+ page's requests in Node, so the app needs no test mode and no service worker.
143
+
144
+ ```bash
145
+ npm install -D -E playwright # exact version: the baselines belong to its Chromium
146
+ npx playwright install chromium
147
+ ```
148
+
149
+ ```ts
150
+ // strata-visual.config.ts
151
+ import { defineVisualConfig } from "strata-react/visual";
152
+ import { handlers, queueEmpty, queueError, queueLoading } from "./src/mocks/handlers";
153
+
154
+ export default defineVisualConfig({
155
+ storybook: "storybook-static", // optional: every story, tags as below
156
+ app: {
157
+ dir: "dist", // the production build, served with history fallback
158
+ base: "/", // Vite's base, if the app is built under a path
159
+ handlers, // the healthy server, the same handlers the unit tests use
160
+ viewports: ["wide", "phone"], // 1440×900 and 390×844; "default" is 1024×768
161
+ routes: [
162
+ {
163
+ name: "review",
164
+ path: "/review",
165
+ states: {
166
+ ready: [],
167
+ loading: [queueLoading],
168
+ empty: [queueEmpty],
169
+ error: { handlers: [queueError], waitFor: "role=alert" }, // after the query client's retry
170
+ sorted: { path: "/review?sort=added.desc" }, // URL state is just a path
171
+ },
172
+ },
173
+ {
174
+ name: "settings",
175
+ path: "/settings",
176
+ states: { sync: { setup: (page) => page.getByRole("tab", { name: "Sync" }).click() } },
177
+ },
178
+ ],
179
+ },
180
+ });
181
+ ```
182
+
183
+ ```bash
184
+ vite build && npx strata-visual --update # write baselines into tests/visual/baselines/; commit them
185
+ vite build && npx strata-visual # compare; diffs land in tests/visual/output/
186
+ npx strata-visual --filter review--error # only some shots
187
+ ```
188
+
189
+ Baselines are named `route--state--viewport--theme.png` (`review--empty--phone--dark.png`) and
190
+ stories `story-id--theme.png`. A shot fails when it differs from its baseline (pixelmatch at
191
+ threshold 0.1, anti-aliasing ignored, 20 stray pixels allowed, any size change), when the page
192
+ throws or logs an error, when it makes a request no handler answers, or, in CI, when it has no
193
+ baseline. Story tags pick the viewport: `visual-wide`, `visual-phone`, `no-visual` to skip.
194
+ Pages run in UTC and `en-US`; set `timezone`, `locale` or a frozen `time` in the config.
195
+ Strata's own suite (`strata-visual.config.ts`, with the kiln-room example app in
196
+ `examples/kiln-app/`) is a working reference.
197
+
198
+ In CI, install the pinned Chromium and upload the diffs when it fails:
199
+
200
+ ```yaml
201
+ - run: npm ci
202
+ - run: npx playwright install --with-deps chromium
203
+ - run: npm run build
204
+ - run: npx strata-visual
205
+ - if: failure()
206
+ uses: actions/upload-artifact@v4
207
+ with: { name: visual-diffs, path: tests/visual/output/, if-no-files-found: ignore }
208
+ ```
209
+
210
+ Write the baselines in that same Chromium on Linux (in CI, or in the Playwright Docker image of
211
+ the pinned version): a Mac renders text differently. `--update` records the Chromium and platform
212
+ in `.strata-visual.json`, and a run that differs says so beside its failures.
213
+
106
214
  ## Develop
107
215
 
108
216
  ```bash
@@ -110,7 +218,7 @@ npm install
110
218
  npm run storybook # http://localhost:6006
111
219
  npm test # typecheck + unit tests
112
220
  npm run test:integration # build, then check the package and its CSS as an app sees them
113
- npm run test:visual # screenshot every story (light, dark) and compare with baselines
221
+ npm run test:visual # strata-visual: every story and the example app's route states, light and dark
114
222
  npm run test:visual:update # accept the current screenshots as baselines
115
223
  npm run site # build the docs site into site/
116
224
  ```
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ // strata-visual: screenshot a Storybook build or an app's routes and compare with baselines.
3
+ // The command is src/visual/cli.ts, built into dist/; see strata-visual --help.
4
+ import { main } from "../dist/visual-cli.js";
5
+
6
+ process.exitCode = await main(process.argv.slice(2));
@@ -0,0 +1,46 @@
1
+ import { Shortcut } from './hotkeys';
2
+ import * as React from "react";
3
+ /** What `useActiveItem` returns: the active item, ways to move it, and the props each item element needs. */
4
+ export type ActiveItem<T> = {
5
+ items: readonly T[];
6
+ getKey: (item: T) => string;
7
+ activeKey: string | null;
8
+ activeItem: T | null;
9
+ /** Position of the active item, or -1 when the list is empty. */
10
+ index: number;
11
+ next: () => void;
12
+ prev: () => void;
13
+ first: () => void;
14
+ last: () => void;
15
+ setActive: (key: string) => void;
16
+ /** The j/k shortcuts for `useHotkeys` and `KeysLegend`. */
17
+ shortcuts: Shortcut[];
18
+ /** Props for the element that represents an item: ref, tabIndex, aria-current and focus tracking. */
19
+ itemProps: (key: string) => {
20
+ ref: (el: HTMLElement | null) => void;
21
+ tabIndex: number;
22
+ "aria-current": "true" | undefined;
23
+ "data-active": "" | undefined;
24
+ onFocus: () => void;
25
+ onBlur: (e: React.FocusEvent) => void;
26
+ };
27
+ };
28
+ /** Tracks the active item in a list worked through from the keyboard: moving, roving focus, and moving on when the active item is removed. */
29
+ export declare function useActiveItem<T>(items: readonly T[], getKey: (item: T) => string, { initial, noun, }?: {
30
+ /** Key of the item active at first; the first item otherwise. */
31
+ initial?: string;
32
+ /** Names an item in the shortcut labels: "Next booking". */
33
+ noun?: string;
34
+ }): ActiveItem<T>;
35
+ /** A keyboard-worked queue: the active item is a roving tab stop with aria-current, and the arrow keys, Home and End move it. */
36
+ export declare function ActiveList<T>({ label, active, empty, children, className, }: {
37
+ /** Names the list for screen readers. */
38
+ label: string;
39
+ active: ActiveItem<T>;
40
+ /** Shown when the queue is clear: what that means and what to do next. */
41
+ empty: React.ReactNode;
42
+ children: (item: T, state: {
43
+ active: boolean;
44
+ }) => React.ReactNode;
45
+ className?: string;
46
+ }): React.JSX.Element;
@@ -16,3 +16,12 @@ export type IconButtonProps = Omit<ButtonProps, "size" | "children" | "aria-labe
16
16
  };
17
17
  /** An icon-only button. `label` is required and becomes the accessible name and tooltip. */
18
18
  export declare function IconButton({ icon: Icon, label, variant, ...props }: IconButtonProps): React.JSX.Element;
19
+ export type RowActionProps = Omit<ButtonProps, "children" | "aria-label" | "asChild"> & {
20
+ /** The visible verb, sentence case: "Withdraw", "Remove". */
21
+ label: string;
22
+ /** What the row is, as a person would say it: "Tom Ellery", "Moonbeam". Completes the accessible name. */
23
+ subject: string;
24
+ icon?: IconComponent;
25
+ };
26
+ /** A small ghost action for one table row: shows `label`, and is named "`label` `subject`" so every row's action has its own name. */
27
+ export declare function RowAction({ label, subject, icon: Icon, variant, size, className, ...props }: RowActionProps): React.JSX.Element;
@@ -0,0 +1,14 @@
1
+ import * as React from "react";
2
+ /** A checkbox with its label as one target. `label` is required; `checked="mixed"` is indeterminate. */
3
+ export type CheckboxProps = Omit<React.ComponentProps<"input">, "type" | "checked" | "onChange" | "aria-label" | "children"> & {
4
+ /** Names the checkbox. Shown beside it unless `hideLabel`. */
5
+ label: string;
6
+ /** Keep the label as the accessible name only, for a cell or toolbar where the context shows what it is. */
7
+ hideLabel?: boolean;
8
+ /** A muted second line under a shown label. */
9
+ detail?: string;
10
+ checked: boolean | "mixed";
11
+ onCheckedChange: (checked: boolean) => void;
12
+ };
13
+ /** A native checkbox and its label as one target. `label` is required; `hideLabel` keeps it as the accessible name only. */
14
+ export declare function Checkbox({ label, hideLabel, detail, checked, onCheckedChange, className, disabled, ...props }: CheckboxProps): React.JSX.Element;
@@ -8,8 +8,20 @@ export type Column<T> = {
8
8
  sort?: (a: T, b: T) => number;
9
9
  /** Cells that may hold long text get truncated rather than stretching the table. */
10
10
  truncate?: boolean;
11
+ /** Keep the header for screen readers only, as for a column of row actions. `header` still names it. */
12
+ hideHeader?: boolean;
11
13
  className?: string;
12
14
  };
15
+ /** Row selection for a `DataTable`: the chosen row keys, how to change them, and how to name each row's checkbox. */
16
+ export type RowSelection<T> = {
17
+ /** Keys (from `rowKey`) of the chosen rows. */
18
+ selected: ReadonlySet<string>;
19
+ onChange: (next: Set<string>) => void;
20
+ /** Names the row in its checkbox ("Select <rowLabel>"). Required: an unnamed checkbox is a column of "checkbox, not checked". */
21
+ rowLabel: (row: T) => string;
22
+ /** Rows that cannot be chosen get a disabled checkbox and are left out of select-all. Default: every row. */
23
+ isSelectable?: (row: T) => boolean;
24
+ };
13
25
  export type Sort = {
14
26
  key: string;
15
27
  dir: "ascending" | "descending";
@@ -27,6 +39,8 @@ export type DataTableProps<T> = {
27
39
  virtualizeFrom?: number;
28
40
  /** Height of the scroll region once virtualised, in px. Default 480. */
29
41
  maxHeight?: number;
42
+ /** Adds a checkbox column and "Select all shown". Use only where a `BulkBar` acts on the selection. */
43
+ selection?: RowSelection<T>;
30
44
  className?: string;
31
45
  };
32
46
  /** Reads a sort from its URL form (`pieces.desc`). */
@@ -0,0 +1,29 @@
1
+ import * as React from "react";
2
+ /** One shortcut: the keys that run it (as `KeyboardEvent.key`), what it does in the product's words, and the action. */
3
+ export type Shortcut = {
4
+ /** `KeyboardEvent.key` values, e.g. `["j", "ArrowDown"]`. The first is the one the legend leads with. */
5
+ keys: string[];
6
+ /** What it does, in the product's words: "Accept booking", not "Action 1". */
7
+ label: string;
8
+ run: () => void;
9
+ /** Fire again while the key is held. On for moving through a list, off (the default) for answers. */
10
+ repeat?: boolean;
11
+ /** Ignore the key for now, and show it muted in the legend (nothing is active, say). */
12
+ disabled?: boolean;
13
+ };
14
+ /** True when a key pressed on this element is the person typing, so single-key shortcuts must leave it alone. */
15
+ export declare function isTypingTarget(target: EventTarget | null): boolean;
16
+ /**
17
+ * Binds single-key shortcuts on the window, ignoring keys typed into fields, chords with Ctrl, Meta
18
+ * or Alt, IME composition and (unless `repeat`) held keys. Pass the same list to `KeysLegend`.
19
+ */
20
+ export declare function useHotkeys(shortcuts: Shortcut[] | Record<string, () => void>, { enabled }?: {
21
+ enabled?: boolean;
22
+ }): void;
23
+ /** A quiet legend of the screen's shortcuts, from the same list `useHotkeys` binds. Hidden on touch screens. */
24
+ export declare function KeysLegend({ shortcuts, label, className, }: {
25
+ shortcuts: Pick<Shortcut, "keys" | "label" | "disabled">[];
26
+ /** Names the legend for screen readers. */
27
+ label?: string;
28
+ className?: string;
29
+ }): React.JSX.Element;
@@ -0,0 +1,29 @@
1
+ import { InfiniteLoad } from '../query/infinite';
2
+ import * as React from "react";
3
+ /** The infinite list's props. */
4
+ export type InfiniteListProps<T> = {
5
+ state: InfiniteLoad<T>;
6
+ /** The list's accessible name, e.g. "Firing log, newest first". */
7
+ label: string;
8
+ children: (item: T, index: number) => React.ReactNode;
9
+ /** The first load. Mirrors the final layout, so nothing jumps when data arrives. */
10
+ skeleton: React.ReactNode;
11
+ /** What goes here and how to add it, when the first page is empty and there are no more. */
12
+ empty: React.ReactNode;
13
+ /** The button behind the sentinel, in the product's words: "Show older firings". */
14
+ moreLabel: string;
15
+ /** The rows of a page on its way. Defaults to `skeleton`. */
16
+ moreSkeleton?: React.ReactNode;
17
+ /** After the last page: say that this is everything. */
18
+ end?: React.ReactNode;
19
+ /** How far before the end the next page is asked for (IntersectionObserver `rootMargin`). */
20
+ rootMargin?: string;
21
+ /** Load more whenever fewer than this many items are held. */
22
+ keepAtLeast?: number;
23
+ estimateSize?: number;
24
+ height?: number;
25
+ virtualizeFrom?: number;
26
+ className?: string;
27
+ };
28
+ /** A cursor-paged list for `useInfiniteLoad`: DataView's first-page states, virtual rows, and a next-page row that loads on approach, shows a skeleton, or says why it failed with Try again. */
29
+ export declare function InfiniteList<T>({ state, label, children, skeleton, empty, moreLabel, moreSkeleton, end, rootMargin, keepAtLeast, estimateSize, height, virtualizeFrom, className, }: InfiniteListProps<T>): React.JSX.Element;
@@ -16,7 +16,12 @@ export type LineChartProps = {
16
16
  };
17
17
  formatX: (x: number) => string;
18
18
  formatY: (y: number) => string;
19
+ /** Where to put x labels, in x units. The chart drops every other one (and so on) when they would overlap at its width. */
19
20
  xTicks: number[];
21
+ /** Pin the bottom of the y-axis (default: 0, or lower if a reading is negative). A reading below it still shows. */
22
+ yMin?: number;
23
+ /** Pin the top of the y-axis, for a bounded quantity such as a percentage (`yMax={100}`), so a low reading looks low. Choose a range that divides into four steps. A reading above it still shows. */
24
+ yMax?: number;
20
25
  /** CSS colour for the measured series. Defaults to the first chart token. */
21
26
  colour?: string;
22
27
  /** Colour the measured series by value: each stop applies from `at` upwards, blending to the
@@ -30,7 +35,23 @@ export type LineChartProps = {
30
35
  height?: number;
31
36
  className?: string;
32
37
  };
33
- /** Four gridline steps of a size people write on a scale (1, 2, 2.5, 4 or 5 × 10ⁿ), ending above the max. */
34
- export declare function niceMax(max: number): number;
38
+ /**
39
+ * The y-axis: four equal gridline steps covering every value. With no pins the steps are a size
40
+ * people write on a scale (1, 2, 2.5, 4 or 5 × 10ⁿ), from zero or a round number below the lowest
41
+ * reading. A pinned end is used as given unless a value lies beyond it.
42
+ */
43
+ export declare function yScale(values: number[], pin?: {
44
+ min?: number;
45
+ max?: number;
46
+ }): {
47
+ min: number;
48
+ max: number;
49
+ ticks: number[];
50
+ };
51
+ /**
52
+ * The x ticks that fit at this width: every k-th tick, the smallest k for which neighbouring labels
53
+ * leave a gap, so the spacing stays even. `scale` maps an x value to a pixel.
54
+ */
55
+ export declare function fitTicks(ticks: number[], scale: (x: number) => number, widthOf: (t: number) => number, gap?: number): number[];
35
56
  /** One measured series, drawn in real pixels, with the peak and current readings labelled on the chart and every reading in a screen-reader table. Optional plan, threshold band and `colourScale`. */
36
- export declare function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, formatX, formatY, xTicks, colour, colourScale, colourScaleLabel, height, className, }: LineChartProps): React.JSX.Element;
57
+ export declare function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, formatX, formatY, xTicks, yMin, yMax, colour, colourScale, colourScaleLabel, height, className, }: LineChartProps): React.JSX.Element;
@@ -0,0 +1,22 @@
1
+ import { Format } from '../lib/format';
2
+ import * as React from "react";
3
+ /** Chosen row keys, pruned to the rows that exist, and the calls that change them. Spread into `DataTable`'s `selection` with a `rowLabel`. */
4
+ export declare function useSelection<T>(rows: readonly T[], rowKey: (row: T) => string, initial?: Iterable<string>): {
5
+ selected: ReadonlySet<string>;
6
+ selectedRows: T[];
7
+ count: number;
8
+ onChange: (next: Set<string>) => void;
9
+ clear: () => void;
10
+ };
11
+ /** The bar for a selection: a polite live count ("2 bookings selected"), the bulk actions, and Clear selection. Renders only the live region while nothing is chosen. */
12
+ export declare function BulkBar({ count, noun, onClear, children, format, className, }: {
13
+ count: number;
14
+ /** What is chosen, singular, or singular and plural: `"booking"`, `["person", "people"]`. */
15
+ noun: string | [one: string, many: string];
16
+ onClear: () => void;
17
+ /** The actions. At most one filled button, named with its verb and count. */
18
+ children: React.ReactNode;
19
+ /** The product's formatters, for the count's figures and plural. Default en-GB. */
20
+ format?: Format;
21
+ className?: string;
22
+ }): React.JSX.Element;
@@ -1,20 +1,63 @@
1
1
  import * as React from "react";
2
- /** A removal waiting out its undo window: what to say, and what to do when the window closes. */
2
+ /** A removal waiting out its undo window: what to say, what to do when the window closes, and what to say if that fails. */
3
3
  export type PendingRemoval = {
4
+ /** Identifies the removed item: `isRemoved(id)` is true from `schedule` until Undo or a failed commit. */
4
5
  id: string;
6
+ /** A bulk removal's items, all removed, undone, committed and restored together (one `commit` for the batch). `isRemoved` is true for each. Default `[id]`. */
7
+ ids?: readonly string[];
8
+ /** What happened, in the product's words: "Withdrew Tom Ellery's 3 pieces from kiln 2." */
5
9
  message: string;
6
- commit: () => void;
10
+ /** What the person reads if the commit fails, saying the item is back: "Tom Ellery's 3 pieces are back in kiln 2: the withdrawal did not go through." */
11
+ failure: string;
12
+ /** Makes the removal real (usually a request, then invalidating the query the item came from). Runs once per attempt: when the window closes, on `flush()`, when a second removal is scheduled, or when the owner unmounts. */
13
+ commit: () => void | Promise<unknown>;
14
+ /** Called after a failed commit, for anything beyond restoring the item and showing the failure (which the hook does). The only failure path once the owner has unmounted. */
15
+ onError?: (error: unknown) => void;
7
16
  };
8
- /** Schedules a reversible removal to commit after `windowMs` unless undone. A second removal, or unmounting, commits the pending one. */
9
- export declare function useUndoable(windowMs?: number): {
17
+ /** A removal whose commit failed: the removal, and the error described for a person. */
18
+ export type FailedRemoval = {
19
+ removal: PendingRemoval;
20
+ message?: string;
21
+ };
22
+ /** Options for `useUndoable`. */
23
+ export type UndoableOptions = {
24
+ /** How long Undo stays in reach, in milliseconds. Default 8000. */
25
+ windowMs?: number;
26
+ /** Describes a failed commit for a person, or returns undefined to show the removal's `failure` alone. Default `describeActionError`, as for `useAsyncAction`. */
27
+ describeError?: (error: unknown) => string | undefined;
28
+ };
29
+ /** What `useUndoable` returns. Pass it whole to `UndoBar`. */
30
+ export type Undoable = {
31
+ /** The removal inside its window, or null. */
10
32
  pending: PendingRemoval | null;
33
+ /** The last removal whose commit failed, until it is retried, dismissed or another removal is scheduled. */
34
+ failed: FailedRemoval | null;
35
+ /** Whether an item is out of view: scheduled, committing or committed, and not undone or failed. Filter rows with it. */
36
+ isRemoved: (id: string) => boolean;
37
+ /** Removes an item and starts its window. Commits any removal already pending first: only one is pending at a time. */
11
38
  schedule: (next: PendingRemoval) => void;
39
+ /** Cancels the pending removal and brings the item back; its `commit` never runs. */
12
40
  undo: () => void;
41
+ /** Commits the pending removal now and resolves when it and every earlier commit still in flight have settled; rejects if any failed, so a dependent action does not run. Resolves at once when nothing is pending or running. */
42
+ flush: () => Promise<void>;
43
+ /** Removes the failed item again and commits it now (the person already waited out the window); settles like `flush`. */
44
+ retry: () => Promise<void>;
45
+ /** Clears the failure from the bar; the item stays back. */
46
+ dismiss: () => void;
13
47
  };
14
- /** The polite live region that shows a pending removal with an Undo button. */
15
- export declare function UndoBar({ pending, onUndo, inline, }: {
16
- pending: PendingRemoval | null;
17
- onUndo: () => void;
48
+ /**
49
+ * Schedules a reversible removal to commit after a window unless undone, and owns which items
50
+ * are out of view meanwhile.
51
+ *
52
+ * Only one removal is pending at a time: scheduling a second commits the first immediately.
53
+ * Unmounting inside the window commits the pending removal (leaving is not Undo), so a navigation
54
+ * or a test that unmounts still sends the commit's request: await `flush()` before a dependent
55
+ * action, and in tests let MSW answer the request or flush before unmounting.
56
+ */
57
+ export declare function useUndoable(options?: number | UndoableOptions): Undoable;
58
+ /** The polite live region that shows a pending removal with Undo, or a failed one with Try again. Pass it the whole `useUndoable()` result. */
59
+ export declare function UndoBar({ undoable, inline, }: {
60
+ undoable: Pick<Undoable, "pending" | "failed" | "undo" | "retry" | "dismiss">;
18
61
  /** Render in the flow instead of fixed to the viewport; for the state-matrix page. */
19
62
  inline?: boolean;
20
63
  }): React.JSX.Element;
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  /** A list that renders only its visible rows (TanStack Virtual) from `virtualizeFrom` items, keeping list semantics for screen readers. */
3
- export declare function VirtualList<T>({ label, items, itemKey, children, estimateSize, height, virtualizeFrom, className, }: {
3
+ export declare function VirtualList<T>({ label, items, itemKey, children, estimateSize, height, virtualizeFrom, bounded, footer, className, }: {
4
4
  label: string;
5
5
  items: T[];
6
6
  itemKey: (item: T) => string;
@@ -8,5 +8,9 @@ export declare function VirtualList<T>({ label, items, itemKey, children, estima
8
8
  estimateSize?: number;
9
9
  height?: number;
10
10
  virtualizeFrom?: number;
11
+ /** Scroll inside a region capped at `height` even below `virtualizeFrom`, so growing past it changes nothing on screen. */
12
+ bounded?: boolean;
13
+ /** After the last row, inside the scroll region (a next-page row, an end note). */
14
+ footer?: React.ReactNode;
11
15
  className?: string;
12
16
  }): React.JSX.Element;
package/dist/index.d.ts CHANGED
@@ -8,20 +8,25 @@
8
8
  export { cn, typeSteps } from './lib/utils';
9
9
  export { createFormat, format, NBSP, type Format, type NumberFormatter } from './lib/format';
10
10
  export type { IconComponent } from './lib/icon';
11
- export { Button, IconButton, buttonVariants, type ButtonProps, type IconButtonProps } from './components/button';
11
+ export { Button, IconButton, RowAction, buttonVariants, type ButtonProps, type IconButtonProps, type RowActionProps, } from './components/button';
12
+ export { Checkbox, type CheckboxProps } from './components/checkbox';
12
13
  export { AsyncButton, useAsyncAction, type Phase, type AsyncLabels, type AsyncAction, type AsyncActionOptions } from './components/async-button';
13
14
  export { Field, Input, Textarea, NativeSelect, ChoiceGroup, type FieldProps, type Choice } from './components/field';
14
15
  export { Status, type Tone } from './components/status';
15
16
  export { Metric, MetricStrip, type MetricProps } from './components/metric';
16
17
  export { DataView, EmptyState, Skeleton, type Load } from './components/data-view';
17
- export { DataTable, TableSkeleton, parseSort, serialiseSort, type Column, type Sort, type DataTableProps } from './components/data-table';
18
+ export { DataTable, TableSkeleton, parseSort, serialiseSort, type Column, type Sort, type DataTableProps, type RowSelection, } from './components/data-table';
19
+ export { BulkBar, useSelection } from './components/selection';
18
20
  export { VirtualList } from './components/virtual-list';
21
+ export { InfiniteList, type InfiniteListProps } from './components/infinite-list';
19
22
  export { LineChart, type LineChartProps, type Point } from './components/line-chart';
20
23
  export { PageHeader } from './components/page-header';
21
- export { UndoBar, useUndoable, type PendingRemoval } from './components/undo';
24
+ export { UndoBar, useUndoable, type PendingRemoval, type FailedRemoval, type Undoable, type UndoableOptions, } from './components/undo';
22
25
  export { Done } from './components/done';
23
26
  export { AppShell, SideNav, Breadcrumb, type NavItem } from './components/app-shell';
24
27
  export { Tabs, type TabItem } from './components/tabs';
28
+ export { useHotkeys, KeysLegend, isTypingTarget, type Shortcut } from './components/hotkeys';
29
+ export { useActiveItem, ActiveList, type ActiveItem } from './components/active-list';
25
30
  export { ThemeProvider, useColorScheme, useSystemColorScheme, ColorSchemeChoice, colorSchemeScript, COLOR_SCHEME_STORAGE_KEY, type ColorScheme, type ColorSchemePreference, type ColorSchemeLabels, type ColorSchemeState, } from './components/theme';
26
- export { StrataQueryProvider, createQueryClient, toLoad, useLoad, fetchJson, HttpError, describeHttpError, type DescribeError, } from './query';
31
+ export { StrataQueryProvider, createQueryClient, toLoad, useLoad, useInfiniteLoad, fetchJson, HttpError, describeHttpError, type DescribeError, type InfiniteLoad, type InfiniteLoadOptions, type More, } from './query';
27
32
  export { describeActionError } from './lib/errors';