strata-react 1.0.11 → 1.0.15
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 +9 -3
- package/UPGRADING.md +5 -0
- package/dist/components/button.d.ts +6 -3
- package/dist/components/checkbox.d.ts +11 -0
- package/dist/components/data-table.d.ts +1 -1
- package/dist/components/density.d.ts +16 -0
- package/dist/components/field.d.ts +9 -4
- package/dist/components/history.d.ts +61 -0
- package/dist/components/save.d.ts +46 -0
- package/dist/components/selectable-grid.d.ts +1 -1
- package/dist/components/selection.d.ts +1 -0
- package/dist/components/theme.d.ts +7 -1
- package/dist/components/value-controls.d.ts +4 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +800 -430
- package/dist/index.js.map +1 -1
- package/dist/lib/control.d.ts +4 -0
- package/dist/{query-CXlmWmrY.js → query-CIh1Dpgn.js} +43 -11
- package/dist/query-CIh1Dpgn.js.map +1 -0
- package/dist/strata.css +7 -1
- package/dist/testing.js +1 -1
- package/dist/testing.js.map +1 -1
- package/package.json +1 -2
- package/dist/query-CXlmWmrY.js.map +0 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Rules for working in this repo, for people and coding agents: [`CLAUDE.md`](./CL
|
|
|
15
15
|
## The stack
|
|
16
16
|
|
|
17
17
|
Node 26 · React 19 · TypeScript · Vite 8 · Tailwind v4 · class-variance-authority · lucide-react ·
|
|
18
|
-
TanStack Query
|
|
18
|
+
TanStack Query and Table · React Router · Vitest + Testing Library + MSW ·
|
|
19
19
|
Storybook 10 · Playwright Chromium + pixelmatch visual regression · GitHub Actions.
|
|
20
20
|
|
|
21
21
|
## Install
|
|
@@ -27,7 +27,7 @@ npm install -D tailwindcss @tailwindcss/vite
|
|
|
27
27
|
|
|
28
28
|
The npm package is built: nothing runs on install. It needs **Node 26 or later**, for apps as
|
|
29
29
|
well as for this repo; an older Node gets an `EBADENGINE` warning, so upgrade it. Strata's own dependencies
|
|
30
|
-
(React Aria Components, TanStack Table
|
|
30
|
+
(React Aria Components, TanStack Table, class-variance-authority, clsx, tailwind-merge,
|
|
31
31
|
lucide-react) come with it, so an app does not list them.
|
|
32
32
|
|
|
33
33
|
**Peers.** What an app installs follows from what it imports, and the integration suite checks
|
|
@@ -114,6 +114,10 @@ function KilnRoom() {
|
|
|
114
114
|
}
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
+
### Testing with Vitest, or with Jest
|
|
118
|
+
|
|
119
|
+
strata-react is ESM-only (`exports` has only `import`), as is its peer `react-router`. **Vitest is the supported runner**: it needs no configuration beyond the `strata-react/testing` helpers. An app on Jest has to do the work itself (strata-vid's `jest.base.config.js` is a working example): transform `.mjs` along with `.js`; leave `strata-react`, `react-router`, `@remix-run`, `cookie-es`, `@tanstack` and `pixelmatch` out of `transformIgnorePatterns` so Babel compiles them; and replace `import.meta` for CommonJS with a small Babel plugin (react-router reads it). Strata's own suite runs on Vitest only, so a Jest setup is the app's to keep working.
|
|
120
|
+
|
|
117
121
|
## Components
|
|
118
122
|
|
|
119
123
|
| Group | Exports | Notes |
|
|
@@ -121,7 +125,7 @@ function KilnRoom() {
|
|
|
121
125
|
| 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; buttons carry `data-variant` and `AsyncButton` `data-phase` for tests; `useAsyncAction` returns `{ phase, run, error, thrown, fieldErrors, clearFieldError }` with a stable `run`, describes an `HttpError` in a sentence with the server's own reason for a 4xx (`describeActionError`, or the product's own `describeError`), and `validate` plus a server's 422 put messages on `fieldErrors` for each `Field` |
|
|
122
126
|
| Form | `Field`, `Input`, `Textarea`, `NativeSelect`, `ChoiceGroup`, `Checkbox` | `Field` wires label, hint, error, `aria-describedby`, `aria-invalid`, and `action` puts a one-field form's button on the control's row with the hint and error under both; `Checkbox` requires `label` and is one target with it, and has a mixed state |
|
|
123
127
|
| Status and figures | `Status`, `Metric`, `MetricStrip`, `Meter`, `crossedThreshold`, `CompositionBar` | A status is always a word; figures have no icons or sparklines; `Meter` is a `meter` named for what it measures, with its reading in words ("72% used"), threshold notches, and a `Status` word once a threshold is crossed (each threshold must name its state); `CompositionBar` is a stacked bar over a table naming every part, its amount and share, and names the remainder (`total` needs `restLabel`); a part that is there reads "<1%" and keeps a sliver, never "0%"; `JobStatus` is a long-running server job: a required word per state beside the app's sentence, a progress bar when the total is known, each failure named with its reason, announced only when the item changes or the job ends |
|
|
124
|
-
| Data | `DataView`, `Load<T>`, `Stale`, `StaleNotice`, `LoadError`, `EmptyState`, `Skeleton`, `Thumbnail`, `ThumbnailSkeleton`, `DataTable`, `TableSkeleton`, `VirtualList`, `InfiniteList`, `LoadMore`, `useInView`, `LineChart` | `DataView` requires skeleton and empty, keeps data on screen under a `StaleNotice` (why, how old, Try again) when a refresh fails, and takes an `error` renderer for an app's own look of a failed read (default `LoadError`, always inside an alert); `Thumbnail` is a remote image in a box of fixed `aspect`, with a skeleton while it loads, the required `missing` words (or a `fallback` drawing, such as an avatar's initial) when it fails or `src` is null, required `alt`, `children` overlaid in its corners, and a request only once it nears the screen (`eager` for the first few); tables and
|
|
128
|
+
| Data | `DataView`, `Load<T>`, `Stale`, `StaleNotice`, `LoadError`, `EmptyState`, `Skeleton`, `Thumbnail`, `ThumbnailSkeleton`, `DataTable`, `TableSkeleton`, `VirtualList`, `InfiniteList`, `LoadMore`, `useInView`, `LineChart` | `DataView` requires skeleton and empty, keeps data on screen under a `StaleNotice` (why, how old, Try again) when a refresh fails, and takes an `error` renderer for an app's own look of a failed read (default `LoadError`, always inside an alert); `Thumbnail` is a remote image in a box of fixed `aspect`, with a skeleton while it loads, the required `missing` words (or a `fallback` drawing, such as an avatar's initial) when it fails or `src` is null, required `alt`, `children` overlaid in its corners, and a request only once it nears the screen (`eager` for the first few); tables, lists and tile grids virtualise from 100 rows, on React Aria's Virtualizer; a `DataTable` is a React Aria table (a `grid`) over TanStack Table's data model; a `DataTable` column with `value` sorts by type with missing values last both ways and draws a placeholder (`missing`, default an en dash); `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, and `scroll="page"` draws a grid that scrolls with the page; `LoadMore` is that next-page row for any list or grid; charts label values directly; `LineChart` can also follow an app's position (`current`), read a value at the pointer or by arrow keys (`readout`, one slider whose value text is the reading), report a picked x (`onPick`) and fill one flat area (`area`) |
|
|
125
129
|
| Compare | `Compare`, `CompareGrid`, `ViewportFrame`, `useViewport`, `FullscreenFrame`, `useDifference`, `differences` | Two pictures judged together: side by side, swipe (a divider that moves from the keyboard), fade, blink (`x` flips) and difference (a live difference blend with amplify, or pixelmatch's changed pixels with a tolerance and the share that differ; pixels are read only when that view is open, at most 2048 px on the long side, and a picture the browser will not let the page read says so in words); `CompareGrid` is every candidate at once with the same zoom and full screen, and `actions` for what a tile offers; one zoom and pan for both sides (buttons, `+` `-` `0`, Ctrl-wheel or trackpad pinch, drag, arrow keys, double click, `1:1`), and full screen (the browser's Fullscreen API, a modal where there is none). `blind` is required: a blind comparison names pictures by `label` only and never writes the variant `id`, `note` or `alt`. A picture that fails shows the required `missing` words in its place; the keys come from one `Shortcut[]` shared with `KeysLegend`, and `keys={false}` leaves them to a surrounding screen. Pictures only so far: voting, text, audio and video are the next changes |
|
|
126
130
|
| Selection | `useSelection`, `BulkBar`, `SelectableGrid`, `DataTable`'s `selection` (`RowSelection<T>`) | Opt-in checkbox column with "Select all shown" that respects `isSelectable`; Shift-click or Shift+Space chooses or clears the run from the last row clicked, in the order shown; `initial` (keys or a test on the row) chooses a row the first time it appears, so it applies to data that loads later; the selection drops rows that are gone; `BulkBar` announces the count politely, and while it is up its one filled action is the view's only one (the screen's primary goes to `outline`); `SelectableGrid` is the same selection as a grid of pictures (`renderImage`), each tile one labelled target, virtualised from 100 tiles |
|
|
127
131
|
| Expansion | `Disclosure`, `useExpanded`, `DataTable`'s `expansion` (`RowExpansion<T>`) | Show more of one row in place. The toggle is a button with `aria-expanded`; the body is mounted only while open, so a request inside it runs on first open (unlike `<details>`, which mounts every closed body); `useExpanded({ param })` shares the open keys across a list or table and keeps them in the URL; a table's detail row spans the data columns and is measured when virtualised |
|
|
@@ -129,6 +133,8 @@ function KilnRoom() {
|
|
|
129
133
|
| Page and navigation | `AppShell`, `SideNav`, `Breadcrumb`, `Tabs`, `PageHeader`, `LinkCard`, `LinkCardList` | React Router; tab and sort state in the URL; a `LinkCard` is one link named by its title, described by its text and `Status` marks, with the whole card as the target (`to` a route, `href` elsewhere, marked with an arrow) |
|
|
130
134
|
| 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 |
|
|
131
135
|
| Theme | `ThemeProvider`, `useColorScheme`, `useSystemColorScheme`, `ColorSchemeChoice`, `colorSchemeScript` | System, light or dark; sets `.dark`, persists in localStorage when it can; `ColorSchemeChoice` is a radio list for a settings page, or `compact` icon segments named "Appearance" for an app with no settings page |
|
|
136
|
+
| Density | `Density`, `DensityName`, `ThemeProvider`'s `density`, `ControlSize` (`size="sm"` on `Input`, `NativeSelect`, `NumberField`, `IconButton`) | Control height is two variables, `--control-h` and `--control-h-sm`. `<ThemeProvider density="compact">` or `<Density page value="compact">` sets them app-wide, including dialogs and menus, which portal out of the app's root; `<Density value="compact">` is one region (a toolbar, a dense panel) and does not reach its overlays. A coarse pointer (touch) always gets 44px targets, whatever the density |
|
|
137
|
+
| History and save state | `useHistory`, `useHistoryState`, `History`, `useAutoSave`, `SaveStatus`, `SaveState`, `useLeaveGuard` | Undo and redo for a document edited over a session: a step is a name and an `undo`/`redo` pair, `begin(label)` groups a drag into one step, a `key` merges a slider's pushes, a `limit` drops the oldest. `history.commands` are Undo and Redo as `Command`s ("Undo move clip", Mod+Z, Mod+Shift+Z or Mod+Y) for `useCommands` and `Menu`. `useAutoSave` debounces and never overlaps saves; `SaveStatus` is the fixed-width sign ("Saved 10:42", "Saving…", "Unsaved changes", "Not saved" with the reason and "Try again"), quiet except for a failure and its recovery. For one removal that commits after a few seconds, use `useUndoable` |
|
|
132
138
|
| 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 |
|
|
133
139
|
| 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 |
|
|
134
140
|
| 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 |
|
package/UPGRADING.md
CHANGED
|
@@ -16,6 +16,11 @@ Every PR that changes what an app sees adds a line here (see `CLAUDE.md`, "Chang
|
|
|
16
16
|
React Aria Components is now the primitives layer (`react-aria-components`, installed with the
|
|
17
17
|
package). `@radix-ui/react-slot` is gone.
|
|
18
18
|
|
|
19
|
+
- **`Input` and `NativeSelect` take `size="default" | "sm"`**, not the native numeric `size` attribute (it is no longer passed through). Their height comes from `--control-h` / `--control-h-sm`, so a root `data-density` changes them, as it does `Button`. `NumberField`'s box lost its fixed height for the same reason; its visual baselines may move by a pixel.
|
|
20
|
+
- **A `ColorField` inside a `Field` has its picker named after the field** ("Route colour, picker"), not "Colour picker"; query it by that name. A `Dialog` or `AlertDialog` with `open` and no `trigger` no longer renders a `DialogTrigger`.
|
|
21
|
+
- **`DataTable` is a `grid`**, not a `table`: query `getByRole("grid", { name: caption })`, cells as `gridcell` and the first column's cells as `rowheader` (React Aria requires a row header; it is the first column). A sortable header is the `columnheader` itself, with no inner `button`: click it, and `aria-sort` is `"none"` until sorted. The `region` that wrapped a table is gone, and a toggle has no `aria-controls`. A click on a cell no longer touches the selection: only the checkbox or Space chooses a row. A part-chosen "Select all shown" still clears. Virtualised tables (100+ rows) size columns evenly rather than to their content. In a jsdom test of a virtualised table with `expansion`, or of a `SelectableGrid` of 100+ tiles, set `Element.prototype.scrollHeight` (the Virtualizer measures rows by it).
|
|
22
|
+
- **`SelectableGrid` is a `grid` of `row`s** (was a `list` of `listitem`s, a `region` once virtualised): query `getByRole("grid", { name: label })`; a press anywhere on a tile toggles it as before, and Shift-click, Shift+Space and "Select all shown" still extend and clear. Virtualised tiles keep a margin of one gap around the box.
|
|
23
|
+
- **`@tanstack/react-virtual` is no longer a dependency.** Strata does not need it; if an app imported it through Strata, add it itself.
|
|
19
24
|
- **`VirtualList` and `InfiniteList` (region mode) are a `grid` of `row`s**, not a `list` of `listitem`s in a `region`: query `getByRole("grid", { name })` and count items with `[data-index]` (the next-page row is a row too). Arrow keys move between rows. New `rowHeight` prop for fixed-height rows. `scroll="page"` is unchanged.
|
|
20
25
|
- **State classes are the `tailwindcss-react-aria-components` variants** (`selected:`, `focus-visible:`, `hover:`, `disabled:`), loaded by `strata.css` (the plugin is installed with the package). A test that matched a class such as `data-[selected]:border-foreground` now matches `selected:border-foreground`; hover colours no longer apply on touch screens.
|
|
21
26
|
- **`Compare`'s default view switch has a fifth view, `difference`** (key `5`). An app that renders `Compare` without `modes` sees one more toggle (and its visual baselines move); pass `modes={["side", "swipe", "fade", "blink"]}` to keep the previous four.
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { PressEvent } from 'react-aria-components';
|
|
2
2
|
import { VariantProps } from 'class-variance-authority';
|
|
3
3
|
import { IconComponent } from '../lib/icon';
|
|
4
|
+
import { ControlSize } from '../lib/control';
|
|
4
5
|
import * as React from "react";
|
|
5
6
|
export declare const buttonVariants: (props?: ({
|
|
6
7
|
variant?: "link" | "default" | "outline" | "secondary" | "ghost" | "destructive" | null | undefined;
|
|
7
|
-
size?: "default" | "sm" | "icon" | null | undefined;
|
|
8
|
+
size?: "default" | "sm" | "icon" | "icon-sm" | null | undefined;
|
|
8
9
|
} & import('class-variance-authority/types').ClassProp) | undefined) => string;
|
|
9
10
|
export type ButtonProps = Omit<React.ComponentProps<"button">, "className" | "style"> & VariantProps<typeof buttonVariants> & {
|
|
10
11
|
className?: string;
|
|
@@ -17,15 +18,17 @@ export type ButtonProps = Omit<React.ComponentProps<"button">, "className" | "st
|
|
|
17
18
|
* `outline`; ask for the filled accent (`variant="default"`) once per view. `type` defaults to `button`.
|
|
18
19
|
* `onClick` and `disabled` are the DOM names and keep working; `onPress` is also accepted.
|
|
19
20
|
*/
|
|
20
|
-
export declare function Button({ className, variant, size, type, disabled, ...props }: ButtonProps): React.JSX.Element;
|
|
21
|
+
export declare function Button({ className, variant, size, type, disabled, children, ...props }: ButtonProps): React.JSX.Element;
|
|
21
22
|
export type IconButtonProps = Omit<ButtonProps, "size" | "children" | "aria-label"> & {
|
|
23
|
+
/** `sm` is --control-h-sm, the height of a small `Toggle` or `Button`, for a toolbar or property row. Default --control-h. */
|
|
24
|
+
size?: ControlSize;
|
|
22
25
|
icon: IconComponent;
|
|
23
26
|
label: string;
|
|
24
27
|
/** Shown after the label in its tooltip, muted: "Ctrl+Z". */
|
|
25
28
|
hint?: React.ReactNode;
|
|
26
29
|
};
|
|
27
30
|
/** An icon-only button. `label` is required and becomes the accessible name and the tooltip (hover and keyboard focus); `hint` adds a muted aside to it, such as a shortcut. */
|
|
28
|
-
export declare function IconButton({ icon: Icon, label, hint, variant, ...props }: IconButtonProps): React.JSX.Element;
|
|
31
|
+
export declare function IconButton({ icon: Icon, label, hint, variant, size, ...props }: IconButtonProps): React.JSX.Element;
|
|
29
32
|
export type RowActionProps = Omit<ButtonProps, "children" | "aria-label"> & {
|
|
30
33
|
/** The visible verb, sentence case: "Withdraw", "Remove". */
|
|
31
34
|
label: string;
|
|
@@ -25,3 +25,14 @@ export declare function useShiftNote(): {
|
|
|
25
25
|
};
|
|
26
26
|
take: () => CheckboxGesture;
|
|
27
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* The checkbox of a React Aria `Table` row or header (`slot="selection"`): its checked, mixed and
|
|
30
|
+
* disabled state come from the table, so it takes only a name. A `Checkbox` is controlled and would
|
|
31
|
+
* fight the table's own selection state. Not exported from the package: `DataTable` uses it.
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
export declare function TableSelectionCheckbox({ label, className, disabled }: {
|
|
35
|
+
label: string;
|
|
36
|
+
className?: string;
|
|
37
|
+
disabled?: boolean;
|
|
38
|
+
}): React.JSX.Element;
|
|
@@ -74,7 +74,7 @@ export type DataTableProps<T> = {
|
|
|
74
74
|
export declare function parseSort(value: string | null): Sort | undefined;
|
|
75
75
|
/** Writes a sort in its URL form (`pieces.desc`). */
|
|
76
76
|
export declare function serialiseSort(sort: Sort): string;
|
|
77
|
-
/** A table on TanStack Table: muted headers, row rules, right-aligned tabular numbers, sortable headers with `aria-sort`, virtualised from `virtualizeFrom` rows, sort optionally kept in the URL (`sortParam`). */
|
|
77
|
+
/** A table on React Aria's Table with TanStack Table's data model: muted headers, row rules, right-aligned tabular numbers, sortable headers with `aria-sort`, virtualised from `virtualizeFrom` rows, sort optionally kept in the URL (`sortParam`). */
|
|
78
78
|
export declare function DataTable<T>(props: DataTableProps<T>): React.JSX.Element;
|
|
79
79
|
/** The loading placeholder for a `DataTable`, shaped like its rows. */
|
|
80
80
|
export declare function TableSkeleton({ rows, columns }: {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/** How much a screen packs in: `default`, or `compact` for a tool screen. */
|
|
3
|
+
export type DensityName = "default" | "compact";
|
|
4
|
+
/** The density attribute's page-level setter, shared by `ThemeProvider`. @internal */
|
|
5
|
+
export declare function useDensityOn(value: DensityName | undefined, target?: HTMLElement | null): void;
|
|
6
|
+
/** Props for `Density`. */
|
|
7
|
+
export type DensityProps = {
|
|
8
|
+
value: DensityName;
|
|
9
|
+
/** Set it on the document's root element for the whole page, overlays included, instead of wrapping a region. Renders only its children. */
|
|
10
|
+
page?: boolean;
|
|
11
|
+
/** For the wrapper of a region: layout classes (the wrapper is a plain `div`; `contents` takes it out of layout). */
|
|
12
|
+
className?: string;
|
|
13
|
+
children?: React.ReactNode;
|
|
14
|
+
};
|
|
15
|
+
/** Sets the density of a region (a wrapper `div`), or of the whole page with `page`, where overlays are reached too. */
|
|
16
|
+
export declare function Density({ value, page, className, children }: DensityProps): React.JSX.Element;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ControlSize } from '../lib/control';
|
|
1
2
|
import * as React from "react";
|
|
2
3
|
type FieldState = {
|
|
3
4
|
id: string;
|
|
@@ -26,12 +27,16 @@ export type FieldProps = {
|
|
|
26
27
|
};
|
|
27
28
|
/** A labelled form field: wires the label, hint, error, `aria-describedby` and `aria-invalid` into the one control it wraps. */
|
|
28
29
|
export declare function Field({ label, id: idProp, hint, error, action, children, className }: FieldProps): React.JSX.Element;
|
|
29
|
-
/** A text input that picks up its id and descriptions from the surrounding `Field`. */
|
|
30
|
-
export declare function Input({ className, id, ...props }: React.ComponentProps<"input">
|
|
30
|
+
/** A text input that picks up its id and descriptions from the surrounding `Field`. `size="sm"` is --control-h-sm; the native `size` (a width in characters) is not passed on. */
|
|
31
|
+
export declare function Input({ className, id, size, ...props }: Omit<React.ComponentProps<"input">, "size"> & {
|
|
32
|
+
size?: ControlSize;
|
|
33
|
+
}): React.JSX.Element;
|
|
31
34
|
/** A multi-line input that picks up its id and descriptions from the surrounding `Field`. */
|
|
32
35
|
export declare function Textarea({ className, id, ...props }: React.ComponentProps<"textarea">): React.JSX.Element;
|
|
33
|
-
/** The platform select, styled. The default for short lists, especially on touch screens. */
|
|
34
|
-
export declare function NativeSelect({ className, id, ...props }: React.ComponentProps<"select">
|
|
36
|
+
/** The platform select, styled. The default for short lists, especially on touch screens. `size="sm"` is --control-h-sm. */
|
|
37
|
+
export declare function NativeSelect({ className, id, size, ...props }: Omit<React.ComponentProps<"select">, "size"> & {
|
|
38
|
+
size?: ControlSize;
|
|
39
|
+
}): React.JSX.Element;
|
|
35
40
|
export type Choice = {
|
|
36
41
|
value: string;
|
|
37
42
|
label: string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Command } from './commands';
|
|
2
|
+
/** One undoable step. `label` is the phrase after the verb ("move clip"); `undo` and `redo` must be inverses. */
|
|
3
|
+
export type HistoryStep = {
|
|
4
|
+
label: string;
|
|
5
|
+
undo: () => void;
|
|
6
|
+
redo: () => void;
|
|
7
|
+
/** Consecutive pushes with the same key merge into one step (a slider, a text drag). */
|
|
8
|
+
key?: string;
|
|
9
|
+
};
|
|
10
|
+
/** Options for `useHistory`. */
|
|
11
|
+
export type HistoryOptions = {
|
|
12
|
+
/** The most steps kept; the oldest is dropped past it. Default 100. */
|
|
13
|
+
limit?: number;
|
|
14
|
+
};
|
|
15
|
+
/** What `useHistory` returns. */
|
|
16
|
+
export type History = {
|
|
17
|
+
/** Records a step the app has just done. Clears what could have been redone. Inside `begin`/`end` it joins the group. */
|
|
18
|
+
push: (step: HistoryStep) => void;
|
|
19
|
+
/** Starts a group named `label`; every push until the returned `end()` is one step. Nested groups join the outer one. An empty group records nothing. */
|
|
20
|
+
begin: (label: string) => () => void;
|
|
21
|
+
/** `begin`, run a function, `end`. */
|
|
22
|
+
group: <T>(label: string, run: () => T) => T;
|
|
23
|
+
undo: () => void;
|
|
24
|
+
redo: () => void;
|
|
25
|
+
canUndo: boolean;
|
|
26
|
+
canRedo: boolean;
|
|
27
|
+
/** The name of the step Undo would take back, or undefined. */
|
|
28
|
+
undoLabel: string | undefined;
|
|
29
|
+
/** The name of the step Redo would repeat, or undefined. */
|
|
30
|
+
redoLabel: string | undefined;
|
|
31
|
+
/** Names of the steps that can be undone, oldest first. */
|
|
32
|
+
past: string[];
|
|
33
|
+
/** Names of the steps that can be redone, next first. */
|
|
34
|
+
future: string[];
|
|
35
|
+
/** The history holds `limit` steps, so the next push drops the oldest. */
|
|
36
|
+
atLimit: boolean;
|
|
37
|
+
/** Forgets every step (a document was opened or saved to a new place). */
|
|
38
|
+
clear: () => void;
|
|
39
|
+
/** Undo then Redo as commands: "Undo move clip", disabled with "Nothing to undo". Pass to `useCommands` and a `Menu`. */
|
|
40
|
+
commands: [undo: Command, redo: Command];
|
|
41
|
+
};
|
|
42
|
+
/** A history of named, undoable steps with grouping, a limit, and Undo and Redo as commands. */
|
|
43
|
+
export declare function useHistory({ limit }?: HistoryOptions): History;
|
|
44
|
+
/** Options for `useHistoryState`. */
|
|
45
|
+
export type HistoryStateOptions = HistoryOptions;
|
|
46
|
+
/** What `setValue` takes besides the new value. */
|
|
47
|
+
export type SetOptions = {
|
|
48
|
+
/** Merges consecutive changes with this key into one step (a slider, a drag). */
|
|
49
|
+
key?: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* React state with a history: `set(next, "move clip")` changes the value and records the step; Undo
|
|
53
|
+
* and Redo put the old and new values back. For an app whose document is a plain value. An app on its
|
|
54
|
+
* own store uses `useHistory` and pushes steps from its actions.
|
|
55
|
+
*/
|
|
56
|
+
export declare function useHistoryState<S>(initial: S | (() => S), options?: HistoryStateOptions): {
|
|
57
|
+
value: S;
|
|
58
|
+
set: (next: S | ((previous: S) => S), label: string, { key }?: SetOptions) => void;
|
|
59
|
+
reset: (next: S) => void;
|
|
60
|
+
history: History;
|
|
61
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/** The state of a document's saving. */
|
|
3
|
+
export type SaveState = {
|
|
4
|
+
status: "saved"; /** When it last saved here; null for a document just opened. */
|
|
5
|
+
at: Date | null;
|
|
6
|
+
} | {
|
|
7
|
+
status: "dirty";
|
|
8
|
+
} | {
|
|
9
|
+
status: "saving";
|
|
10
|
+
} | {
|
|
11
|
+
status: "failed"; /** What happened, in the product's words. */
|
|
12
|
+
reason?: string;
|
|
13
|
+
};
|
|
14
|
+
/** Options for `useAutoSave`. */
|
|
15
|
+
export type AutoSaveOptions<V> = {
|
|
16
|
+
/** The document's current value. Compared with what was last saved by `equals`. */
|
|
17
|
+
value: V;
|
|
18
|
+
/** Saves a value. Throw (or reject) to fail. */
|
|
19
|
+
save: (value: V) => void | Promise<unknown>;
|
|
20
|
+
/** Wait this long after the last change before saving. `null`: never on its own, only `saveNow()`. Default 1500. */
|
|
21
|
+
delayMs?: number | null;
|
|
22
|
+
/** Whether two values are the same document. Default `Object.is`. */
|
|
23
|
+
equals?: (a: V, b: V) => boolean;
|
|
24
|
+
/** Turns a thrown error into the sentence shown. Default `describeActionError`. */
|
|
25
|
+
describeError?: (error: unknown) => string | undefined;
|
|
26
|
+
};
|
|
27
|
+
/** What `useAutoSave` returns. */
|
|
28
|
+
export type AutoSave = {
|
|
29
|
+
state: SaveState;
|
|
30
|
+
/** Saves now (and is "Try again" after a failure). Resolves when the save has finished, failed or not. */
|
|
31
|
+
saveNow: () => Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
/** Saves `value` after changes settle, never two at once, and says where it stands. The document's first `value` counts as saved. */
|
|
34
|
+
export declare function useAutoSave<V>({ value, save, delayMs, equals, describeError }: AutoSaveOptions<V>): AutoSave;
|
|
35
|
+
/** Asks the browser to confirm before the page is closed or reloaded, while `active`. Off when there is nothing to lose. */
|
|
36
|
+
export declare function useLeaveGuard(active: boolean): void;
|
|
37
|
+
/**
|
|
38
|
+
* The sign of whether the work is safe: "Saved 10:42", "Saving…", "Unsaved changes", or "Not saved"
|
|
39
|
+
* with the reason and "Try again". Fixed width, so it never moves what is beside it. Announces a
|
|
40
|
+
* failure, and the recovery from one, politely; a routine save is silent.
|
|
41
|
+
*/
|
|
42
|
+
export declare function SaveStatus({ state, onRetry, className }: {
|
|
43
|
+
state: SaveState;
|
|
44
|
+
onRetry: () => void;
|
|
45
|
+
className?: string;
|
|
46
|
+
}): React.JSX.Element;
|
|
@@ -5,7 +5,7 @@ export type TileAspect = "square" | "portrait" | "landscape";
|
|
|
5
5
|
/** Smallest tile width: `sm` 96px (dense crops), `md` 144px, `lg` 192px. Tiles grow to fill the row. */
|
|
6
6
|
export type TileSize = "sm" | "md" | "lg";
|
|
7
7
|
export type SelectableGridProps<T> = {
|
|
8
|
-
/** Names the
|
|
8
|
+
/** Names the grid of tiles. */
|
|
9
9
|
label: string;
|
|
10
10
|
rows: T[];
|
|
11
11
|
rowKey: (row: T) => string;
|
|
@@ -38,6 +38,7 @@ export declare function useSelectRows<T>(rows: readonly T[], rowKey: (row: T) =>
|
|
|
38
38
|
toggle: (key: string, on: boolean, { shiftKey }: {
|
|
39
39
|
shiftKey: boolean;
|
|
40
40
|
}) => void;
|
|
41
|
+
setAnchor: (key: string | null) => void;
|
|
41
42
|
all: {
|
|
42
43
|
checked: boolean | "mixed";
|
|
43
44
|
toggle: () => void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DensityName } from './density';
|
|
1
2
|
import * as React from "react";
|
|
2
3
|
/** What a person chose: follow the operating system, or a fixed light or dark theme. */
|
|
3
4
|
export type ColorSchemePreference = "system" | "light" | "dark";
|
|
@@ -14,7 +15,7 @@ export type ColorSchemeState = {
|
|
|
14
15
|
setPreference: (preference: ColorSchemePreference) => void;
|
|
15
16
|
};
|
|
16
17
|
/** Sets the `.dark` class strata.css keys on, from a system, light or dark preference that persists in localStorage when it can. */
|
|
17
|
-
export declare function ThemeProvider({ children, defaultPreference, storageKey, target, }: {
|
|
18
|
+
export declare function ThemeProvider({ children, defaultPreference, storageKey, target, density, }: {
|
|
18
19
|
children: React.ReactNode;
|
|
19
20
|
/** The preference before a person has chosen one. */
|
|
20
21
|
defaultPreference?: ColorSchemePreference;
|
|
@@ -28,6 +29,11 @@ export declare function ThemeProvider({ children, defaultPreference, storageKey,
|
|
|
28
29
|
* means it has not mounted yet, and nothing is set until it has.
|
|
29
30
|
*/
|
|
30
31
|
target?: HTMLElement | null;
|
|
32
|
+
/**
|
|
33
|
+
* How much the screen packs in, set on the same element as the colour scheme (the root, so
|
|
34
|
+
* overlays are reached): `compact` for a tool screen. See `Density`. Left out, nothing is set.
|
|
35
|
+
*/
|
|
36
|
+
density?: DensityName;
|
|
31
37
|
}): React.JSX.Element;
|
|
32
38
|
/** The person's colour-scheme preference, the scheme in effect, and a setter that persists it. Must be inside `ThemeProvider`. */
|
|
33
39
|
export declare function useColorScheme(): ColorSchemeState;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ControlSize } from '../lib/control';
|
|
1
2
|
import * as React from "react";
|
|
2
3
|
/** Props shared by the number field and the slider. */
|
|
3
4
|
export type RangeProps = {
|
|
@@ -25,10 +26,12 @@ export type NumberFieldProps = RangeProps & {
|
|
|
25
26
|
"aria-label"?: string;
|
|
26
27
|
id?: string;
|
|
27
28
|
name?: string;
|
|
29
|
+
/** `sm` is --control-h-sm, the height of a small `Toggle` or `IconButton` beside it. Default --control-h. */
|
|
30
|
+
size?: ControlSize;
|
|
28
31
|
className?: string;
|
|
29
32
|
};
|
|
30
33
|
/** 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;
|
|
34
|
+
export declare function NumberField({ value, onChange, min, max, step, places, unit, locale, required, disabled, id: idProp, name, size, className, "aria-label": ariaLabel, }: NumberFieldProps): React.JSX.Element;
|
|
32
35
|
/** Props for `Slider`. */
|
|
33
36
|
export type SliderProps = RangeProps & {
|
|
34
37
|
value: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -52,6 +52,8 @@ export { UndoBar, useUndoable, type PendingRemoval, type FailedRemoval, type Und
|
|
|
52
52
|
export { Done } from './components/done';
|
|
53
53
|
export { AppShell, SideNav, Breadcrumb, type NavItem } from './components/app-shell';
|
|
54
54
|
export { Tabs, type TabItem } from './components/tabs';
|
|
55
|
+
export { Density, type DensityName, type DensityProps } from './components/density';
|
|
56
|
+
export type { ControlSize } from './lib/control';
|
|
55
57
|
export { useHotkeys, KeysLegend, isTypingTarget, type Shortcut } from './components/hotkeys';
|
|
56
58
|
export { useActiveItem, ActiveList, type ActiveItem } from './components/active-list';
|
|
57
59
|
export { ThemeProvider, useColorScheme, useSystemColorScheme, ColorSchemeChoice, colorSchemeScript, COLOR_SCHEME_STORAGE_KEY, type ColorScheme, type ColorSchemePreference, type ColorSchemeLabels, type ColorSchemeState, } from './components/theme';
|
|
@@ -64,3 +66,5 @@ export { FIT, MIN_SCALE, MAX_SCALE, clampViewport, zoomAt, actualPixelsScale, ty
|
|
|
64
66
|
export { CompareGrid, type CompareGridProps } from './components/compare-grid';
|
|
65
67
|
export { useDifference, type DifferenceState, type ReadPixels } from './components/difference';
|
|
66
68
|
export { differences, readPixels, resample, MAX_SIDE, DEFAULT_TOLERANCE, type Difference, type Pixels } from './lib/image-diff';
|
|
69
|
+
export { useHistory, useHistoryState, type History, type HistoryOptions, type HistoryStep, type HistoryStateOptions, type SetOptions, } from './components/history';
|
|
70
|
+
export { useAutoSave, useLeaveGuard, SaveStatus, type AutoSave, type AutoSaveOptions, type SaveState } from './components/save';
|