strata-react 0.1.0 → 0.1.4
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 -1
- package/dist/components/app-shell.d.ts +3 -0
- package/dist/components/async-button.d.ts +22 -3
- package/dist/components/button.d.ts +2 -0
- package/dist/components/data-table.d.ts +4 -0
- package/dist/components/data-view.d.ts +4 -1
- package/dist/components/done.d.ts +1 -0
- package/dist/components/field.d.ts +5 -0
- package/dist/components/line-chart.d.ts +1 -0
- package/dist/components/metric.d.ts +2 -0
- package/dist/components/page-header.d.ts +1 -0
- package/dist/components/status.d.ts +1 -0
- package/dist/components/tabs.d.ts +1 -0
- package/dist/components/undo.d.ts +7 -5
- package/dist/components/virtual-list.d.ts +1 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.js +89 -15
- package/dist/index.js.map +1 -1
- package/dist/lib/errors.d.ts +13 -0
- package/dist/lib/format.d.ts +2 -0
- package/dist/lib/utils.d.ts +1 -0
- package/dist/query/index.d.ts +6 -10
- package/dist/{query-BXH-Gfj7.js → query-Bi7rfvwp.js} +27 -16
- package/dist/query-Bi7rfvwp.js.map +1 -0
- package/dist/testing/index.d.ts +6 -0
- package/dist/testing.js +1 -1
- package/dist/testing.js.map +1 -1
- package/package.json +5 -2
- package/dist/query-BXH-Gfj7.js.map +0 -1
package/README.md
CHANGED
|
@@ -80,7 +80,7 @@ function KilnRoom() {
|
|
|
80
80
|
|
|
81
81
|
| Group | Exports | Notes |
|
|
82
82
|
|---|---|---|
|
|
83
|
-
| 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 |
|
|
83
|
+
| 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`) |
|
|
84
84
|
| Form | `Field`, `Input`, `Textarea`, `NativeSelect`, `ChoiceGroup` | `Field` wires label, hint, error, `aria-describedby`, `aria-invalid` |
|
|
85
85
|
| Status and figures | `Status`, `Metric`, `MetricStrip` | A status is always a word; figures have no icons or sparklines |
|
|
86
86
|
| 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 |
|
|
@@ -102,8 +102,16 @@ npm test # typecheck + unit tests
|
|
|
102
102
|
npm run test:integration # build, then check the package and its CSS as an app sees them
|
|
103
103
|
npm run test:visual # screenshot every story (light, dark) and compare with baselines
|
|
104
104
|
npm run test:visual:update # accept the current screenshots as baselines
|
|
105
|
+
npm run site # build the docs site into site/
|
|
105
106
|
```
|
|
106
107
|
|
|
108
|
+
## Docs site
|
|
109
|
+
|
|
110
|
+
GitHub Pages serves one site, built by `.github/workflows/pages.yml` on every push to main:
|
|
111
|
+
Storybook at the root, the TypeDoc API reference at `/api/`, and a gallery of every visual
|
|
112
|
+
baseline (light and dark, linked to its story) at `/visuals/`. One-time setup: Settings → Pages →
|
|
113
|
+
Source: GitHub Actions.
|
|
114
|
+
|
|
107
115
|
## Licence
|
|
108
116
|
|
|
109
117
|
MIT
|
|
@@ -7,6 +7,7 @@ export type NavItem = {
|
|
|
7
7
|
/** Match only this exact path, for an index route such as "/". */
|
|
8
8
|
end?: boolean;
|
|
9
9
|
};
|
|
10
|
+
/** The app frame: product name, side nav on the page ground (a scrollable row on phones), optional top bar, and the main region. */
|
|
10
11
|
export declare function AppShell({ product, nav, navLabel, topBar, children, className, }: {
|
|
11
12
|
/** The product's name or mark, linking home. */
|
|
12
13
|
product: React.ReactNode;
|
|
@@ -16,11 +17,13 @@ export declare function AppShell({ product, nav, navLabel, topBar, children, cla
|
|
|
16
17
|
children: React.ReactNode;
|
|
17
18
|
className?: string;
|
|
18
19
|
}): React.JSX.Element;
|
|
20
|
+
/** Navigation links (React Router `NavLink`); the current route is a neutral pill with `aria-current`. */
|
|
19
21
|
export declare function SideNav({ items, label, className }: {
|
|
20
22
|
items: NavItem[];
|
|
21
23
|
label: string;
|
|
22
24
|
className?: string;
|
|
23
25
|
}): React.JSX.Element;
|
|
26
|
+
/** Plain links separated by `/`; the last crumb is the current page. */
|
|
24
27
|
export declare function Breadcrumb({ items }: {
|
|
25
28
|
items: {
|
|
26
29
|
label: string;
|
|
@@ -9,9 +9,28 @@ export type AsyncLabels = {
|
|
|
9
9
|
done: string;
|
|
10
10
|
error?: string;
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
/** One button through idle, pending, done and error, with the label changing in place and its width fixed by the longest label. The outcome is announced politely, with the error's own words when `error` is given. */
|
|
13
|
+
export declare function AsyncButton({ phase, labels, error, disabled, ...props }: Omit<ButtonProps, "children"> & {
|
|
13
14
|
phase: Phase;
|
|
14
15
|
labels: AsyncLabels;
|
|
16
|
+
/** What went wrong, in the product's words (`useAsyncAction`'s `error`). Announced with the error label when `phase` is `error`. */
|
|
17
|
+
error?: string;
|
|
15
18
|
}): React.JSX.Element;
|
|
16
|
-
/**
|
|
17
|
-
export
|
|
19
|
+
/** Options for `useAsyncAction`. */
|
|
20
|
+
export type AsyncActionOptions = {
|
|
21
|
+
/** How long `done` shows before returning to `idle`. Default 2000ms. */
|
|
22
|
+
settleMs?: number;
|
|
23
|
+
/** Called with whatever the action threw, once the `error` render has committed: for logging, or to move focus to the retry button or an error message. */
|
|
24
|
+
onError?: (error: unknown) => void;
|
|
25
|
+
/** Turns what was thrown into `error`'s sentence, in the product's words. Default `describeActionError`: HTTP status sentences for `fetchJson`'s `HttpError`, else the Error's message. */
|
|
26
|
+
describeError?: (error: unknown) => string | undefined;
|
|
27
|
+
};
|
|
28
|
+
/** What `useAsyncAction` returns: the phase for `AsyncButton`, a stable `run`, and what went wrong while `phase` is `error`. */
|
|
29
|
+
export type AsyncAction<A extends unknown[]> = {
|
|
30
|
+
phase: Phase;
|
|
31
|
+
run: (...args: A) => Promise<void>;
|
|
32
|
+
/** What went wrong, from `describeError`, while `phase` is `error`; otherwise undefined. Pass it to `AsyncButton`'s `error`. */
|
|
33
|
+
error: string | undefined;
|
|
34
|
+
};
|
|
35
|
+
/** Runs an async action and reports its phase and error. `done` returns to `idle` after `settleMs`; `run` never changes identity. */
|
|
36
|
+
export declare function useAsyncAction<A extends unknown[]>(action: (...args: A) => Promise<unknown>, { settleMs, onError, describeError }?: AsyncActionOptions): AsyncAction<A>;
|
|
@@ -8,9 +8,11 @@ export declare const buttonVariants: (props?: ({
|
|
|
8
8
|
export type ButtonProps = React.ComponentProps<"button"> & VariantProps<typeof buttonVariants> & {
|
|
9
9
|
asChild?: boolean;
|
|
10
10
|
};
|
|
11
|
+
/** A button with shadcn's variant names. The default variant is `outline`; ask for the filled accent (`variant="default"`) once per view. `type` defaults to `button`. */
|
|
11
12
|
export declare function Button({ className, variant, size, asChild, type, ...props }: ButtonProps): React.JSX.Element;
|
|
12
13
|
export type IconButtonProps = Omit<ButtonProps, "size" | "children" | "aria-label"> & {
|
|
13
14
|
icon: IconComponent;
|
|
14
15
|
label: string;
|
|
15
16
|
};
|
|
17
|
+
/** An icon-only button. `label` is required and becomes the accessible name and tooltip. */
|
|
16
18
|
export declare function IconButton({ icon: Icon, label, variant, ...props }: IconButtonProps): React.JSX.Element;
|
|
@@ -29,9 +29,13 @@ export type DataTableProps<T> = {
|
|
|
29
29
|
maxHeight?: number;
|
|
30
30
|
className?: string;
|
|
31
31
|
};
|
|
32
|
+
/** Reads a sort from its URL form (`pieces.desc`). */
|
|
32
33
|
export declare function parseSort(value: string | null): Sort | undefined;
|
|
34
|
+
/** Writes a sort in its URL form (`pieces.desc`). */
|
|
33
35
|
export declare function serialiseSort(sort: Sort): string;
|
|
36
|
+
/** 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`). */
|
|
34
37
|
export declare function DataTable<T>(props: DataTableProps<T>): React.JSX.Element;
|
|
38
|
+
/** The loading placeholder for a `DataTable`, shaped like its rows. */
|
|
35
39
|
export declare function TableSkeleton({ rows, columns }: {
|
|
36
40
|
rows?: number;
|
|
37
41
|
columns?: number;
|
|
@@ -9,22 +9,25 @@ export type Load<T> = {
|
|
|
9
9
|
status: "ready";
|
|
10
10
|
data: T;
|
|
11
11
|
};
|
|
12
|
+
/** Every view of remote data: renders `skeleton` while loading, an alert with Try again on error, `empty` when `isEmpty`, else `children(data)`. The skeleton and empty state are required. */
|
|
12
13
|
export declare function DataView<T>({ state, isEmpty, skeleton, empty, children, className, }: {
|
|
13
14
|
state: Load<T>;
|
|
14
15
|
/** When the loaded data counts as empty. For arrays, `(rows) => rows.length === 0`. */
|
|
15
16
|
isEmpty: (data: T) => boolean;
|
|
16
17
|
/** Mirrors the final layout, so nothing jumps when data arrives. Not a centred spinner. */
|
|
17
18
|
skeleton: React.ReactNode;
|
|
18
|
-
/** What goes here and how to add it. An
|
|
19
|
+
/** What goes here and how to add it. An `EmptyState`, not an illustration. */
|
|
19
20
|
empty: React.ReactNode;
|
|
20
21
|
children: (data: T) => React.ReactNode;
|
|
21
22
|
className?: string;
|
|
22
23
|
}): React.JSX.Element;
|
|
24
|
+
/** An empty state that teaches the next action: a title, a sentence and an action. No illustration slot, on purpose. */
|
|
23
25
|
export declare function EmptyState({ title, children, action }: {
|
|
24
26
|
title: string;
|
|
25
27
|
children?: React.ReactNode;
|
|
26
28
|
action?: React.ReactNode;
|
|
27
29
|
}): React.JSX.Element;
|
|
30
|
+
/** A placeholder block for a loading layout. Size it with layout classes so it mirrors the final content. */
|
|
28
31
|
export declare function Skeleton({ className }: {
|
|
29
32
|
className?: string;
|
|
30
33
|
}): React.JSX.Element;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
/** The completion moment for a rare, earned finish: what happened (past tense, with its object), what happens next, and optionally a figure drawn from the person's own data. Focus moves to the heading. */
|
|
2
3
|
export declare function Done({ title, next, figure, actions, focusOnMount, className, }: {
|
|
3
4
|
/** What happened, past tense, with its object. */
|
|
4
5
|
title: string;
|
|
@@ -10,15 +10,20 @@ export type FieldProps = {
|
|
|
10
10
|
children: React.ReactNode;
|
|
11
11
|
className?: string;
|
|
12
12
|
};
|
|
13
|
+
/** A labelled form field: wires the label, hint, error, `aria-describedby` and `aria-invalid` into the one control it wraps. */
|
|
13
14
|
export declare function Field({ label, id: idProp, hint, error, children, className }: FieldProps): React.JSX.Element;
|
|
15
|
+
/** A text input that picks up its id and descriptions from the surrounding `Field`. */
|
|
14
16
|
export declare function Input({ className, id, ...props }: React.ComponentProps<"input">): React.JSX.Element;
|
|
17
|
+
/** A multi-line input that picks up its id and descriptions from the surrounding `Field`. */
|
|
15
18
|
export declare function Textarea({ className, id, ...props }: React.ComponentProps<"textarea">): React.JSX.Element;
|
|
19
|
+
/** The platform select, styled. The default for short lists, especially on touch screens. */
|
|
16
20
|
export declare function NativeSelect({ className, id, ...props }: React.ComponentProps<"select">): React.JSX.Element;
|
|
17
21
|
export type Choice = {
|
|
18
22
|
value: string;
|
|
19
23
|
label: string;
|
|
20
24
|
detail?: string;
|
|
21
25
|
};
|
|
26
|
+
/** Radio choices in a fieldset with a legend; each whole row is the hit target. For 2 to 5 options that each need a sentence. */
|
|
22
27
|
export declare function ChoiceGroup({ legend, name, choices, value, onChange, error, }: {
|
|
23
28
|
legend: string;
|
|
24
29
|
name: string;
|
|
@@ -32,4 +32,5 @@ export type LineChartProps = {
|
|
|
32
32
|
};
|
|
33
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
34
|
export declare function niceMax(max: number): number;
|
|
35
|
+
/** 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`. */
|
|
35
36
|
export declare function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, formatX, formatY, xTicks, colour, colourScale, colourScaleLabel, height, className, }: LineChartProps): React.JSX.Element;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
/** Headline figures as one description list split by hairlines. Holds `Metric`s. */
|
|
2
3
|
export declare function MetricStrip({ label, children, className }: {
|
|
3
4
|
label: string;
|
|
4
5
|
children: React.ReactNode;
|
|
@@ -12,4 +13,5 @@ export type MetricProps = {
|
|
|
12
13
|
/** One sentence: the change in words with its window, or what the figure means right now. */
|
|
13
14
|
note?: React.ReactNode;
|
|
14
15
|
};
|
|
16
|
+
/** One figure: label over value, an optional muted unit and a note that states any change in words with its window. */
|
|
15
17
|
export declare function Metric({ label, value, unit, note }: MetricProps): React.JSX.Element;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
/** The top of an Operate screen: a noun title, its scope, the main action, and the finding (the one fact in today's data that most needs attention). */
|
|
2
3
|
export declare function PageHeader({ title, scope, actions, finding, as: Heading, }: {
|
|
3
4
|
title: string;
|
|
4
5
|
/** The title's element: h1 on a screen, h2 where the header is shown inside another page. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IconComponent } from '../lib/icon';
|
|
2
2
|
export type Tone = "neutral" | "info" | "success" | "warning" | "danger";
|
|
3
|
+
/** A status as a word on a pale tint of its tone, with an optional icon. Never colour alone. */
|
|
3
4
|
export declare function Status({ tone, icon: Icon, children, className, }: {
|
|
4
5
|
tone: Tone;
|
|
5
6
|
icon?: IconComponent;
|
|
@@ -3,6 +3,7 @@ export type TabItem = {
|
|
|
3
3
|
value: string;
|
|
4
4
|
label: string;
|
|
5
5
|
};
|
|
6
|
+
/** Tabs whose selection lives in a URL search parameter (React Router), with the ARIA tabs keyboard model. */
|
|
6
7
|
export declare function Tabs({ param, items, label, children, className, }: {
|
|
7
8
|
/** The search parameter that holds the selected tab. */
|
|
8
9
|
param: string;
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
|
|
2
|
+
/** A removal waiting out its undo window: what to say, and what to do when the window closes. */
|
|
3
|
+
export type PendingRemoval = {
|
|
3
4
|
id: string;
|
|
4
5
|
message: string;
|
|
5
6
|
commit: () => void;
|
|
6
7
|
};
|
|
8
|
+
/** Schedules a reversible removal to commit after `windowMs` unless undone. A second removal, or unmounting, commits the pending one. */
|
|
7
9
|
export declare function useUndoable(windowMs?: number): {
|
|
8
|
-
pending:
|
|
9
|
-
schedule: (next:
|
|
10
|
+
pending: PendingRemoval | null;
|
|
11
|
+
schedule: (next: PendingRemoval) => void;
|
|
10
12
|
undo: () => void;
|
|
11
13
|
};
|
|
14
|
+
/** The polite live region that shows a pending removal with an Undo button. */
|
|
12
15
|
export declare function UndoBar({ pending, onUndo, inline, }: {
|
|
13
|
-
pending:
|
|
16
|
+
pending: PendingRemoval | null;
|
|
14
17
|
onUndo: () => void;
|
|
15
18
|
/** Render in the flow instead of fixed to the viewport; for the state-matrix page. */
|
|
16
19
|
inline?: boolean;
|
|
17
20
|
}): React.JSX.Element;
|
|
18
|
-
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
/** A list that renders only its visible rows (TanStack Virtual) from `virtualizeFrom` items, keeping list semantics for screen readers. */
|
|
2
3
|
export declare function VirtualList<T>({ label, items, itemKey, children, estimateSize, height, virtualizeFrom, className, }: {
|
|
3
4
|
label: string;
|
|
4
5
|
items: T[];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* strata-react: an opinionated React + Tailwind v4 framework for building product frontends.
|
|
3
|
+
* Components ship structure, behaviour, states and accessibility; the look comes from the
|
|
4
|
+
* product's own theme. Every component has a Storybook story for each of its states.
|
|
5
|
+
*
|
|
6
|
+
* @module strata-react
|
|
7
|
+
*/
|
|
1
8
|
export { cn, typeSteps } from './lib/utils';
|
|
2
9
|
export { createFormat, format, NBSP, type Format } from './lib/format';
|
|
3
10
|
export type { IconComponent } from './lib/icon';
|
|
4
11
|
export { Button, IconButton, buttonVariants, type ButtonProps, type IconButtonProps } from './components/button';
|
|
5
|
-
export { AsyncButton, useAsyncAction, type Phase, type AsyncLabels } from './components/async-button';
|
|
12
|
+
export { AsyncButton, useAsyncAction, type Phase, type AsyncLabels, type AsyncAction, type AsyncActionOptions } from './components/async-button';
|
|
6
13
|
export { Field, Input, Textarea, NativeSelect, ChoiceGroup, type FieldProps, type Choice } from './components/field';
|
|
7
14
|
export { Status, type Tone } from './components/status';
|
|
8
15
|
export { Metric, MetricStrip, type MetricProps } from './components/metric';
|
|
@@ -11,8 +18,9 @@ export { DataTable, TableSkeleton, parseSort, serialiseSort, type Column, type S
|
|
|
11
18
|
export { VirtualList } from './components/virtual-list';
|
|
12
19
|
export { LineChart, type LineChartProps, type Point } from './components/line-chart';
|
|
13
20
|
export { PageHeader } from './components/page-header';
|
|
14
|
-
export { UndoBar, useUndoable } from './components/undo';
|
|
21
|
+
export { UndoBar, useUndoable, type PendingRemoval } from './components/undo';
|
|
15
22
|
export { Done } from './components/done';
|
|
16
23
|
export { AppShell, SideNav, Breadcrumb, type NavItem } from './components/app-shell';
|
|
17
24
|
export { Tabs, type TabItem } from './components/tabs';
|
|
18
25
|
export { StrataQueryProvider, createQueryClient, toLoad, useLoad, fetchJson, HttpError, describeHttpError, type DescribeError, } from './query';
|
|
26
|
+
export { describeActionError } from './lib/errors';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as useLoad, c as describeHttpError, i as toLoad, n as createQueryClient, o as HttpError, r as fetchJson, s as describeActionError, t as StrataQueryProvider } from "./query-Bi7rfvwp.js";
|
|
2
2
|
import { clsx } from "clsx";
|
|
3
3
|
import { extendTailwindMerge } from "tailwind-merge";
|
|
4
4
|
import * as React from "react";
|
|
@@ -21,11 +21,13 @@ var typeSteps = [
|
|
|
21
21
|
"display"
|
|
22
22
|
];
|
|
23
23
|
var twMerge = extendTailwindMerge({ extend: { classGroups: { "font-size": [{ type: [...typeSteps] }] } } });
|
|
24
|
+
/** clsx + tailwind-merge, taught that `type-*` utilities are font sizes. */
|
|
24
25
|
function cn(...inputs) {
|
|
25
26
|
return twMerge(clsx(inputs));
|
|
26
27
|
}
|
|
27
28
|
// src/lib/format.ts
|
|
28
29
|
var NBSP = "\xA0";
|
|
30
|
+
/** Intl formatters for one locale: integers, decimals, percent, times, days, units with a non-breaking space, and counted nouns. */
|
|
29
31
|
function createFormat(locale) {
|
|
30
32
|
const integer = new Intl.NumberFormat(locale, { maximumFractionDigits: 0 });
|
|
31
33
|
const decimal = new Intl.NumberFormat(locale, { maximumFractionDigits: 1 });
|
|
@@ -62,6 +64,7 @@ function createFormat(locale) {
|
|
|
62
64
|
count: (value, one, many = `${one}s`) => `${integer.format(value)} ${new Intl.PluralRules(locale).select(value) === "one" ? one : many}`
|
|
63
65
|
};
|
|
64
66
|
}
|
|
67
|
+
/** The en-GB formatters. */
|
|
65
68
|
var format = createFormat("en-GB");
|
|
66
69
|
// src/components/button.tsx
|
|
67
70
|
var buttonVariants = cva("inline-flex shrink-0 cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-control type-label transition-state press disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0", {
|
|
@@ -85,6 +88,7 @@ var buttonVariants = cva("inline-flex shrink-0 cursor-pointer items-center justi
|
|
|
85
88
|
size: "default"
|
|
86
89
|
}
|
|
87
90
|
});
|
|
91
|
+
/** A button with shadcn's variant names. The default variant is `outline`; ask for the filled accent (`variant="default"`) once per view. `type` defaults to `button`. */
|
|
88
92
|
function Button({ className, variant, size, asChild = false, type = "button", ...props }) {
|
|
89
93
|
return /* @__PURE__ */ jsx(asChild ? Slot : "button", {
|
|
90
94
|
type: asChild ? void 0 : type,
|
|
@@ -95,6 +99,7 @@ function Button({ className, variant, size, asChild = false, type = "button", ..
|
|
|
95
99
|
...props
|
|
96
100
|
});
|
|
97
101
|
}
|
|
102
|
+
/** An icon-only button. `label` is required and becomes the accessible name and tooltip. */
|
|
98
103
|
function IconButton({ icon: Icon, label, variant = "ghost", ...props }) {
|
|
99
104
|
return /* @__PURE__ */ jsx(Button, {
|
|
100
105
|
size: "icon",
|
|
@@ -106,7 +111,8 @@ function IconButton({ icon: Icon, label, variant = "ghost", ...props }) {
|
|
|
106
111
|
});
|
|
107
112
|
}
|
|
108
113
|
// src/components/async-button.tsx
|
|
109
|
-
|
|
114
|
+
/** One button through idle, pending, done and error, with the label changing in place and its width fixed by the longest label. The outcome is announced politely, with the error's own words when `error` is given. */
|
|
115
|
+
function AsyncButton({ phase, labels, error, disabled, ...props }) {
|
|
110
116
|
const errorLabel = labels.error ?? "Try again";
|
|
111
117
|
const current = {
|
|
112
118
|
idle: labels.idle,
|
|
@@ -120,6 +126,7 @@ function AsyncButton({ phase, labels, disabled, ...props }) {
|
|
|
120
126
|
done: Check,
|
|
121
127
|
error: CircleAlert
|
|
122
128
|
}[phase];
|
|
129
|
+
const announcement = phase === "done" ? labels.done : phase === "error" ? error ? `${error} ${errorLabel}` : errorLabel : "";
|
|
123
130
|
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Button, {
|
|
124
131
|
...props,
|
|
125
132
|
disabled: disabled || phase === "pending",
|
|
@@ -143,25 +150,67 @@ function AsyncButton({ phase, labels, disabled, ...props }) {
|
|
|
143
150
|
}), /* @__PURE__ */ jsx("span", {
|
|
144
151
|
role: "status",
|
|
145
152
|
className: "sr-only",
|
|
146
|
-
children:
|
|
153
|
+
children: announcement
|
|
147
154
|
})] });
|
|
148
155
|
}
|
|
149
|
-
/** Runs an async action and reports its phase. `done` returns to `idle` after `settleMs
|
|
150
|
-
function useAsyncAction(action, settleMs = 2e3) {
|
|
151
|
-
const [
|
|
156
|
+
/** Runs an async action and reports its phase and error. `done` returns to `idle` after `settleMs`; `run` never changes identity. */
|
|
157
|
+
function useAsyncAction(action, { settleMs = 2e3, onError, describeError = describeActionError } = {}) {
|
|
158
|
+
const [state, setState] = React.useState({
|
|
159
|
+
phase: "idle",
|
|
160
|
+
error: void 0
|
|
161
|
+
});
|
|
152
162
|
const timer = React.useRef(void 0);
|
|
163
|
+
const unreported = React.useRef(void 0);
|
|
164
|
+
const latest = React.useRef({
|
|
165
|
+
action,
|
|
166
|
+
onError,
|
|
167
|
+
settleMs,
|
|
168
|
+
describeError
|
|
169
|
+
});
|
|
170
|
+
React.useLayoutEffect(() => {
|
|
171
|
+
latest.current = {
|
|
172
|
+
action,
|
|
173
|
+
onError,
|
|
174
|
+
settleMs,
|
|
175
|
+
describeError
|
|
176
|
+
};
|
|
177
|
+
});
|
|
153
178
|
React.useEffect(() => () => window.clearTimeout(timer.current), []);
|
|
154
|
-
|
|
179
|
+
const run = React.useCallback(async (...args) => {
|
|
155
180
|
window.clearTimeout(timer.current);
|
|
156
|
-
|
|
181
|
+
setState({
|
|
182
|
+
phase: "pending",
|
|
183
|
+
error: void 0
|
|
184
|
+
});
|
|
157
185
|
try {
|
|
158
|
-
await action(...args);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
186
|
+
await latest.current.action(...args);
|
|
187
|
+
setState({
|
|
188
|
+
phase: "done",
|
|
189
|
+
error: void 0
|
|
190
|
+
});
|
|
191
|
+
timer.current = window.setTimeout(() => setState({
|
|
192
|
+
phase: "idle",
|
|
193
|
+
error: void 0
|
|
194
|
+
}), latest.current.settleMs);
|
|
195
|
+
} catch (thrown) {
|
|
196
|
+
unreported.current = { thrown };
|
|
197
|
+
setState({
|
|
198
|
+
phase: "error",
|
|
199
|
+
error: latest.current.describeError(thrown)
|
|
200
|
+
});
|
|
163
201
|
}
|
|
164
|
-
}, [
|
|
202
|
+
}, []);
|
|
203
|
+
React.useEffect(() => {
|
|
204
|
+
if (state.phase !== "error" || !unreported.current) return;
|
|
205
|
+
const { thrown } = unreported.current;
|
|
206
|
+
unreported.current = void 0;
|
|
207
|
+
latest.current.onError?.(thrown);
|
|
208
|
+
}, [state]);
|
|
209
|
+
return {
|
|
210
|
+
phase: state.phase,
|
|
211
|
+
run,
|
|
212
|
+
error: state.error
|
|
213
|
+
};
|
|
165
214
|
}
|
|
166
215
|
// src/components/field.tsx
|
|
167
216
|
var FieldContext = React.createContext(null);
|
|
@@ -173,6 +222,7 @@ function useField(id) {
|
|
|
173
222
|
"aria-invalid": field?.invalid || void 0
|
|
174
223
|
};
|
|
175
224
|
}
|
|
225
|
+
/** A labelled form field: wires the label, hint, error, `aria-describedby` and `aria-invalid` into the one control it wraps. */
|
|
176
226
|
function Field({ label, id: idProp, hint, error, children, className }) {
|
|
177
227
|
const generated = React.useId();
|
|
178
228
|
const id = idProp ?? generated;
|
|
@@ -212,6 +262,7 @@ function Field({ label, id: idProp, hint, error, children, className }) {
|
|
|
212
262
|
});
|
|
213
263
|
}
|
|
214
264
|
var control = "w-full min-w-0 rounded-control border border-input bg-background px-3 type-body text-foreground transition-state placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-70 aria-invalid:border-danger";
|
|
265
|
+
/** A text input that picks up its id and descriptions from the surrounding `Field`. */
|
|
215
266
|
function Input({ className, id, ...props }) {
|
|
216
267
|
return /* @__PURE__ */ jsx("input", {
|
|
217
268
|
...useField(id),
|
|
@@ -219,6 +270,7 @@ function Input({ className, id, ...props }) {
|
|
|
219
270
|
...props
|
|
220
271
|
});
|
|
221
272
|
}
|
|
273
|
+
/** A multi-line input that picks up its id and descriptions from the surrounding `Field`. */
|
|
222
274
|
function Textarea({ className, id, ...props }) {
|
|
223
275
|
return /* @__PURE__ */ jsx("textarea", {
|
|
224
276
|
...useField(id),
|
|
@@ -226,6 +278,7 @@ function Textarea({ className, id, ...props }) {
|
|
|
226
278
|
...props
|
|
227
279
|
});
|
|
228
280
|
}
|
|
281
|
+
/** The platform select, styled. The default for short lists, especially on touch screens. */
|
|
229
282
|
function NativeSelect({ className, id, ...props }) {
|
|
230
283
|
return /* @__PURE__ */ jsx("select", {
|
|
231
284
|
...useField(id),
|
|
@@ -233,6 +286,7 @@ function NativeSelect({ className, id, ...props }) {
|
|
|
233
286
|
...props
|
|
234
287
|
});
|
|
235
288
|
}
|
|
289
|
+
/** Radio choices in a fieldset with a legend; each whole row is the hit target. For 2 to 5 options that each need a sentence. */
|
|
236
290
|
function ChoiceGroup({ legend, name, choices, value, onChange, error }) {
|
|
237
291
|
const errorId = React.useId();
|
|
238
292
|
return /* @__PURE__ */ jsxs("fieldset", {
|
|
@@ -282,6 +336,7 @@ var tones = {
|
|
|
282
336
|
warning: "bg-warning-subtle text-warning",
|
|
283
337
|
danger: "bg-danger-subtle text-danger"
|
|
284
338
|
};
|
|
339
|
+
/** A status as a word on a pale tint of its tone, with an optional icon. Never colour alone. */
|
|
285
340
|
function Status({ tone, icon: Icon, children, className }) {
|
|
286
341
|
return /* @__PURE__ */ jsxs("span", {
|
|
287
342
|
className: cn("inline-flex items-center gap-1.5 whitespace-nowrap rounded-pill py-0.5 pr-2.5 pl-2 type-caption font-medium", tones[tone], className),
|
|
@@ -292,6 +347,7 @@ function Status({ tone, icon: Icon, children, className }) {
|
|
|
292
347
|
});
|
|
293
348
|
}
|
|
294
349
|
// src/components/metric.tsx
|
|
350
|
+
/** Headline figures as one description list split by hairlines. Holds `Metric`s. */
|
|
295
351
|
function MetricStrip({ label, children, className }) {
|
|
296
352
|
return /* @__PURE__ */ jsx("dl", {
|
|
297
353
|
"aria-label": label,
|
|
@@ -299,6 +355,7 @@ function MetricStrip({ label, children, className }) {
|
|
|
299
355
|
children
|
|
300
356
|
});
|
|
301
357
|
}
|
|
358
|
+
/** One figure: label over value, an optional muted unit and a note that states any change in words with its window. */
|
|
302
359
|
function Metric({ label, value, unit, note }) {
|
|
303
360
|
return /* @__PURE__ */ jsxs("div", {
|
|
304
361
|
className: "grid content-start gap-0.5 border-border py-3 not-first:border-t sm:px-5 sm:not-first:border-t-0 sm:first:pl-0",
|
|
@@ -322,6 +379,7 @@ function Metric({ label, value, unit, note }) {
|
|
|
322
379
|
});
|
|
323
380
|
}
|
|
324
381
|
// src/components/data-view.tsx
|
|
382
|
+
/** Every view of remote data: renders `skeleton` while loading, an alert with Try again on error, `empty` when `isEmpty`, else `children(data)`. The skeleton and empty state are required. */
|
|
325
383
|
function DataView({ state, isEmpty, skeleton, empty, children, className }) {
|
|
326
384
|
return /* @__PURE__ */ jsxs("div", {
|
|
327
385
|
className: cn("min-w-0", className),
|
|
@@ -351,6 +409,7 @@ function DataView({ state, isEmpty, skeleton, empty, children, className }) {
|
|
|
351
409
|
]
|
|
352
410
|
});
|
|
353
411
|
}
|
|
412
|
+
/** An empty state that teaches the next action: a title, a sentence and an action. No illustration slot, on purpose. */
|
|
354
413
|
function EmptyState({ title, children, action }) {
|
|
355
414
|
return /* @__PURE__ */ jsxs("div", {
|
|
356
415
|
className: "grid justify-items-start gap-2 border-y border-border py-6",
|
|
@@ -370,6 +429,7 @@ function EmptyState({ title, children, action }) {
|
|
|
370
429
|
]
|
|
371
430
|
});
|
|
372
431
|
}
|
|
432
|
+
/** A placeholder block for a loading layout. Size it with layout classes so it mirrors the final content. */
|
|
373
433
|
function Skeleton({ className }) {
|
|
374
434
|
return /* @__PURE__ */ jsx("div", {
|
|
375
435
|
"aria-hidden": true,
|
|
@@ -381,6 +441,7 @@ function useLocalSort(initial) {
|
|
|
381
441
|
const [sort, setSort] = React.useState(initial);
|
|
382
442
|
return [sort, setSort];
|
|
383
443
|
}
|
|
444
|
+
/** Reads a sort from its URL form (`pieces.desc`). */
|
|
384
445
|
function parseSort(value) {
|
|
385
446
|
if (!value) return void 0;
|
|
386
447
|
const [key, dir] = value.split(".");
|
|
@@ -390,6 +451,7 @@ function parseSort(value) {
|
|
|
390
451
|
dir: dir === "desc" ? "descending" : "ascending"
|
|
391
452
|
};
|
|
392
453
|
}
|
|
454
|
+
/** Writes a sort in its URL form (`pieces.desc`). */
|
|
393
455
|
function serialiseSort(sort) {
|
|
394
456
|
return `${sort.key}.${sort.dir === "descending" ? "desc" : "asc"}`;
|
|
395
457
|
}
|
|
@@ -401,6 +463,7 @@ function useUrlSort(param, initial) {
|
|
|
401
463
|
return out;
|
|
402
464
|
}, { replace: true }), [param, setParams])];
|
|
403
465
|
}
|
|
466
|
+
/** 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`). */
|
|
404
467
|
function DataTable(props) {
|
|
405
468
|
return props.sortParam ? /* @__PURE__ */ jsx(UrlSortedTable, {
|
|
406
469
|
...props,
|
|
@@ -529,6 +592,7 @@ function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], vir
|
|
|
529
592
|
})
|
|
530
593
|
});
|
|
531
594
|
}
|
|
595
|
+
/** The loading placeholder for a `DataTable`, shaped like its rows. */
|
|
532
596
|
function TableSkeleton({ rows = 4, columns = 5 }) {
|
|
533
597
|
return /* @__PURE__ */ jsxs("div", {
|
|
534
598
|
"aria-hidden": true,
|
|
@@ -543,6 +607,7 @@ function TableSkeleton({ rows = 4, columns = 5 }) {
|
|
|
543
607
|
});
|
|
544
608
|
}
|
|
545
609
|
// src/components/virtual-list.tsx
|
|
610
|
+
/** A list that renders only its visible rows (TanStack Virtual) from `virtualizeFrom` items, keeping list semantics for screen readers. */
|
|
546
611
|
function VirtualList({ label, items, itemKey, children, estimateSize = 48, height = 480, virtualizeFrom = 100, className }) {
|
|
547
612
|
const scroller = React.useRef(null);
|
|
548
613
|
const virtual = items.length >= virtualizeFrom;
|
|
@@ -618,6 +683,7 @@ function niceMax(max) {
|
|
|
618
683
|
10
|
|
619
684
|
].map((m) => m * mag).find((s) => s >= raw) ?? 10 * mag) * 4;
|
|
620
685
|
}
|
|
686
|
+
/** 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`. */
|
|
621
687
|
function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, formatX, formatY, xTicks, colour = "var(--chart-1)", colourScale, colourScaleLabel, height = 280, className }) {
|
|
622
688
|
const [ref, width] = useWidth();
|
|
623
689
|
const gradientId = `heat-${React.useId().replace(/[^\w-]/g, "")}`;
|
|
@@ -832,6 +898,7 @@ function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, fo
|
|
|
832
898
|
});
|
|
833
899
|
}
|
|
834
900
|
// src/components/page-header.tsx
|
|
901
|
+
/** The top of an Operate screen: a noun title, its scope, the main action, and the finding (the one fact in today's data that most needs attention). */
|
|
835
902
|
function PageHeader({ title, scope, actions, finding, as: Heading = "h1" }) {
|
|
836
903
|
return /* @__PURE__ */ jsxs("header", {
|
|
837
904
|
className: "grid gap-4",
|
|
@@ -860,6 +927,7 @@ function PageHeader({ title, scope, actions, finding, as: Heading = "h1" }) {
|
|
|
860
927
|
});
|
|
861
928
|
}
|
|
862
929
|
// src/components/undo.tsx
|
|
930
|
+
/** Schedules a reversible removal to commit after `windowMs` unless undone. A second removal, or unmounting, commits the pending one. */
|
|
863
931
|
function useUndoable(windowMs = 8e3) {
|
|
864
932
|
const [pending, setPending] = React.useState(null);
|
|
865
933
|
const current = React.useRef(null);
|
|
@@ -892,6 +960,7 @@ function useUndoable(windowMs = 8e3) {
|
|
|
892
960
|
undo
|
|
893
961
|
};
|
|
894
962
|
}
|
|
963
|
+
/** The polite live region that shows a pending removal with an Undo button. */
|
|
895
964
|
function UndoBar({ pending, onUndo, inline = false }) {
|
|
896
965
|
return /* @__PURE__ */ jsx("div", {
|
|
897
966
|
"aria-live": "polite",
|
|
@@ -912,6 +981,7 @@ function UndoBar({ pending, onUndo, inline = false }) {
|
|
|
912
981
|
});
|
|
913
982
|
}
|
|
914
983
|
// src/components/done.tsx
|
|
984
|
+
/** The completion moment for a rare, earned finish: what happened (past tense, with its object), what happens next, and optionally a figure drawn from the person's own data. Focus moves to the heading. */
|
|
915
985
|
function Done({ title, next, figure, actions, focusOnMount = true, className }) {
|
|
916
986
|
const heading = React.useRef(null);
|
|
917
987
|
const titleId = React.useId();
|
|
@@ -947,6 +1017,7 @@ function Done({ title, next, figure, actions, focusOnMount = true, className })
|
|
|
947
1017
|
});
|
|
948
1018
|
}
|
|
949
1019
|
// src/components/app-shell.tsx
|
|
1020
|
+
/** The app frame: product name, side nav on the page ground (a scrollable row on phones), optional top bar, and the main region. */
|
|
950
1021
|
function AppShell({ product, nav, navLabel = "Main", topBar, children, className }) {
|
|
951
1022
|
return /* @__PURE__ */ jsxs("div", {
|
|
952
1023
|
className: cn("min-h-dvh md:grid md:grid-cols-[14rem_minmax(0,1fr)]", className),
|
|
@@ -976,6 +1047,7 @@ function AppShell({ product, nav, navLabel = "Main", topBar, children, className
|
|
|
976
1047
|
})]
|
|
977
1048
|
});
|
|
978
1049
|
}
|
|
1050
|
+
/** Navigation links (React Router `NavLink`); the current route is a neutral pill with `aria-current`. */
|
|
979
1051
|
function SideNav({ items, label, className }) {
|
|
980
1052
|
return /* @__PURE__ */ jsx("nav", {
|
|
981
1053
|
"aria-label": label,
|
|
@@ -997,6 +1069,7 @@ function SideNav({ items, label, className }) {
|
|
|
997
1069
|
})
|
|
998
1070
|
});
|
|
999
1071
|
}
|
|
1072
|
+
/** Plain links separated by `/`; the last crumb is the current page. */
|
|
1000
1073
|
function Breadcrumb({ items }) {
|
|
1001
1074
|
return /* @__PURE__ */ jsx("nav", {
|
|
1002
1075
|
"aria-label": "Breadcrumb",
|
|
@@ -1024,6 +1097,7 @@ function Breadcrumb({ items }) {
|
|
|
1024
1097
|
});
|
|
1025
1098
|
}
|
|
1026
1099
|
// src/components/tabs.tsx
|
|
1100
|
+
/** Tabs whose selection lives in a URL search parameter (React Router), with the ARIA tabs keyboard model. */
|
|
1027
1101
|
function Tabs({ param, items, label, children, className }) {
|
|
1028
1102
|
const [params, setParams] = useSearchParams();
|
|
1029
1103
|
const fallback = items[0]?.value ?? "";
|
|
@@ -1080,6 +1154,6 @@ function Tabs({ param, items, label, children, className }) {
|
|
|
1080
1154
|
})]
|
|
1081
1155
|
});
|
|
1082
1156
|
}
|
|
1083
|
-
export { AppShell, AsyncButton, Breadcrumb, Button, ChoiceGroup, DataTable, DataView, Done, EmptyState, Field, HttpError, IconButton, Input, LineChart, Metric, MetricStrip, NBSP, NativeSelect, PageHeader, SideNav, Skeleton, Status, StrataQueryProvider, TableSkeleton, Tabs, Textarea, UndoBar, VirtualList, buttonVariants, cn, createFormat, createQueryClient, describeHttpError, fetchJson, format, parseSort, serialiseSort, toLoad, typeSteps, useAsyncAction, useLoad, useUndoable };
|
|
1157
|
+
export { AppShell, AsyncButton, Breadcrumb, Button, ChoiceGroup, DataTable, DataView, Done, EmptyState, Field, HttpError, IconButton, Input, LineChart, Metric, MetricStrip, NBSP, NativeSelect, PageHeader, SideNav, Skeleton, Status, StrataQueryProvider, TableSkeleton, Tabs, Textarea, UndoBar, VirtualList, buttonVariants, cn, createFormat, createQueryClient, describeActionError, describeHttpError, fetchJson, format, parseSort, serialiseSort, toLoad, typeSteps, useAsyncAction, useLoad, useUndoable };
|
|
1084
1158
|
|
|
1085
1159
|
//# sourceMappingURL=index.js.map
|