strata-react 0.1.13 → 0.1.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 +3 -3
- package/dist/components/checkbox.d.ts +14 -1
- package/dist/components/data-view.d.ts +24 -2
- package/dist/components/selectable-grid.d.ts +29 -0
- package/dist/components/selection.d.ts +39 -2
- package/dist/components/thumbnail.d.ts +31 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +456 -114
- package/dist/index.js.map +1 -1
- package/dist/lib/in-view.d.ts +21 -0
- package/dist/query/index.d.ts +12 -2
- package/dist/{query-CkOrBm3w.js → query-BlPgaCBG.js} +20 -3
- package/dist/{query-CkOrBm3w.js.map → query-BlPgaCBG.js.map} +1 -1
- package/dist/testing.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -119,9 +119,9 @@ function KilnRoom() {
|
|
|
119
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
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 |
|
|
121
121
|
| 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`) |
|
|
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 |
|
|
122
|
+
| Data | `DataView`, `Load<T>`, `Stale`, `StaleNotice`, `EmptyState`, `Skeleton`, `Thumbnail`, `ThumbnailSkeleton`, `DataTable`, `TableSkeleton`, `VirtualList`, `InfiniteList`, `LineChart` | `DataView` requires skeleton and empty, and keeps data on screen under a `StaleNotice` (why, how old, Try again) when a refresh fails; `Thumbnail` is a remote image in a box of fixed `aspect`, with a skeleton while it loads, the required `missing` words when it fails or `src` is null, required `alt`, and a request only once it nears the screen (`eager` for the first few); 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`, `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; `SelectableGrid` is the same selection as a grid of pictures (`renderImage`), each tile one labelled target, virtualised from 100 tiles |
|
|
124
|
+
| Data loading | `StrataQueryProvider`, `createQueryClient`, `useLoad`, `useInfiniteLoad`, `toLoad`, `staleOf`, `fetchJson`, `HttpError` | TanStack Query in, `Load<T>` out; a refetch that fails after a good read stays `ready` with `stale` set, never an error panel; `useInfiniteLoad` works out the cursor itself (after the last item held), merges pages by key and can `dismiss` an item at once |
|
|
125
125
|
| 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) |
|
|
126
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 |
|
|
127
127
|
| 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 |
|
|
@@ -8,7 +8,20 @@ export type CheckboxProps = Omit<React.ComponentProps<"input">, "type" | "checke
|
|
|
8
8
|
/** A muted second line under a shown label. */
|
|
9
9
|
detail?: string;
|
|
10
10
|
checked: boolean | "mixed";
|
|
11
|
-
|
|
11
|
+
/** Called with the new state, and whether Shift was held (a range click or Shift+Space). */
|
|
12
|
+
onCheckedChange: (checked: boolean, gesture: CheckboxGesture) => void;
|
|
13
|
+
};
|
|
14
|
+
/** How a checkbox was changed: `shiftKey` is true for Shift+click and Shift+Space, which extend a range in a list. */
|
|
15
|
+
export type CheckboxGesture = {
|
|
16
|
+
shiftKey: boolean;
|
|
12
17
|
};
|
|
13
18
|
/** A native checkbox and its label as one target. `label` is required; `hideLabel` keeps it as the accessible name only. */
|
|
14
19
|
export declare function Checkbox({ label, hideLabel, detail, checked, onCheckedChange, className, disabled, ...props }: CheckboxProps): React.JSX.Element;
|
|
20
|
+
/** Notes Shift on the press that leads to a checkbox's change event, which has no modifier keys of its own. */
|
|
21
|
+
export declare function useShiftNote(): {
|
|
22
|
+
handlers: {
|
|
23
|
+
onMouseDown: (e: React.MouseEvent) => undefined;
|
|
24
|
+
onKeyDown: (e: React.KeyboardEvent) => undefined;
|
|
25
|
+
};
|
|
26
|
+
take: () => CheckboxGesture;
|
|
27
|
+
};
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
/** Data still shown after a refresh failed: why the refresh failed, when the data was read, and the Try again. */
|
|
3
|
+
export type Stale = {
|
|
4
|
+
/** Why the refresh failed, for a person: the sentence an error panel would have shown. */
|
|
5
|
+
message: string;
|
|
6
|
+
/** When the data on screen was read. */
|
|
7
|
+
readAt: Date;
|
|
8
|
+
/** Fetch again. */
|
|
9
|
+
retry: () => void;
|
|
10
|
+
/** A fetch is on its way (a Try again or the next poll). */
|
|
11
|
+
retrying?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** The state of one remote read, for `DataView`: loading, failed with no data, or ready (and `stale` when a later refresh failed). */
|
|
2
14
|
export type Load<T> = {
|
|
3
15
|
status: "loading";
|
|
4
16
|
} | {
|
|
@@ -8,9 +20,10 @@ export type Load<T> = {
|
|
|
8
20
|
} | {
|
|
9
21
|
status: "ready";
|
|
10
22
|
data: T;
|
|
23
|
+
stale?: Stale;
|
|
11
24
|
};
|
|
12
|
-
/** Every view of remote data: renders `skeleton` while loading, an alert with Try again on error, `empty` when `isEmpty`, else `children(data)
|
|
13
|
-
export declare function DataView<T>({ state, isEmpty, skeleton, empty, children, className, }: {
|
|
25
|
+
/** Every view of remote data: renders `skeleton` while loading, an alert with Try again on error, `empty` when `isEmpty`, else `children(data)`, under a `StaleNotice` when a refresh failed. The skeleton and empty state are required. */
|
|
26
|
+
export declare function DataView<T>({ state, isEmpty, skeleton, empty, children, staleNotice, className, }: {
|
|
14
27
|
state: Load<T>;
|
|
15
28
|
/** When the loaded data counts as empty. For arrays, `(rows) => rows.length === 0`. */
|
|
16
29
|
isEmpty: (data: T) => boolean;
|
|
@@ -19,6 +32,15 @@ export declare function DataView<T>({ state, isEmpty, skeleton, empty, children,
|
|
|
19
32
|
/** What goes here and how to add it. An `EmptyState`, not an illustration. */
|
|
20
33
|
empty: React.ReactNode;
|
|
21
34
|
children: (data: T) => React.ReactNode;
|
|
35
|
+
/** Shown above the data when a refresh failed. Defaults to a `StaleNotice`; pass one with the product's words for what is old ("Readings from 13:50"). */
|
|
36
|
+
staleNotice?: (stale: Stale) => React.ReactNode;
|
|
37
|
+
className?: string;
|
|
38
|
+
}): React.JSX.Element;
|
|
39
|
+
/** The notice over data whose refresh failed: what happened, how old the data shown is, and Try again. A polite status, not an alert: nothing was lost. */
|
|
40
|
+
export declare function StaleNotice({ stale, shown, className, }: {
|
|
41
|
+
stale: Stale;
|
|
42
|
+
/** What is old, in the product's words, given when it was read ("13:50", or "Sat 13:50" before today). Defaults to "Showing data from 13:50." */
|
|
43
|
+
shown?: (when: string) => React.ReactNode;
|
|
22
44
|
className?: string;
|
|
23
45
|
}): React.JSX.Element;
|
|
24
46
|
/** An empty state that teaches the next action: a title, a sentence and an action. No illustration slot, on purpose. */
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { RowSelection } from './data-table';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
/** The frame each picture is drawn in. */
|
|
4
|
+
export type TileAspect = "square" | "portrait" | "landscape";
|
|
5
|
+
/** Smallest tile width: `sm` 96px (dense crops), `md` 144px, `lg` 192px. Tiles grow to fill the row. */
|
|
6
|
+
export type TileSize = "sm" | "md" | "lg";
|
|
7
|
+
export type SelectableGridProps<T> = {
|
|
8
|
+
/** Names the list of tiles (and its scroll region once virtualised). */
|
|
9
|
+
label: string;
|
|
10
|
+
rows: T[];
|
|
11
|
+
rowKey: (row: T) => string;
|
|
12
|
+
/** The picture, drawn to fill a frame of `aspect`. An `<img className="size-full object-cover">` or a `Thumbnail`. */
|
|
13
|
+
renderImage: (row: T) => React.ReactNode;
|
|
14
|
+
/** A short line under the picture (a name, a date, a score). Truncated to one line. */
|
|
15
|
+
detail?: (row: T) => React.ReactNode;
|
|
16
|
+
/** The chosen keys and how to change them, as `DataTable` takes them; `rowLabel` names each tile's box. */
|
|
17
|
+
selection: RowSelection<T>;
|
|
18
|
+
/** Default `square`. `portrait` is 3:4, `landscape` 4:3. */
|
|
19
|
+
aspect?: TileAspect;
|
|
20
|
+
/** Default `md`. */
|
|
21
|
+
tileSize?: TileSize;
|
|
22
|
+
/** Tile count from which only the visible rows of tiles render. Default 100. */
|
|
23
|
+
virtualizeFrom?: number;
|
|
24
|
+
/** Height of the scroll region once virtualised, in px. Default 480. */
|
|
25
|
+
maxHeight?: number;
|
|
26
|
+
className?: string;
|
|
27
|
+
};
|
|
28
|
+
/** A grid of pictures to choose from: each tile one labelled target, "Select all shown", Shift-click ranges, virtualised from `virtualizeFrom` tiles. Pair with `useSelection` and a `BulkBar`. */
|
|
29
|
+
export declare function SelectableGrid<T>({ label, rows, rowKey, renderImage, detail, selection, aspect, tileSize, virtualizeFrom, maxHeight, className, }: SelectableGridProps<T>): React.JSX.Element;
|
|
@@ -1,13 +1,49 @@
|
|
|
1
1
|
import { Format } from '../lib/format';
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
/**
|
|
4
|
-
export
|
|
3
|
+
/** Which rows start chosen: their keys, or a test on each row. Either applies to a row the first time it appears. */
|
|
4
|
+
export type InitialSelection<T> = Iterable<string> | ((row: T) => boolean);
|
|
5
|
+
/**
|
|
6
|
+
* Chosen row keys, pruned to the rows that exist, and the calls that change them. Spread into
|
|
7
|
+
* `DataTable`'s or `SelectableGrid`'s `selection` with a `rowLabel`. `initial` (keys, or a test on
|
|
8
|
+
* the row) chooses each row the first time it appears, so a selection seeded from data that loads
|
|
9
|
+
* later, or a next page, still starts right.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useSelection<T>(rows: readonly T[], rowKey: (row: T) => string, initial?: InitialSelection<T>): {
|
|
5
12
|
selected: ReadonlySet<string>;
|
|
6
13
|
selectedRows: T[];
|
|
7
14
|
count: number;
|
|
8
15
|
onChange: (next: Set<string>) => void;
|
|
9
16
|
clear: () => void;
|
|
10
17
|
};
|
|
18
|
+
/** The part of a selection the surfaces drawing it (`DataTable`, `SelectableGrid`) need. */
|
|
19
|
+
type SelectionLike<T> = {
|
|
20
|
+
selected: ReadonlySet<string>;
|
|
21
|
+
onChange: (next: Set<string>) => void;
|
|
22
|
+
isSelectable?: (row: T) => boolean;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Selecting rows of a surface in the order it shows them: one row, a range with Shift, and all
|
|
26
|
+
* shown. Shared by `DataTable` and `SelectableGrid`, so a range and select-all behave the same on
|
|
27
|
+
* both. `rows` are in display order (after sorting) and include rows a virtualised surface has not
|
|
28
|
+
* rendered.
|
|
29
|
+
*
|
|
30
|
+
* A range runs from the last row clicked (the anchor) to this one, over the selectable rows
|
|
31
|
+
* between, and sets them all to this row's new state, as Gmail and Finder do: Shift-clicking an
|
|
32
|
+
* unchosen row chooses the run, Shift-clicking a chosen one clears it. Every click moves the
|
|
33
|
+
* anchor. An anchor that has left the rows (filtered, removed) makes the next Shift-click a plain
|
|
34
|
+
* one.
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export declare function useSelectRows<T>(rows: readonly T[], rowKey: (row: T) => string, selection?: SelectionLike<T>): {
|
|
38
|
+
toggle: (key: string, on: boolean, { shiftKey }: {
|
|
39
|
+
shiftKey: boolean;
|
|
40
|
+
}) => void;
|
|
41
|
+
all: {
|
|
42
|
+
checked: boolean | "mixed";
|
|
43
|
+
toggle: () => void;
|
|
44
|
+
disabled: boolean;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
11
47
|
/** 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
48
|
export declare function BulkBar({ count, noun, onClear, children, format, className, }: {
|
|
13
49
|
count: number;
|
|
@@ -20,3 +56,4 @@ export declare function BulkBar({ count, noun, onClear, children, format, classN
|
|
|
20
56
|
format?: Format;
|
|
21
57
|
className?: string;
|
|
22
58
|
}): React.JSX.Element;
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/** A width-over-height ratio: a number (`1.5`) or a fraction (`"4/3"`). */
|
|
3
|
+
export type AspectRatio = number | `${number}/${number}`;
|
|
4
|
+
/** The thumbnail's props. */
|
|
5
|
+
export type ThumbnailProps = {
|
|
6
|
+
/** The image URL. `null` when the record has no photo: the `missing` words show without a request. */
|
|
7
|
+
src: string | null;
|
|
8
|
+
/** What the photo shows ("Celadon bowl, front"). `""` only when the text beside it already says it. */
|
|
9
|
+
alt: string;
|
|
10
|
+
/** What to show when there is no photo or it cannot be loaded, in the product's words: "Photo not found". */
|
|
11
|
+
missing: string;
|
|
12
|
+
/** Width over height. The box has this shape before the image loads. Default `1`. */
|
|
13
|
+
aspect?: AspectRatio;
|
|
14
|
+
/** `cover` crops to fill the box (default); `contain` fits the whole image in it. */
|
|
15
|
+
fit?: "cover" | "contain";
|
|
16
|
+
srcSet?: string;
|
|
17
|
+
sizes?: string;
|
|
18
|
+
/** Load at once rather than when near the screen: for the first few above the fold. */
|
|
19
|
+
eager?: boolean;
|
|
20
|
+
/** How far outside the scroll region the request starts (IntersectionObserver `rootMargin`). */
|
|
21
|
+
rootMargin?: string;
|
|
22
|
+
/** Layout at the call site: a width (`w-24`, `w-full`). The height follows from `aspect`. */
|
|
23
|
+
className?: string;
|
|
24
|
+
};
|
|
25
|
+
/** A box of fixed aspect ratio for a remote image: a skeleton until it loads, the `missing` words if it cannot, and a request only when it nears the screen. `alt` and `missing` are required. */
|
|
26
|
+
export declare function Thumbnail({ src, alt, missing, aspect, fit, srcSet, sizes, eager, rootMargin, className, }: ThumbnailProps): React.JSX.Element;
|
|
27
|
+
/** The loading shape of a `Thumbnail`, for a `DataView` skeleton: the same box and aspect ratio, so nothing moves when the list arrives. */
|
|
28
|
+
export declare function ThumbnailSkeleton({ aspect, className }: {
|
|
29
|
+
aspect?: AspectRatio;
|
|
30
|
+
className?: string;
|
|
31
|
+
}): React.JSX.Element;
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { cn, typeSteps } from './lib/utils';
|
|
|
9
9
|
export { createFormat, format, NBSP, toDate, type ByteUnit, type DateFormatter, type DateInput, type Format, type FormatOptions, type NumberFormatter } from './lib/format';
|
|
10
10
|
export type { IconComponent } from './lib/icon';
|
|
11
11
|
export { Button, IconButton, RowAction, buttonVariants, type ButtonProps, type IconButtonProps, type RowActionProps, } from './components/button';
|
|
12
|
-
export { Checkbox, type CheckboxProps } from './components/checkbox';
|
|
12
|
+
export { Checkbox, type CheckboxProps, type CheckboxGesture } from './components/checkbox';
|
|
13
13
|
export { AsyncButton, useAsyncAction, type Phase, type AsyncLabels, type AsyncAction, type AsyncActionOptions } from './components/async-button';
|
|
14
14
|
export { Field, Input, Textarea, NativeSelect, ChoiceGroup, type FieldProps, type Choice } from './components/field';
|
|
15
15
|
export { Status, type Tone } from './components/status';
|
|
@@ -17,9 +17,11 @@ export { Metric, MetricStrip, type MetricProps } from './components/metric';
|
|
|
17
17
|
export { Meter, crossedThreshold, type MeterProps, type MeterThreshold } from './components/meter';
|
|
18
18
|
export { CompositionBar, type CompositionBarProps, type CompositionPart } from './components/composition';
|
|
19
19
|
export { LinkCard, LinkCardList, type LinkCardProps } from './components/link-card';
|
|
20
|
-
export { DataView, EmptyState, Skeleton, type Load } from './components/data-view';
|
|
20
|
+
export { DataView, EmptyState, Skeleton, StaleNotice, type Load, type Stale } from './components/data-view';
|
|
21
|
+
export { Thumbnail, ThumbnailSkeleton, type ThumbnailProps, type AspectRatio } from './components/thumbnail';
|
|
21
22
|
export { DataTable, TableSkeleton, parseSort, serialiseSort, type Column, type Sort, type DataTableProps, type RowSelection, } from './components/data-table';
|
|
22
|
-
export { BulkBar, useSelection } from './components/selection';
|
|
23
|
+
export { BulkBar, useSelection, type InitialSelection } from './components/selection';
|
|
24
|
+
export { SelectableGrid, type SelectableGridProps, type TileAspect, type TileSize, } from './components/selectable-grid';
|
|
23
25
|
export { VirtualList } from './components/virtual-list';
|
|
24
26
|
export { InfiniteList, type InfiniteListProps } from './components/infinite-list';
|
|
25
27
|
export { LineChart, type LineChartProps, type Point } from './components/line-chart';
|
|
@@ -31,5 +33,5 @@ export { Tabs, type TabItem } from './components/tabs';
|
|
|
31
33
|
export { useHotkeys, KeysLegend, isTypingTarget, type Shortcut } from './components/hotkeys';
|
|
32
34
|
export { useActiveItem, ActiveList, type ActiveItem } from './components/active-list';
|
|
33
35
|
export { ThemeProvider, useColorScheme, useSystemColorScheme, ColorSchemeChoice, colorSchemeScript, COLOR_SCHEME_STORAGE_KEY, type ColorScheme, type ColorSchemePreference, type ColorSchemeLabels, type ColorSchemeState, } from './components/theme';
|
|
34
|
-
export { StrataQueryProvider, createQueryClient, toLoad, useLoad, useInfiniteLoad, fetchJson, HttpError, describeHttpError, type DescribeError, type InfiniteLoad, type InfiniteLoadOptions, type More, } from './query';
|
|
36
|
+
export { StrataQueryProvider, createQueryClient, toLoad, staleOf, useLoad, useInfiniteLoad, fetchJson, HttpError, describeHttpError, type DescribeError, type InfiniteLoad, type InfiniteLoadOptions, type More, } from './query';
|
|
35
37
|
export { describeActionError } from './lib/errors';
|