strata-react 0.1.3 → 0.1.5
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 +17 -7
- package/dist/components/async-button.d.ts +22 -4
- package/dist/components/theme.d.ts +51 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +79 -153
- package/dist/index.js.map +1 -1
- package/dist/lib/errors.d.ts +13 -0
- package/dist/lib/format.d.ts +30 -10
- package/dist/query/index.d.ts +2 -9
- package/dist/query-CmdlXVW_.js +345 -0
- package/dist/query-CmdlXVW_.js.map +1 -0
- package/dist/testing/index.d.ts +10 -3
- package/dist/testing/intersection-observer.d.ts +34 -0
- package/dist/testing/layout.d.ts +13 -0
- package/dist/testing.js +175 -9
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
- package/dist/query-DZVmYJSx.js +0 -72
- package/dist/query-DZVmYJSx.js.map +0 -1
package/README.md
CHANGED
|
@@ -44,18 +44,27 @@ kiln-room fixture).
|
|
|
44
44
|
|
|
45
45
|
```tsx
|
|
46
46
|
import { createBrowserRouter, RouterProvider } from "react-router";
|
|
47
|
-
import { StrataQueryProvider } from "strata-react";
|
|
47
|
+
import { StrataQueryProvider, ThemeProvider } from "strata-react";
|
|
48
48
|
import "./app.css";
|
|
49
49
|
|
|
50
50
|
const router = createBrowserRouter([{ path: "/", element: <KilnRoom /> }]);
|
|
51
51
|
|
|
52
52
|
createRoot(document.getElementById("root")!).render(
|
|
53
|
-
<
|
|
54
|
-
<
|
|
55
|
-
|
|
53
|
+
<ThemeProvider>
|
|
54
|
+
<StrataQueryProvider>
|
|
55
|
+
<RouterProvider router={router} />
|
|
56
|
+
</StrataQueryProvider>
|
|
57
|
+
</ThemeProvider>,
|
|
56
58
|
);
|
|
57
59
|
```
|
|
58
60
|
|
|
61
|
+
`ThemeProvider` sets the `.dark` class strata.css keys on. It follows the operating system until
|
|
62
|
+
a person chooses light or dark, keeps that choice in localStorage (and carries on without it when
|
|
63
|
+
storage is blocked), and follows a choice made in another tab. Put `<ColorSchemeChoice />` on the
|
|
64
|
+
settings page, or build your own control from `useColorScheme()`. So a dark page does not flash
|
|
65
|
+
light while the bundle loads, inline the pre-paint script in `index.html`'s `<head>`; generate it
|
|
66
|
+
once with `colorSchemeScript()` (it reads the same key the provider writes).
|
|
67
|
+
|
|
59
68
|
```tsx
|
|
60
69
|
// One question: "Is my work out of the kiln yet?"
|
|
61
70
|
function KilnRoom() {
|
|
@@ -80,15 +89,16 @@ function KilnRoom() {
|
|
|
80
89
|
|
|
81
90
|
| Group | Exports | Notes |
|
|
82
91
|
|---|---|---|
|
|
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 |
|
|
92
|
+
| Actions | `Button`, `IconButton`, `AsyncButton`, `useAsyncAction` | Default is `outline`; one filled button per view; `IconButton` requires `label`; `AsyncButton` keeps one width through idle, pending, done and error, and announces `error` with its retry label; `useAsyncAction` returns `{ phase, run, error }` with a stable `run`, and describes an `HttpError` in a sentence (`describeActionError`, or the product's own `describeError`) |
|
|
84
93
|
| Form | `Field`, `Input`, `Textarea`, `NativeSelect`, `ChoiceGroup` | `Field` wires label, hint, error, `aria-describedby`, `aria-invalid` |
|
|
85
94
|
| Status and figures | `Status`, `Metric`, `MetricStrip` | A status is always a word; figures have no icons or sparklines |
|
|
86
95
|
| Data | `DataView`, `Load<T>`, `EmptyState`, `Skeleton`, `DataTable`, `TableSkeleton`, `VirtualList`, `LineChart` | `DataView` requires skeleton and empty; tables and lists virtualise from 100 rows; charts label values directly |
|
|
87
96
|
| Data loading | `StrataQueryProvider`, `createQueryClient`, `useLoad`, `toLoad`, `fetchJson`, `HttpError` | TanStack Query in, `Load<T>` out |
|
|
88
97
|
| Page and navigation | `AppShell`, `SideNav`, `Breadcrumb`, `Tabs`, `PageHeader` | React Router; tab and sort state in the URL |
|
|
98
|
+
| Theme | `ThemeProvider`, `useColorScheme`, `useSystemColorScheme`, `ColorSchemeChoice`, `colorSchemeScript` | System, light or dark; sets `.dark`, persists in localStorage when it can; no picker beyond the settings-page radio group |
|
|
89
99
|
| Feedback | `UndoBar`, `useUndoable`, `Done` | Undo before confirm; `Done` is the one celebration, and it must say what happens next |
|
|
90
|
-
| Helpers | `cn`, `format`, `createFormat` | `cn` knows `type-*`; all numbers and dates through `Intl` |
|
|
91
|
-
| Testing | `strata-react/testing`: `renderWithStrata`, `createTestQueryClient` | Router + query client around Testing Library's `render` |
|
|
100
|
+
| Helpers | `cn`, `format`, `createFormat`, `NBSP` | `cn` knows `type-*`; all numbers and dates through `Intl`; `format.integer(n)`, `.decimal(n)`, `.percent(n)` are callable and keep Intl's methods; units and counts join with a non-breaking space |
|
|
101
|
+
| Testing | `strata-react/testing`: `renderWithStrata`, `createTestQueryClient`, `installLayoutShims`, `installFakeIntersectionObserver` | Router + query client around Testing Library's `render`; a fixed box and ResizeObserver so measuring components render in jsdom; an IntersectionObserver the test fires with `scrollToEnd()` or `intersect(el)`. Role names keep the non-breaking space from `format.count`, so match them with the same call or a `\s` regex |
|
|
92
102
|
|
|
93
103
|
Specs for the components not built yet (dialogs, sheets, menus, toasts, command menu, prose)
|
|
94
104
|
are in ux-research `ui-library/components.md`.
|
|
@@ -9,10 +9,28 @@ export type AsyncLabels = {
|
|
|
9
9
|
done: string;
|
|
10
10
|
error?: string;
|
|
11
11
|
};
|
|
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. */
|
|
13
|
-
export declare function AsyncButton({ phase, labels, disabled, ...props }: Omit<ButtonProps, "children"> & {
|
|
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"> & {
|
|
14
14
|
phase: Phase;
|
|
15
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;
|
|
16
18
|
}): React.JSX.Element;
|
|
17
|
-
/**
|
|
18
|
-
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>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/** What a person chose: follow the operating system, or a fixed light or dark theme. */
|
|
3
|
+
export type ColorSchemePreference = "system" | "light" | "dark";
|
|
4
|
+
/** The scheme in effect after "system" is resolved. */
|
|
5
|
+
export type ColorScheme = "light" | "dark";
|
|
6
|
+
/** The localStorage key `ThemeProvider` uses unless given another. */
|
|
7
|
+
export declare const COLOR_SCHEME_STORAGE_KEY = "strata-color-scheme";
|
|
8
|
+
/** The operating system's colour scheme, kept current as it changes. Light where it cannot be read (the server, jsdom). */
|
|
9
|
+
export declare function useSystemColorScheme(): ColorScheme;
|
|
10
|
+
/** What `useColorScheme` returns: the chosen preference, the scheme in effect, and a setter that persists the choice. */
|
|
11
|
+
export type ColorSchemeState = {
|
|
12
|
+
preference: ColorSchemePreference;
|
|
13
|
+
scheme: ColorScheme;
|
|
14
|
+
setPreference: (preference: ColorSchemePreference) => void;
|
|
15
|
+
};
|
|
16
|
+
/** 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
|
+
children: React.ReactNode;
|
|
19
|
+
/** The preference before a person has chosen one. */
|
|
20
|
+
defaultPreference?: ColorSchemePreference;
|
|
21
|
+
/** Where the choice is kept in localStorage; `null` keeps it for this visit only. */
|
|
22
|
+
storageKey?: string | null;
|
|
23
|
+
/**
|
|
24
|
+
* The element that gets the `.dark` class; the document's root element when left out. A nested
|
|
25
|
+
* target can turn a light page's panel dark, not the reverse: strata.css keys dark on any
|
|
26
|
+
* `.dark` ancestor. Pass the element itself (keep it in state with a callback ref, since a
|
|
27
|
+
* wrapping element's ref is not attached yet when this provider's effect first runs); `null`
|
|
28
|
+
* means it has not mounted yet, and nothing is set until it has.
|
|
29
|
+
*/
|
|
30
|
+
target?: HTMLElement | null;
|
|
31
|
+
}): React.JSX.Element;
|
|
32
|
+
/** The person's colour-scheme preference, the scheme in effect, and a setter that persists it. Must be inside `ThemeProvider`. */
|
|
33
|
+
export declare function useColorScheme(): ColorSchemeState;
|
|
34
|
+
/**
|
|
35
|
+
* The body of an inline `<script>` for the page's `<head>` that sets `.dark` before the first
|
|
36
|
+
* paint, from the stored choice or the operating system, so a dark page does not flash light while
|
|
37
|
+
* the bundle loads. Pass the same key and default as the `ThemeProvider`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function colorSchemeScript(storageKey?: string, defaultPreference?: ColorSchemePreference): string;
|
|
40
|
+
/** The words `ColorSchemeChoice` shows for each preference. */
|
|
41
|
+
export type ColorSchemeLabels = Record<ColorSchemePreference, {
|
|
42
|
+
label: string;
|
|
43
|
+
detail?: string;
|
|
44
|
+
}>;
|
|
45
|
+
/** The three colour-scheme preferences as radio buttons, bound to the nearest `ThemeProvider`. For a settings page. */
|
|
46
|
+
export declare function ColorSchemeChoice({ legend, labels, }: {
|
|
47
|
+
/** The group's name, as the settings page words it. */
|
|
48
|
+
legend?: string;
|
|
49
|
+
/** Overrides the words for each choice, in the product's voice. */
|
|
50
|
+
labels?: Partial<ColorSchemeLabels>;
|
|
51
|
+
}): React.JSX.Element;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* @module strata-react
|
|
7
7
|
*/
|
|
8
8
|
export { cn, typeSteps } from './lib/utils';
|
|
9
|
-
export { createFormat, format, NBSP, type Format } from './lib/format';
|
|
9
|
+
export { createFormat, format, NBSP, type Format, type NumberFormatter } from './lib/format';
|
|
10
10
|
export type { IconComponent } from './lib/icon';
|
|
11
11
|
export { Button, IconButton, buttonVariants, type ButtonProps, type IconButtonProps } from './components/button';
|
|
12
|
-
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';
|
|
13
13
|
export { Field, Input, Textarea, NativeSelect, ChoiceGroup, type FieldProps, type Choice } from './components/field';
|
|
14
14
|
export { Status, type Tone } from './components/status';
|
|
15
15
|
export { Metric, MetricStrip, type MetricProps } from './components/metric';
|
|
@@ -22,4 +22,6 @@ export { UndoBar, useUndoable, type PendingRemoval } from './components/undo';
|
|
|
22
22
|
export { Done } from './components/done';
|
|
23
23
|
export { AppShell, SideNav, Breadcrumb, type NavItem } from './components/app-shell';
|
|
24
24
|
export { Tabs, type TabItem } from './components/tabs';
|
|
25
|
+
export { ThemeProvider, useColorScheme, useSystemColorScheme, ColorSchemeChoice, colorSchemeScript, COLOR_SCHEME_STORAGE_KEY, type ColorScheme, type ColorSchemePreference, type ColorSchemeLabels, type ColorSchemeState, } from './components/theme';
|
|
25
26
|
export { StrataQueryProvider, createQueryClient, toLoad, useLoad, fetchJson, HttpError, describeHttpError, type DescribeError, } from './query';
|
|
27
|
+
export { describeActionError } from './lib/errors';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { clsx } from "clsx";
|
|
3
|
-
import { extendTailwindMerge } from "tailwind-merge";
|
|
1
|
+
import { _ as HttpError, a as useLoad, b as cn, c as ThemeProvider, d as useSystemColorScheme, f as ChoiceGroup, g as Textarea, h as NativeSelect, i as toLoad, l as colorSchemeScript, m as Input, n as createQueryClient, o as COLOR_SCHEME_STORAGE_KEY, p as Field, r as fetchJson, s as ColorSchemeChoice, t as StrataQueryProvider, u as useColorScheme, v as describeActionError, x as typeSteps, y as describeHttpError } from "./query-CmdlXVW_.js";
|
|
4
2
|
import * as React from "react";
|
|
5
3
|
import { Slot } from "@radix-ui/react-slot";
|
|
6
4
|
import { cva } from "class-variance-authority";
|
|
@@ -9,32 +7,24 @@ import { ArrowDown, ArrowUp, ArrowUpDown, Check, CircleAlert, LoaderCircle, Rota
|
|
|
9
7
|
import { flexRender, getCoreRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
|
|
10
8
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
11
9
|
import { Link, NavLink, useSearchParams } from "react-router";
|
|
12
|
-
// src/lib/utils.ts
|
|
13
|
-
var typeSteps = [
|
|
14
|
-
"caption",
|
|
15
|
-
"label",
|
|
16
|
-
"body-sm",
|
|
17
|
-
"body",
|
|
18
|
-
"heading",
|
|
19
|
-
"title",
|
|
20
|
-
"figure",
|
|
21
|
-
"display"
|
|
22
|
-
];
|
|
23
|
-
var twMerge = extendTailwindMerge({ extend: { classGroups: { "font-size": [{ type: [...typeSteps] }] } } });
|
|
24
|
-
/** clsx + tailwind-merge, taught that `type-*` utilities are font sizes. */
|
|
25
|
-
function cn(...inputs) {
|
|
26
|
-
return twMerge(clsx(inputs));
|
|
27
|
-
}
|
|
28
10
|
// src/lib/format.ts
|
|
29
11
|
var NBSP = "\xA0";
|
|
12
|
+
function callable(nf) {
|
|
13
|
+
const format = (value) => nf.format(value);
|
|
14
|
+
return Object.assign(format, {
|
|
15
|
+
format,
|
|
16
|
+
formatToParts: (value) => nf.formatToParts(value),
|
|
17
|
+
resolvedOptions: () => nf.resolvedOptions()
|
|
18
|
+
});
|
|
19
|
+
}
|
|
30
20
|
/** Intl formatters for one locale: integers, decimals, percent, times, days, units with a non-breaking space, and counted nouns. */
|
|
31
21
|
function createFormat(locale) {
|
|
32
|
-
const integer = new Intl.NumberFormat(locale, { maximumFractionDigits: 0 });
|
|
33
|
-
const decimal = new Intl.NumberFormat(locale, { maximumFractionDigits: 1 });
|
|
34
|
-
const percent = new Intl.NumberFormat(locale, {
|
|
22
|
+
const integer = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }));
|
|
23
|
+
const decimal = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }));
|
|
24
|
+
const percent = callable(new Intl.NumberFormat(locale, {
|
|
35
25
|
style: "percent",
|
|
36
26
|
maximumFractionDigits: 0
|
|
37
|
-
});
|
|
27
|
+
}));
|
|
38
28
|
const clock = new Intl.DateTimeFormat(locale, {
|
|
39
29
|
hour: "2-digit",
|
|
40
30
|
minute: "2-digit"
|
|
@@ -52,15 +42,24 @@ function createFormat(locale) {
|
|
|
52
42
|
const withUnit = (value, unit, fmt = integer) => `${fmt.format(value)} ${unit}`;
|
|
53
43
|
return {
|
|
54
44
|
locale,
|
|
45
|
+
/** Whole numbers with grouping: `format.integer(1222)` is "1,222". */
|
|
55
46
|
integer,
|
|
47
|
+
/** One decimal place at most: `format.decimal(3.14)` is "3.1". */
|
|
56
48
|
decimal,
|
|
49
|
+
/** A ratio as a whole percent: `format.percent(0.42)` is "42%". */
|
|
57
50
|
percent,
|
|
58
51
|
clock,
|
|
59
52
|
day,
|
|
60
53
|
shortDay,
|
|
54
|
+
/** A figure and its unit joined by a non-breaking space (`NBSP`), so they never wrap apart. */
|
|
61
55
|
withUnit,
|
|
56
|
+
/** A temperature in °C, joined by a non-breaking space. */
|
|
62
57
|
celsius: (value) => withUnit(value, "°C"),
|
|
63
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* "1 piece", "6 pieces": the count and its noun, so copy never reads "1 pieces". They are
|
|
60
|
+
* joined by a non-breaking space (`NBSP`), not a plain one: in a test, match with the same
|
|
61
|
+
* call or a `\s` regex, not a typed "6 pieces" string in a role's `name`.
|
|
62
|
+
*/
|
|
64
63
|
count: (value, one, many = `${one}s`) => `${integer.format(value)} ${new Intl.PluralRules(locale).select(value) === "one" ? one : many}`
|
|
65
64
|
};
|
|
66
65
|
}
|
|
@@ -111,8 +110,8 @@ function IconButton({ icon: Icon, label, variant = "ghost", ...props }) {
|
|
|
111
110
|
});
|
|
112
111
|
}
|
|
113
112
|
// src/components/async-button.tsx
|
|
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. */
|
|
115
|
-
function AsyncButton({ phase, labels, disabled, ...props }) {
|
|
113
|
+
/** 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. */
|
|
114
|
+
function AsyncButton({ phase, labels, error, disabled, ...props }) {
|
|
116
115
|
const errorLabel = labels.error ?? "Try again";
|
|
117
116
|
const current = {
|
|
118
117
|
idle: labels.idle,
|
|
@@ -126,6 +125,7 @@ function AsyncButton({ phase, labels, disabled, ...props }) {
|
|
|
126
125
|
done: Check,
|
|
127
126
|
error: CircleAlert
|
|
128
127
|
}[phase];
|
|
128
|
+
const announcement = phase === "done" ? labels.done : phase === "error" ? error ? `${error} ${errorLabel}` : errorLabel : "";
|
|
129
129
|
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Button, {
|
|
130
130
|
...props,
|
|
131
131
|
disabled: disabled || phase === "pending",
|
|
@@ -149,142 +149,68 @@ function AsyncButton({ phase, labels, disabled, ...props }) {
|
|
|
149
149
|
}), /* @__PURE__ */ jsx("span", {
|
|
150
150
|
role: "status",
|
|
151
151
|
className: "sr-only",
|
|
152
|
-
children:
|
|
152
|
+
children: announcement
|
|
153
153
|
})] });
|
|
154
154
|
}
|
|
155
|
-
/** Runs an async action and reports its phase. `done` returns to `idle` after `settleMs
|
|
156
|
-
function useAsyncAction(action, settleMs = 2e3) {
|
|
157
|
-
const [
|
|
155
|
+
/** Runs an async action and reports its phase and error. `done` returns to `idle` after `settleMs`; `run` never changes identity. */
|
|
156
|
+
function useAsyncAction(action, { settleMs = 2e3, onError, describeError = describeActionError } = {}) {
|
|
157
|
+
const [state, setState] = React.useState({
|
|
158
|
+
phase: "idle",
|
|
159
|
+
error: void 0
|
|
160
|
+
});
|
|
158
161
|
const timer = React.useRef(void 0);
|
|
162
|
+
const unreported = React.useRef(void 0);
|
|
163
|
+
const latest = React.useRef({
|
|
164
|
+
action,
|
|
165
|
+
onError,
|
|
166
|
+
settleMs,
|
|
167
|
+
describeError
|
|
168
|
+
});
|
|
169
|
+
React.useLayoutEffect(() => {
|
|
170
|
+
latest.current = {
|
|
171
|
+
action,
|
|
172
|
+
onError,
|
|
173
|
+
settleMs,
|
|
174
|
+
describeError
|
|
175
|
+
};
|
|
176
|
+
});
|
|
159
177
|
React.useEffect(() => () => window.clearTimeout(timer.current), []);
|
|
160
|
-
|
|
178
|
+
const run = React.useCallback(async (...args) => {
|
|
161
179
|
window.clearTimeout(timer.current);
|
|
162
|
-
|
|
180
|
+
setState({
|
|
181
|
+
phase: "pending",
|
|
182
|
+
error: void 0
|
|
183
|
+
});
|
|
163
184
|
try {
|
|
164
|
-
await action(...args);
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
185
|
+
await latest.current.action(...args);
|
|
186
|
+
setState({
|
|
187
|
+
phase: "done",
|
|
188
|
+
error: void 0
|
|
189
|
+
});
|
|
190
|
+
timer.current = window.setTimeout(() => setState({
|
|
191
|
+
phase: "idle",
|
|
192
|
+
error: void 0
|
|
193
|
+
}), latest.current.settleMs);
|
|
194
|
+
} catch (thrown) {
|
|
195
|
+
unreported.current = { thrown };
|
|
196
|
+
setState({
|
|
197
|
+
phase: "error",
|
|
198
|
+
error: latest.current.describeError(thrown)
|
|
199
|
+
});
|
|
169
200
|
}
|
|
170
|
-
}, [
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
201
|
+
}, []);
|
|
202
|
+
React.useEffect(() => {
|
|
203
|
+
if (state.phase !== "error" || !unreported.current) return;
|
|
204
|
+
const { thrown } = unreported.current;
|
|
205
|
+
unreported.current = void 0;
|
|
206
|
+
latest.current.onError?.(thrown);
|
|
207
|
+
}, [state]);
|
|
176
208
|
return {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
209
|
+
phase: state.phase,
|
|
210
|
+
run,
|
|
211
|
+
error: state.error
|
|
180
212
|
};
|
|
181
213
|
}
|
|
182
|
-
/** A labelled form field: wires the label, hint, error, `aria-describedby` and `aria-invalid` into the one control it wraps. */
|
|
183
|
-
function Field({ label, id: idProp, hint, error, children, className }) {
|
|
184
|
-
const generated = React.useId();
|
|
185
|
-
const id = idProp ?? generated;
|
|
186
|
-
const hintId = hint ? `${id}-hint` : void 0;
|
|
187
|
-
const errorId = error ? `${id}-error` : void 0;
|
|
188
|
-
const describedBy = [errorId, hintId].filter(Boolean).join(" ") || void 0;
|
|
189
|
-
return /* @__PURE__ */ jsx(FieldContext.Provider, {
|
|
190
|
-
value: {
|
|
191
|
-
id,
|
|
192
|
-
describedBy,
|
|
193
|
-
invalid: Boolean(error)
|
|
194
|
-
},
|
|
195
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
196
|
-
className: cn("grid min-w-0 content-start gap-1.5", className),
|
|
197
|
-
children: [
|
|
198
|
-
/* @__PURE__ */ jsx("label", {
|
|
199
|
-
htmlFor: id,
|
|
200
|
-
className: "type-label text-foreground",
|
|
201
|
-
children: label
|
|
202
|
-
}),
|
|
203
|
-
children,
|
|
204
|
-
error && /* @__PURE__ */ jsxs("p", {
|
|
205
|
-
id: errorId,
|
|
206
|
-
className: "flex items-start gap-1.5 type-body-sm text-danger",
|
|
207
|
-
children: [/* @__PURE__ */ jsx(CircleAlert, {
|
|
208
|
-
"aria-hidden": true,
|
|
209
|
-
className: "mt-0.5 size-4 shrink-0"
|
|
210
|
-
}), error]
|
|
211
|
-
}),
|
|
212
|
-
hint && /* @__PURE__ */ jsx("p", {
|
|
213
|
-
id: hintId,
|
|
214
|
-
className: "type-body-sm text-muted-foreground",
|
|
215
|
-
children: hint
|
|
216
|
-
})
|
|
217
|
-
]
|
|
218
|
-
})
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
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";
|
|
222
|
-
/** A text input that picks up its id and descriptions from the surrounding `Field`. */
|
|
223
|
-
function Input({ className, id, ...props }) {
|
|
224
|
-
return /* @__PURE__ */ jsx("input", {
|
|
225
|
-
...useField(id),
|
|
226
|
-
className: cn(control, "h-(--control-h)", className),
|
|
227
|
-
...props
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
/** A multi-line input that picks up its id and descriptions from the surrounding `Field`. */
|
|
231
|
-
function Textarea({ className, id, ...props }) {
|
|
232
|
-
return /* @__PURE__ */ jsx("textarea", {
|
|
233
|
-
...useField(id),
|
|
234
|
-
className: cn(control, "min-h-24 py-2", className),
|
|
235
|
-
...props
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
/** The platform select, styled. The default for short lists, especially on touch screens. */
|
|
239
|
-
function NativeSelect({ className, id, ...props }) {
|
|
240
|
-
return /* @__PURE__ */ jsx("select", {
|
|
241
|
-
...useField(id),
|
|
242
|
-
className: cn(control, "h-(--control-h) pr-8", className),
|
|
243
|
-
...props
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
/** 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. */
|
|
247
|
-
function ChoiceGroup({ legend, name, choices, value, onChange, error }) {
|
|
248
|
-
const errorId = React.useId();
|
|
249
|
-
return /* @__PURE__ */ jsxs("fieldset", {
|
|
250
|
-
className: "grid gap-2",
|
|
251
|
-
"aria-describedby": error ? errorId : void 0,
|
|
252
|
-
children: [
|
|
253
|
-
/* @__PURE__ */ jsx("legend", {
|
|
254
|
-
className: "mb-1.5 type-label text-foreground",
|
|
255
|
-
children: legend
|
|
256
|
-
}),
|
|
257
|
-
choices.map((c) => /* @__PURE__ */ jsxs("label", {
|
|
258
|
-
className: "flex min-h-(--control-h-sm) cursor-pointer items-start gap-3 py-1",
|
|
259
|
-
children: [/* @__PURE__ */ jsx("input", {
|
|
260
|
-
type: "radio",
|
|
261
|
-
name,
|
|
262
|
-
value: c.value,
|
|
263
|
-
checked: value === c.value,
|
|
264
|
-
onChange: () => onChange(c.value),
|
|
265
|
-
className: "mt-1 size-4 shrink-0 accent-primary"
|
|
266
|
-
}), /* @__PURE__ */ jsxs("span", {
|
|
267
|
-
className: "grid",
|
|
268
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
269
|
-
className: "type-body",
|
|
270
|
-
children: c.label
|
|
271
|
-
}), c.detail && /* @__PURE__ */ jsx("span", {
|
|
272
|
-
className: "type-body-sm text-muted-foreground",
|
|
273
|
-
children: c.detail
|
|
274
|
-
})]
|
|
275
|
-
})]
|
|
276
|
-
}, c.value)),
|
|
277
|
-
error && /* @__PURE__ */ jsxs("p", {
|
|
278
|
-
id: errorId,
|
|
279
|
-
className: "flex items-start gap-1.5 type-body-sm text-danger",
|
|
280
|
-
children: [/* @__PURE__ */ jsx(CircleAlert, {
|
|
281
|
-
"aria-hidden": true,
|
|
282
|
-
className: "mt-0.5 size-4 shrink-0"
|
|
283
|
-
}), error]
|
|
284
|
-
})
|
|
285
|
-
]
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
214
|
// src/components/status.tsx
|
|
289
215
|
var tones = {
|
|
290
216
|
neutral: "bg-muted text-muted-foreground",
|
|
@@ -1111,6 +1037,6 @@ function Tabs({ param, items, label, children, className }) {
|
|
|
1111
1037
|
})]
|
|
1112
1038
|
});
|
|
1113
1039
|
}
|
|
1114
|
-
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 };
|
|
1040
|
+
export { AppShell, AsyncButton, Breadcrumb, Button, COLOR_SCHEME_STORAGE_KEY, ChoiceGroup, ColorSchemeChoice, DataTable, DataView, Done, EmptyState, Field, HttpError, IconButton, Input, LineChart, Metric, MetricStrip, NBSP, NativeSelect, PageHeader, SideNav, Skeleton, Status, StrataQueryProvider, TableSkeleton, Tabs, Textarea, ThemeProvider, UndoBar, VirtualList, buttonVariants, cn, colorSchemeScript, createFormat, createQueryClient, describeActionError, describeHttpError, fetchJson, format, parseSort, serialiseSort, toLoad, typeSteps, useAsyncAction, useColorScheme, useLoad, useSystemColorScheme, useUndoable };
|
|
1115
1041
|
|
|
1116
1042
|
//# sourceMappingURL=index.js.map
|