strata-react 1.0.1 → 1.0.3

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
@@ -46,6 +46,8 @@ The last three are optional peers: an app that never imports those entries never
46
46
  dev dependency and builds the package, so it is slow and also needs Node 26.
47
47
  Use it to try a fix before it is released, then move back to the npm version.
48
48
 
49
+ **Updating:** [`UPGRADING.md`](./UPGRADING.md) lists what an app has to change between versions (breaking and test-visible changes only); [`CHANGELOG.md`](./CHANGELOG.md) is the development log.
50
+
49
51
  ## Set up an app
50
52
 
51
53
  ```css
@@ -129,6 +131,8 @@ function KilnRoom() {
129
131
  | Toolbar and toggles | `Toolbar`, `ToolbarSeparator`, `Toggle`, `ToggleGroup`, `Switch` | A toolbar is one tab stop with arrows, Home and End inside; needs a `label`. `Toggle` (`aria-pressed`) and `ToggleGroup` (one of 2 to 7, always one chosen) show chosen as an ink border on a tint, never the filled primary, so they do not break the one-filled-button rule; an icon-only toggle still needs its `label` (shown as a tooltip). `Switch` is only for a setting that applies at once, label and control one target |
130
132
  | Commands | `Command`, `useCommands`, `Menu`, `ContextMenu`, `CommandMenu`, `CommandLegend`, `formatChord`, `matchesChord` | A command is declared once (label or label function, chords, `disabled` with a reason, `destructive`, `checked`) and drives the key handler, dropdown and menu-bar menus, the context menu, the searchable command menu (Mod+K) and the legend, so they cannot disagree. Chords are written once ("Mod+Shift+Z") and shown per platform (⇧⌘Z, Ctrl+Shift+Z); they never fire while typing or during IME composition, and a chord the browser keeps (Ctrl+S) needs `claim: true`. `useHotkeys` is unchanged for single keys |
131
133
  | Overlays | `Dialog`, `DialogProps`, `AlertDialog`, `Popover`, `Tooltip` | React Aria underneath. A dialog always has a title and, via `actions`'s close render prop, a way out; `closable={false}` while work cannot stop; `placement="end"` is a sheet. `AlertDialog` is the only confirm: required verb on the confirm button, Cancel focused first, no outside dismiss, stays open with the reason when an async confirm fails. `Popover` needs a `label`. `Tooltip` opens on hover and focus and `IconButton` uses it. All portal onto the `layer-*` stacking utilities |
134
+ | Value controls | `NumberField`, `Slider`, `ColorField` | Set a number or colour precisely, inside `Field`. `NumberField` and `Slider` are React Aria's; the number field runs with `commitBehavior="validate"`, so a typed value outside `min`/`max` is kept on screen, explained in the `Field` ("Enter a value from 0% to 500%.") and never passed to `onChange`. A value that is not known is `null` and shows an en dash, never 0 or NaN. Digits and decimal mark follow `locale`. The unit sits inside the control, and in the slider's spoken value when `Intl` has it (%, °, ms, s, kB, MB, GB, kbps, Mbps). Arrows step, Home/End jump to the limits; `Slider editable` adds a number field. `ColorField`: platform picker, typed hex that is normalised, app suggestions, and a contrast note against `against`. No motion on value changes |
135
+ | Notices and progress | `Alert`, `toast`, `StrataToastRegion`, `useClientWork`, `JobStatus` | Three weights. A `toast` confirms finished work and goes by itself (5 s plus 40 ms a character, 8 s minimum with an action, paused under the pointer or focus, always dismissable); it has no danger tone, because an error a person must act on is an inline `Alert` with its recovery as `action` (`announce` makes it `role="alert"` only when it answers something the person just did). `StrataToastRegion` goes once at the app root. `useClientWork` runs browser work with progress, cancel (aborts its `signal`, ends `cancelled`, never `failed`) and a double-start guard; `JobStatus` shows it exactly as it shows a server job, with `onCancel`, `cancelled` and `onDismiss` |
132
136
  | 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 |
133
137
  | 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; `format.bytes(n, unit?)` writes sizes in decimal units (`byteUnit` shares one unit across figures); `format.date(at)` ("8 Nov 2026") and `format.dateTime(at)` ("8 Nov 2026, 06:05"), like `clock`, `day` and `shortDay`, take a Date, ISO string or epoch ms; `format.ago(at, now?)` ("3 weeks ago"), `format.compact(n)` ("1.2k", and `count(n, one, many, { compact: true })`), `format.runningTime(seconds)` ("1:02:09") and `format.share(n)` ("<1%" for a part that rounds to 0); every number and date formatter prints the placeholder (`format.missing`, an en dash) for `null` or `undefined`; `createFormat(locale, { timeZone, missing })` fixes the zone and the placeholder; units and counts join with a non-breaking space |
134
138
  | Testing | `strata-react/testing`: `renderWithStrata`, `renderRoutes`, `createTestQueryClient`, `installLayoutShims`, `installFakeIntersectionObserver`, `filledButtons`, `expectOneFilledButton`, `asyncButtonPhase` | Router + query client around Testing Library's `render`; `renderRoutes(routes, { route, basename })` renders the app's own `RouteObject[]` in a memory data router, so layout routes, redirects, loaders and error elements run, and returns the `router` (where a redirect landed is `router.state.location`) and an act-wrapped `navigate`; a fixed box and ResizeObserver so measuring components render in jsdom; an IntersectionObserver the test fires with `scrollToEnd()` or `intersect(el)`; `filledButtons()` and `expectOneFilledButton()` check "one filled button per view" from `data-variant`, and `asyncButtonPhase(el)` reads an `AsyncButton`'s phase. Role names keep the non-breaking space from `format.count`, so match them with the same call or a `\s` regex |
package/UPGRADING.md ADDED
@@ -0,0 +1,60 @@
1
+ # Upgrading strata-react
2
+
3
+ What an app has to change when it updates, newest first. Only things that break, change
4
+ behaviour an app or its tests can see, or need an action. New components and props are not
5
+ listed; the [API reference](https://jburnhams.github.io/strata-react/api/) has them, and the
6
+ full development log, with reasons, is [`CHANGELOG.md`](./CHANGELOG.md).
7
+
8
+ Releases are cut on every merge to `main` (`v0.1.x`), so a day can span several versions.
9
+ Sections are by date; `v0.1.17` was published 2026-11-09 and the Release page gives each tag's
10
+ time. While the version is 0.x, any release may break.
11
+
12
+ Every PR that changes what an app sees adds a line here (see `CLAUDE.md`, "Changelog").
13
+
14
+ ## After v0.1.17 (2026-11-11 to 2026-11-12)
15
+
16
+ React Aria Components is now the primitives layer (`react-aria-components`, installed with the
17
+ package). `@radix-ui/react-slot` is gone.
18
+
19
+ - **`Button` has no `asChild`.** A button that navigates is a link: use a router `Link`.
20
+ Do not rely on `@radix-ui/react-slot` arriving through Strata.
21
+ - **`IconButton` shows `label` as a tooltip**, not a `title` attribute. New optional `hint`
22
+ for a shortcut. `Button` still takes `onClick` and `disabled`; `onPress` also works.
23
+ - **Tests that query roles:** `ChoiceGroup` and `ColorSchemeChoice` are `radiogroup`, not
24
+ `group`. A mixed `Checkbox` is the DOM `indeterminate` state, no longer `aria-checked="mixed"`.
25
+ - **Checkbox, radio and selection tables are drawn from tokens**, not native controls. Expect
26
+ visual baselines to change (selection tables 4px shorter, choice groups 8px taller).
27
+ - **Tooltips and other portalled overlays are now in `strata-visual` shots** (the clip walks
28
+ the other children of `<body>`). Rewrite baselines that included a tooltip trigger.
29
+ - **Visual baselines:** lucide-react 1.72 redrew icons (moon, sort arrows, shell and status
30
+ icons), and the reference Chromium moved to 158 (Playwright 1.65). Re-record, after looking.
31
+ - No app change: TypeScript 7 for the repo's own typecheck, TanStack Table 9 inside `DataTable`
32
+ (its column API is unchanged), new `layer-bar`/`layer-overlay`/`layer-tip` utilities (use them
33
+ instead of writing a z-index).
34
+
35
+ ## v0.1.17 and the days before (2026-11-07 to 2026-11-09)
36
+
37
+ - **`useUndoable`** (2026-11-07): returns `{ pending, failed, isRemoved, schedule, undo, flush,
38
+ retry, dismiss }`. `PendingRemoval` requires a `failure` sentence. `UndoBar` takes
39
+ `undoable={...}` instead of `pending` and `onUndo`. Filter rows with `isRemoved(id)` and drop
40
+ any hand-kept hidden set; `commit` may return a promise, and a rejection restores the item.
41
+ - **Errors read from the response** (2026-11-09): `HttpError` carries `body`, `reason` and
42
+ `fieldErrors`; `describeActionError`/`describeHttpError` now say "The request was refused:
43
+ <reason>." for a 4xx with a reason. Tests asserting the old error sentences need updating.
44
+ `fetchJson` treats a 204 or empty body as success.
45
+ - **`useAsyncAction`** (2026-11-07, 2026-11-09): returns `thrown`, `fieldErrors`,
46
+ `clearFieldError`; takes `onError` and `validate`. Failures no longer disappear silently.
47
+ - **Dark mode:** wrap the app in `ThemeProvider` and delete any `matchMedia` listener; it owns
48
+ the `.dark` class. `colorSchemeScript()` goes in `<head>`.
49
+ - **`strata-react/visual` and `strata-visual`** (2026-11-07): replaces any local Playwright
50
+ script. Every font a screen uses must be bundled (fontsource); text in a system font fails
51
+ the shot. Playwright must be pinned to an exact version. Both images are blurred before
52
+ comparing, so baselines recorded with plain pixelmatch settings may be re-recorded once.
53
+ - **One filled button per view** (2026-11-09): while a `BulkBar` is up, the screen's own
54
+ primary becomes `variant="outline"`. `expectOneFilledButton()` checks it.
55
+ - **`format`** (2026-11-08, 2026-11-09): number formatters are callable
56
+ (`format.integer(n)`; `.format(n)` still works). Missing values print `format.missing` and
57
+ dates accept a `Date` or ISO string. `format.share` prints `<1%` and `>99%` where it used to
58
+ print `0%` and `100%`; `CompositionBar` and `Meter` use it.
59
+ - **Install:** `dist/strata.css` scans the built components, so an app needs no `@source`
60
+ line. Node 26 is the floor (`engines`).
@@ -0,0 +1,17 @@
1
+ import { Tone } from './status';
2
+ import * as React from "react";
3
+ /** Props for `Alert`. */
4
+ export type AlertProps = {
5
+ tone: Exclude<Tone, "neutral">;
6
+ /** A short first line, when the sentence needs one: "Export failed". */
7
+ title?: string;
8
+ /** The sentence, in the product's words: what happened and what to do. */
9
+ children: React.ReactNode;
10
+ /** One recovery, a `Button` ("Try again"). */
11
+ action?: React.ReactNode;
12
+ /** It appeared because of something the person just did (a failed submit): announce it at once (`role="alert"`). */
13
+ announce?: boolean;
14
+ className?: string;
15
+ };
16
+ /** An inline sentence about a problem or a fact, in a tone with an icon, with one optional action. `announce` makes it `role="alert"` for a result of the person's own action. */
17
+ export declare function Alert({ tone, title, children, action, announce, className }: AlertProps): React.JSX.Element;
@@ -1,4 +1,16 @@
1
1
  import * as React from "react";
2
+ type FieldState = {
3
+ id: string;
4
+ label: string;
5
+ describedBy?: string;
6
+ invalid: boolean;
7
+ report: (message: string | undefined) => void;
8
+ };
9
+ /** @internal The surrounding Field, and where a control reports its own message. */
10
+ export declare function useFieldControl(): {
11
+ field: FieldState | null;
12
+ report: (message: string | undefined) => void;
13
+ };
2
14
  export type FieldProps = {
3
15
  label: string;
4
16
  /** The control's id, when the page needs a known one (an anchor, a test). Generated otherwise. */
@@ -34,3 +46,4 @@ export declare function ChoiceGroup({ legend, name, choices, value, onChange, er
34
46
  onChange: (value: string) => void;
35
47
  error?: string;
36
48
  }): React.JSX.Element;
49
+ export {};
@@ -9,7 +9,8 @@ export type JobFailure = {
9
9
  export type JobWords = {
10
10
  running: string;
11
11
  finished: string;
12
- failed: string;
12
+ failed: string; /** Shown when `cancelled`. Default "Cancelled". */
13
+ cancelled?: string;
13
14
  };
14
15
  /** The job status's props. */
15
16
  export type JobStatusProps = {
@@ -30,7 +31,15 @@ export type JobStatusProps = {
30
31
  failed?: boolean;
31
32
  /** Names the list of failures for screen readers. Default "Failures". */
32
33
  failuresLabel?: string;
34
+ /** The person stopped it. A neutral ending, not a failure. */
35
+ cancelled?: boolean;
36
+ /** Stops the job. Shows a Cancel button while it runs. */
37
+ onCancel?: () => void;
38
+ /** Label of the cancel button. Default "Cancel". */
39
+ cancelLabel?: string;
40
+ /** Clears the result. Shows a Dismiss button once the job has ended. */
41
+ onDismiss?: () => void;
33
42
  className?: string;
34
43
  };
35
44
  /** A long-running server job: its state as a required word beside the app's sentence, a progress bar when the total is known, each failure named with its reason, and a polite announcement only when the item changes or the job ends. */
36
- export declare function JobStatus({ label, running, words, summary, current, total, failures, failed, failuresLabel, className, }: JobStatusProps): React.JSX.Element;
45
+ export declare function JobStatus({ label, running, words, summary, current, total, failures, failed, failuresLabel, cancelled, onCancel, cancelLabel, onDismiss, className, }: JobStatusProps): React.JSX.Element;
@@ -0,0 +1,33 @@
1
+ /** What a toast says. */
2
+ export type ToastContentProps = {
3
+ /** What finished, past tense, in the product's words: "Export finished". */
4
+ title: string;
5
+ /** One more sentence: what and where ("run.mp4, 2:31 at 1080p, in your Downloads folder."). */
6
+ description?: string;
7
+ /** `info` by default. There is no danger tone: an error the person must act on is an `Alert`. */
8
+ tone?: "info" | "success" | "warning";
9
+ /** One action beside the words. */
10
+ action?: {
11
+ label: string;
12
+ onPress: () => void;
13
+ };
14
+ /** Milliseconds before it goes. Defaults to enough to read the words. */
15
+ timeout?: number;
16
+ };
17
+ /** Milliseconds a toast stays: 5 s plus 40 ms a character, to at most 15 s, and at least 8 s with an action. */
18
+ export declare function toastTimeout(content: Pick<ToastContentProps, "title" | "description" | "action" | "timeout">): number;
19
+ /** The toast queue: `toast.show({ title })` from anywhere; `toast.close(key)`; `toast.clear()`. */
20
+ export declare const toast: {
21
+ /** Shows a toast and returns its key. */
22
+ show(content: ToastContentProps): string;
23
+ close(key: string): void;
24
+ clear(): void;
25
+ };
26
+ /** Props for `ToastRegion`. */
27
+ export type StrataToastRegionProps = {
28
+ /** Names the landmark. Default "Notifications". */
29
+ label?: string;
30
+ className?: string;
31
+ };
32
+ /** The one place toasts appear. Render it once at the app root. A labelled landmark (F6), polite, above panes and the undo bar. */
33
+ export declare function StrataToastRegion({ label, className }: StrataToastRegionProps): import('react').JSX.Element;
@@ -0,0 +1,72 @@
1
+ import * as React from "react";
2
+ /** Props shared by the number field and the slider. */
3
+ export type RangeProps = {
4
+ min?: number;
5
+ max?: number;
6
+ /** The size of one arrow-key step. Default 1. */
7
+ step?: number;
8
+ /** The unit shown with the value: "%", "°", "Mbps", "px". Spoken too when `Intl` has it (%, °, ms, s, kB, MB, GB, kbps, Mbps). */
9
+ unit?: string;
10
+ /** The locale for digits and the decimal mark. Default the app's `format` locale. */
11
+ locale?: string;
12
+ };
13
+ /** Props for `NumberField`. */
14
+ export type NumberFieldProps = RangeProps & {
15
+ /** The current value; `null` when it is not known (shown as an en dash, not 0). */
16
+ value: number | null;
17
+ /** Receives a number inside the limits, or `null` when the field is cleared. Never NaN, never out of range. */
18
+ onChange: (value: number | null) => void;
19
+ /** Decimal places to show and keep. Default the places in `step` (and `min`). */
20
+ places?: number;
21
+ /** An empty field is an error ("Enter a value.") rather than `null`. */
22
+ required?: boolean;
23
+ disabled?: boolean;
24
+ /** Names the control when it is used without a `Field`. */
25
+ "aria-label"?: string;
26
+ id?: string;
27
+ name?: string;
28
+ className?: string;
29
+ };
30
+ /** A number with a unit on React Aria's number field: typed input is validated, not clamped, so an out-of-range value is explained in the surrounding `Field` and never passed on; empty stays `null`. */
31
+ export declare function NumberField({ value, onChange, min, max, step, places, unit, locale, required, disabled, id: idProp, name, className, "aria-label": ariaLabel, }: NumberFieldProps): React.JSX.Element;
32
+ /** Props for `Slider`. */
33
+ export type SliderProps = RangeProps & {
34
+ value: number;
35
+ onChange: (value: number) => void;
36
+ /** Both limits are required: a slider with no ends is not a slider. */
37
+ min: number;
38
+ max: number;
39
+ /** Replace the printed value with a `NumberField` beside the track, so an exact value can be typed. */
40
+ editable?: boolean;
41
+ /** Hide the printed value (when something else beside it already shows it). */
42
+ hideValue?: boolean;
43
+ /** Decimal places in the printed and spoken value. Default the places in `step`. */
44
+ places?: number;
45
+ disabled?: boolean;
46
+ /** Names the slider when it is used without a `Field`. */
47
+ "aria-label"?: string;
48
+ className?: string;
49
+ };
50
+ /** A slider on React Aria with its current value always printed beside the track (and spoken with the unit when `Intl` knows it); `editable` adds a number field to type an exact value. */
51
+ export declare function Slider({ value, onChange, min, max, step, unit, locale, editable, hideValue, places, disabled, className, "aria-label": ariaLabel, }: SliderProps): React.JSX.Element;
52
+ /** Props for `ColorField`. */
53
+ export type ColorFieldProps = {
54
+ /** `#rrggbb`, or `null` when no colour is set. */
55
+ value: string | null;
56
+ /** Receives a valid `#rrggbb` (lower case) or `null` when cleared; never a half-typed value. */
57
+ onChange: (value: string | null) => void;
58
+ /** A short list the app suggests, as `#rrggbb`. Pressing one chooses it. */
59
+ suggestions?: readonly string[];
60
+ /** The colour this will be drawn on, `#rrggbb`: a note appears when the contrast would be low. */
61
+ against?: string;
62
+ /** What it is drawn on, in words: "the map". Completes the note. */
63
+ againstLabel?: string;
64
+ /** The lowest contrast ratio accepted before the note shows. Default 3, the WCAG minimum for graphics. */
65
+ minContrast?: number;
66
+ disabled?: boolean;
67
+ "aria-label"?: string;
68
+ id?: string;
69
+ className?: string;
70
+ };
71
+ /** Choose a colour with the platform picker, see and type its hex value, pick from the app's suggestions, and get a note when it would be hard to see on `against`. A half-typed value is never passed on. */
72
+ export declare function ColorField({ value, onChange, suggestions, against, againstLabel, minContrast, disabled, id: idProp, className, "aria-label": ariaLabel }: ColorFieldProps): React.JSX.Element;
package/dist/index.d.ts CHANGED
@@ -27,6 +27,10 @@ export { Meter, crossedThreshold, type MeterProps, type MeterThreshold } from '.
27
27
  export { CompositionBar, type CompositionBarProps, type CompositionPart } from './components/composition';
28
28
  export { LinkCard, LinkCardList, type LinkCardProps } from './components/link-card';
29
29
  export { DataView, EmptyState, LoadError, Skeleton, StaleNotice, type Load, type LoadFailure, type Stale } from './components/data-view';
30
+ export { NumberField, Slider, ColorField, type NumberFieldProps, type SliderProps, type ColorFieldProps, type RangeProps } from './components/value-controls';
31
+ export { Alert, type AlertProps } from './components/alert';
32
+ export { toast, toastTimeout, StrataToastRegion, type ToastContentProps, type StrataToastRegionProps } from './components/toast';
33
+ export { useClientWork, type ClientWork, type WorkContext, type WorkPhase } from './lib/client-work';
30
34
  export { JobStatus, type JobStatusProps, type JobFailure, type JobWords } from './components/job-status';
31
35
  export { Thumbnail, ThumbnailSkeleton, type ThumbnailProps, type AspectRatio } from './components/thumbnail';
32
36
  export { DataTable, TableSkeleton, parseSort, serialiseSort, type CellValue, type Column, type Sort, type DataTableProps, type RowSelection, type RowExpansion, } from './components/data-table';