strata-react 0.1.9 → 0.1.10
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 +4 -4
- package/dist/components/composition.d.ts +35 -0
- package/dist/components/link-card.d.ts +30 -0
- package/dist/components/meter.d.ts +32 -0
- package/dist/components/theme.d.ts +7 -3
- package/dist/index.d.ts +4 -1
- package/dist/index.js +276 -5
- package/dist/index.js.map +1 -1
- package/dist/lib/format.d.ts +19 -1
- package/dist/{query-5469ipOC.js → query-CkOrBm3w.js} +34 -5
- package/dist/query-CkOrBm3w.js.map +1 -0
- package/dist/testing.js +1 -1
- package/package.json +1 -1
- package/dist/query-5469ipOC.js.map +0 -1
package/README.md
CHANGED
|
@@ -118,15 +118,15 @@ function KilnRoom() {
|
|
|
118
118
|
|---|---|---|
|
|
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
|
-
| Status and figures | `Status`, `Metric`, `MetricStrip` | A status is always a word; figures have no icons or sparklines |
|
|
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
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
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
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 |
|
|
125
|
-
| Page and navigation | `AppShell`, `SideNav`, `Breadcrumb`, `Tabs`, `PageHeader` | React Router; tab and sort state in the URL |
|
|
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
|
-
| Theme | `ThemeProvider`, `useColorScheme`, `useSystemColorScheme`, `ColorSchemeChoice`, `colorSchemeScript` | System, light or dark; sets `.dark`, persists in localStorage when it can;
|
|
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 |
|
|
128
128
|
| Feedback | `UndoBar`, `useUndoable`, `Done` | Undo before confirm; the hook owns which rows are out of view (`isRemoved`), a failed commit brings the row back with Try again in the same bar, and `flush()` commits before a dependent action; `Done` is the one celebration, and it must say what happens next |
|
|
129
|
-
| 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 |
|
|
129
|
+
| Helpers | `cn`, `format`, `createFormat`, `NBSP` | `cn` knows `type-*`; all numbers and dates through `Intl`; `format.integer(n)`, `.decimal(n)`, `.percent(n)` are callable and keep Intl's methods; `format.bytes(n, unit?)` writes sizes in decimal units (`byteUnit` shares one unit across figures); units and counts join with a non-breaking space |
|
|
130
130
|
| 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 |
|
|
131
131
|
| Visual regression | `strata-react/visual` and the `strata-visual` command | Screenshots an app's Storybook and its routes in each MSW state, light and dark, against baselines in the app's repo |
|
|
132
132
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/** One part of a `CompositionBar`'s whole. */
|
|
3
|
+
export type CompositionPart = {
|
|
4
|
+
/** Stable key for the part. */
|
|
5
|
+
key: string;
|
|
6
|
+
label: string;
|
|
7
|
+
value: number;
|
|
8
|
+
/** CSS colour for the segment and swatch. Defaults to the chart token for its position. */
|
|
9
|
+
colour?: string;
|
|
10
|
+
};
|
|
11
|
+
export type CompositionBarProps = {
|
|
12
|
+
/** What the whole is, such as "Memory". Shown above the bar and names the table. */
|
|
13
|
+
label: string;
|
|
14
|
+
parts: CompositionPart[];
|
|
15
|
+
formatValue: (value: number) => string;
|
|
16
|
+
/** Formats a part's share of the whole (0 to 1). Defaults to `format.percent`. */
|
|
17
|
+
formatShare?: (share: number) => string;
|
|
18
|
+
/** Header of the parts column, for screen readers and over the table. Defaults to "Part". */
|
|
19
|
+
partHeader?: string;
|
|
20
|
+
/** Header of the amounts column. Defaults to "Amount". */
|
|
21
|
+
valueHeader?: string;
|
|
22
|
+
/** Header of the shares column. Defaults to "Share". */
|
|
23
|
+
shareHeader?: string;
|
|
24
|
+
className?: string;
|
|
25
|
+
} & ({
|
|
26
|
+
/** The size of the whole, when the parts do not fill it. The remainder is the empty track. */
|
|
27
|
+
total: number;
|
|
28
|
+
/** What the remainder is called ("Free", "Empty shelves"). Required with `total`. */
|
|
29
|
+
restLabel: string;
|
|
30
|
+
} | {
|
|
31
|
+
total?: undefined;
|
|
32
|
+
restLabel?: undefined;
|
|
33
|
+
});
|
|
34
|
+
/** What a whole is made of: a stacked bar for proportion and a table that names every part, its amount and its share, so colour is never the only cue. */
|
|
35
|
+
export declare function CompositionBar({ label, parts, formatValue, formatShare, partHeader, valueHeader, shareHeader, className, ...whole }: CompositionBarProps): React.JSX.Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { To } from 'react-router';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
/** A destination card's props: `to` for a route in this app, or `href` for anywhere else, never both. */
|
|
4
|
+
export type LinkCardProps = ({
|
|
5
|
+
/** A route in this app, followed with React Router. */
|
|
6
|
+
to: To;
|
|
7
|
+
href?: undefined;
|
|
8
|
+
} | {
|
|
9
|
+
/** Somewhere outside this app; the card shows an arrow. */
|
|
10
|
+
href: string;
|
|
11
|
+
to?: undefined;
|
|
12
|
+
}) & {
|
|
13
|
+
/** The destination's name, and the link's accessible name. */
|
|
14
|
+
title: string;
|
|
15
|
+
/** One sentence on what is there. Read as the link's description. */
|
|
16
|
+
description?: string;
|
|
17
|
+
/** `Status` words about the destination ("Running", "Updated today"). Nothing interactive. */
|
|
18
|
+
marks?: React.ReactNode;
|
|
19
|
+
/** The title's element. h3 under a section heading; h2 when the cards are the page's sections. */
|
|
20
|
+
as?: "h2" | "h3" | "h4";
|
|
21
|
+
className?: string;
|
|
22
|
+
};
|
|
23
|
+
/** A destination as a card that is one link: its title is the link's name, the description and status marks are its description, and the whole card is the target. */
|
|
24
|
+
export declare function LinkCard({ title, description, marks, as: Heading, className, ...destination }: LinkCardProps): React.JSX.Element;
|
|
25
|
+
/** A labelled list of `LinkCard`s in a grid: one column on a phone, up to three on a wide screen. */
|
|
26
|
+
export declare function LinkCardList({ label, children, className }: {
|
|
27
|
+
label: string;
|
|
28
|
+
children: React.ReactNode;
|
|
29
|
+
className?: string;
|
|
30
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/** A level on a `Meter` at which the reading changes state, with the word for that state. */
|
|
3
|
+
export type MeterThreshold = {
|
|
4
|
+
/** A share of `max`, from 0 to 1: 0.8 is 80%. */
|
|
5
|
+
at: number;
|
|
6
|
+
tone: "warning" | "danger";
|
|
7
|
+
/** What the state is called, in the product's words: "Filling up", "Nearly full". */
|
|
8
|
+
label: string;
|
|
9
|
+
};
|
|
10
|
+
export type MeterProps = {
|
|
11
|
+
/** What is measured, such as "Disk /". The meter's accessible name. */
|
|
12
|
+
label: string;
|
|
13
|
+
value: number;
|
|
14
|
+
/** The full scale, in the same units as `value`. Defaults to 1, so a share can be passed as is. */
|
|
15
|
+
max?: number;
|
|
16
|
+
/** The reading in words, shown beside the bar and used as `aria-valuetext`. Defaults to "72% used". */
|
|
17
|
+
valueText?: string;
|
|
18
|
+
/** A second line of fact, such as "36 of 50 GB". */
|
|
19
|
+
detail?: React.ReactNode;
|
|
20
|
+
thresholds?: MeterThreshold[];
|
|
21
|
+
/** "lower" when an emptier reading is the worse one (a battery, credit left). */
|
|
22
|
+
worseWhen?: "higher" | "lower";
|
|
23
|
+
/** Keeps the label as the accessible name only, for a meter in a table row that names it. */
|
|
24
|
+
hideLabel?: boolean;
|
|
25
|
+
/** CSS colour for the fill below every threshold. Defaults to the first chart token. */
|
|
26
|
+
colour?: string;
|
|
27
|
+
className?: string;
|
|
28
|
+
};
|
|
29
|
+
/** The threshold a share has crossed, if any: the most severe one reached in the worse direction. */
|
|
30
|
+
export declare function crossedThreshold(share: number, thresholds?: readonly MeterThreshold[], worseWhen?: "higher" | "lower"): MeterThreshold | undefined;
|
|
31
|
+
/** How full one thing is: a labelled `meter` with its reading in words, threshold notches, and a status word once a threshold is crossed. */
|
|
32
|
+
export declare function Meter({ label, value, max, valueText, detail, thresholds, worseWhen, hideLabel, colour, className, }: MeterProps): React.JSX.Element;
|
|
@@ -42,10 +42,14 @@ export type ColorSchemeLabels = Record<ColorSchemePreference, {
|
|
|
42
42
|
label: string;
|
|
43
43
|
detail?: string;
|
|
44
44
|
}>;
|
|
45
|
-
/** The three colour-scheme preferences as radio buttons, bound to the nearest `ThemeProvider`.
|
|
46
|
-
export declare function ColorSchemeChoice({ legend, labels, }: {
|
|
47
|
-
/** The group's name, as the
|
|
45
|
+
/** The three colour-scheme preferences as radio buttons, bound to the nearest `ThemeProvider`. A list for a settings page, or `compact` icon segments named "Appearance" for a header. */
|
|
46
|
+
export declare function ColorSchemeChoice({ legend, labels, compact, className, }: {
|
|
47
|
+
/** The group's name, as the page words it. Defaults to "Theme", or "Appearance" when `compact`. */
|
|
48
48
|
legend?: string;
|
|
49
49
|
/** Overrides the words for each choice, in the product's voice. */
|
|
50
50
|
labels?: Partial<ColorSchemeLabels>;
|
|
51
|
+
/** Three icon segments for a header or footer, for an app with no settings page. */
|
|
52
|
+
compact?: boolean;
|
|
53
|
+
/** Layout at the call site (compact only). */
|
|
54
|
+
className?: string;
|
|
51
55
|
}): React.JSX.Element;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @module strata-react
|
|
7
7
|
*/
|
|
8
8
|
export { cn, typeSteps } from './lib/utils';
|
|
9
|
-
export { createFormat, format, NBSP, type Format, type NumberFormatter } from './lib/format';
|
|
9
|
+
export { createFormat, format, NBSP, type ByteUnit, type Format, 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
12
|
export { Checkbox, type CheckboxProps } from './components/checkbox';
|
|
@@ -14,6 +14,9 @@ export { AsyncButton, useAsyncAction, type Phase, type AsyncLabels, type AsyncAc
|
|
|
14
14
|
export { Field, Input, Textarea, NativeSelect, ChoiceGroup, type FieldProps, type Choice } from './components/field';
|
|
15
15
|
export { Status, type Tone } from './components/status';
|
|
16
16
|
export { Metric, MetricStrip, type MetricProps } from './components/metric';
|
|
17
|
+
export { Meter, crossedThreshold, type MeterProps, type MeterThreshold } from './components/meter';
|
|
18
|
+
export { CompositionBar, type CompositionBarProps, type CompositionPart } from './components/composition';
|
|
19
|
+
export { LinkCard, LinkCardList, type LinkCardProps } from './components/link-card';
|
|
17
20
|
export { DataView, EmptyState, Skeleton, type Load } from './components/data-view';
|
|
18
21
|
export { DataTable, TableSkeleton, parseSort, serialiseSort, type Column, type Sort, type DataTableProps, type RowSelection, } from './components/data-table';
|
|
19
22
|
export { BulkBar, useSelection } from './components/selection';
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
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-
|
|
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-CkOrBm3w.js";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { Slot } from "@radix-ui/react-slot";
|
|
4
4
|
import { cva } from "class-variance-authority";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import { ArrowDown, ArrowUp, ArrowUpDown, Check, CircleAlert, LoaderCircle, RotateCcw, X } from "lucide-react";
|
|
6
|
+
import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Check, CircleAlert, LoaderCircle, RotateCcw, X } from "lucide-react";
|
|
7
|
+
import { Link, NavLink, useSearchParams } from "react-router";
|
|
7
8
|
import { flexRender, getCoreRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
|
|
8
9
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
9
|
-
import { Link, NavLink, useSearchParams } from "react-router";
|
|
10
10
|
import { hashKey, useInfiniteQuery } from "@tanstack/react-query";
|
|
11
11
|
// src/lib/format.ts
|
|
12
12
|
var NBSP = "\xA0";
|
|
13
|
+
var BYTE_UNITS = [
|
|
14
|
+
"B",
|
|
15
|
+
"kB",
|
|
16
|
+
"MB",
|
|
17
|
+
"GB",
|
|
18
|
+
"TB",
|
|
19
|
+
"PB"
|
|
20
|
+
];
|
|
21
|
+
var BYTE_SIZE = Object.fromEntries(BYTE_UNITS.map((u, i) => [u, 1e3 ** i]));
|
|
13
22
|
function callable(nf) {
|
|
14
23
|
const format = (value) => nf.format(value);
|
|
15
24
|
return Object.assign(format, {
|
|
@@ -18,7 +27,7 @@ function callable(nf) {
|
|
|
18
27
|
resolvedOptions: () => nf.resolvedOptions()
|
|
19
28
|
});
|
|
20
29
|
}
|
|
21
|
-
/** Intl formatters for one locale: integers, decimals, percent, times, days, units with a non-breaking space, and counted nouns. */
|
|
30
|
+
/** Intl formatters for one locale: integers, decimals, percent, times, days, units with a non-breaking space, byte sizes, and counted nouns. */
|
|
22
31
|
function createFormat(locale) {
|
|
23
32
|
const integer = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }));
|
|
24
33
|
const decimal = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }));
|
|
@@ -57,6 +66,18 @@ function createFormat(locale) {
|
|
|
57
66
|
/** A temperature in °C, joined by a non-breaking space. */
|
|
58
67
|
celsius: (value) => withUnit(value, "°C"),
|
|
59
68
|
/**
|
|
69
|
+
* A size in bytes in the largest decimal unit it reaches (kB, MB, GB, TB, as disks and
|
|
70
|
+
* networks are sold): one decimal below 10 ("5.2 GB"), whole above ("431 GB"). Pass `unit`
|
|
71
|
+
* to fix the unit, so figures compared side by side ("431 of 466 GB") share one.
|
|
72
|
+
*/
|
|
73
|
+
bytes: (value, unit) => {
|
|
74
|
+
const chosen = unit ?? [...BYTE_UNITS].reverse().find((u) => Math.abs(value) >= BYTE_SIZE[u]) ?? "B";
|
|
75
|
+
const scaled = value / BYTE_SIZE[chosen];
|
|
76
|
+
return withUnit(scaled, chosen, Math.abs(scaled) < 10 && chosen !== "B" ? decimal : integer);
|
|
77
|
+
},
|
|
78
|
+
/** The unit `bytes` would choose for a value, to share it across a set of figures. */
|
|
79
|
+
byteUnit: (value) => [...BYTE_UNITS].reverse().find((u) => Math.abs(value) >= BYTE_SIZE[u]) ?? "B",
|
|
80
|
+
/**
|
|
60
81
|
* "1 piece", "6 pieces": the count and its noun, so copy never reads "1 pieces". They are
|
|
61
82
|
* joined by a non-breaking space (`NBSP`), not a plain one: in a test, match with the same
|
|
62
83
|
* call or a `\s` regex, not a typed "6 pieces" string in a role's `name`.
|
|
@@ -304,6 +325,256 @@ function Metric({ label, value, unit, note }) {
|
|
|
304
325
|
]
|
|
305
326
|
});
|
|
306
327
|
}
|
|
328
|
+
// src/components/meter.tsx
|
|
329
|
+
/** The threshold a share has crossed, if any: the most severe one reached in the worse direction. */
|
|
330
|
+
function crossedThreshold(share, thresholds = [], worseWhen = "higher") {
|
|
331
|
+
return thresholds.filter((t) => worseWhen === "higher" ? share >= t.at : share <= t.at).sort((a, b) => worseWhen === "higher" ? b.at - a.at : a.at - b.at)[0];
|
|
332
|
+
}
|
|
333
|
+
var fills = {
|
|
334
|
+
warning: "var(--warning)",
|
|
335
|
+
danger: "var(--danger)"
|
|
336
|
+
};
|
|
337
|
+
/** How full one thing is: a labelled `meter` with its reading in words, threshold notches, and a status word once a threshold is crossed. */
|
|
338
|
+
function Meter({ label, value, max = 1, valueText, detail, thresholds, worseWhen = "higher", hideLabel = false, colour = "var(--chart-1)", className }) {
|
|
339
|
+
const labelId = React.useId();
|
|
340
|
+
const statusId = React.useId();
|
|
341
|
+
const detailId = React.useId();
|
|
342
|
+
const share = max > 0 ? Math.min(1, Math.max(0, value / max)) : 0;
|
|
343
|
+
const crossed = crossedThreshold(share, thresholds, worseWhen);
|
|
344
|
+
const text = valueText ?? `${format.percent(share)} used`;
|
|
345
|
+
const hasNote = Boolean(crossed || detail);
|
|
346
|
+
const describedBy = [crossed && statusId, detail && detailId].filter(Boolean).join(" ") || void 0;
|
|
347
|
+
const bar = /* @__PURE__ */ jsxs("div", {
|
|
348
|
+
role: "meter",
|
|
349
|
+
"aria-labelledby": hideLabel ? void 0 : labelId,
|
|
350
|
+
"aria-label": hideLabel ? label : void 0,
|
|
351
|
+
"aria-valuemin": 0,
|
|
352
|
+
"aria-valuemax": max,
|
|
353
|
+
"aria-valuenow": Math.min(max, Math.max(0, value)),
|
|
354
|
+
"aria-valuetext": text,
|
|
355
|
+
"aria-describedby": describedBy,
|
|
356
|
+
className: "relative h-2 min-w-16 flex-1 overflow-hidden rounded-pill bg-muted",
|
|
357
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
358
|
+
className: "absolute inset-y-0 left-0",
|
|
359
|
+
style: {
|
|
360
|
+
width: `${share * 100}%`,
|
|
361
|
+
background: crossed ? fills[crossed.tone] : colour
|
|
362
|
+
}
|
|
363
|
+
}), thresholds?.map((t) => /* @__PURE__ */ jsx("div", {
|
|
364
|
+
className: "absolute inset-y-0 w-0.5 -translate-x-1/2 bg-background",
|
|
365
|
+
style: { left: `${Math.min(1, Math.max(0, t.at)) * 100}%` }
|
|
366
|
+
}, t.at))]
|
|
367
|
+
});
|
|
368
|
+
const figure = /* @__PURE__ */ jsx("span", {
|
|
369
|
+
"aria-hidden": true,
|
|
370
|
+
className: "shrink-0 type-body-sm tabular-nums text-foreground",
|
|
371
|
+
children: text
|
|
372
|
+
});
|
|
373
|
+
const note = hasNote && /* @__PURE__ */ jsxs("div", {
|
|
374
|
+
className: "flex flex-wrap items-center gap-x-3 gap-y-1",
|
|
375
|
+
children: [crossed && /* @__PURE__ */ jsx("span", {
|
|
376
|
+
id: statusId,
|
|
377
|
+
className: "contents",
|
|
378
|
+
children: /* @__PURE__ */ jsx(Status, {
|
|
379
|
+
tone: crossed.tone,
|
|
380
|
+
children: crossed.label
|
|
381
|
+
})
|
|
382
|
+
}), detail && /* @__PURE__ */ jsx("span", {
|
|
383
|
+
id: detailId,
|
|
384
|
+
className: "type-body-sm text-muted-foreground tabular-nums",
|
|
385
|
+
children: detail
|
|
386
|
+
})]
|
|
387
|
+
});
|
|
388
|
+
if (hideLabel) return /* @__PURE__ */ jsxs("div", {
|
|
389
|
+
className: cn("grid min-w-0 gap-1.5", className),
|
|
390
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
391
|
+
className: "flex items-center gap-3",
|
|
392
|
+
children: [bar, figure]
|
|
393
|
+
}), note]
|
|
394
|
+
});
|
|
395
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
396
|
+
className: cn("grid min-w-0 gap-1.5", className),
|
|
397
|
+
children: [
|
|
398
|
+
/* @__PURE__ */ jsxs("div", {
|
|
399
|
+
className: "flex items-baseline justify-between gap-3",
|
|
400
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
401
|
+
id: labelId,
|
|
402
|
+
className: "min-w-0 truncate type-label text-foreground",
|
|
403
|
+
children: label
|
|
404
|
+
}), figure]
|
|
405
|
+
}),
|
|
406
|
+
/* @__PURE__ */ jsx("div", {
|
|
407
|
+
className: "flex",
|
|
408
|
+
children: bar
|
|
409
|
+
}),
|
|
410
|
+
note
|
|
411
|
+
]
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
// src/components/composition.tsx
|
|
415
|
+
var MAX_TOKENS = 5;
|
|
416
|
+
/** A part's colour: its own, or the chart token for its position. Throws past the fifth token. */
|
|
417
|
+
function colourFor(part, index) {
|
|
418
|
+
if (part.colour) return part.colour;
|
|
419
|
+
if (index >= MAX_TOKENS) throw new Error(`CompositionBar: part "${part.label}" is number ${index + 1}, and there are only ${MAX_TOKENS} chart colours. Combine the smallest parts into one "Other" part, or give this part a colour.`);
|
|
420
|
+
return `var(--chart-${index + 1})`;
|
|
421
|
+
}
|
|
422
|
+
/** What a whole is made of: a stacked bar for proportion and a table that names every part, its amount and its share, so colour is never the only cue. */
|
|
423
|
+
function CompositionBar({ label, parts, formatValue, formatShare = format.percent, partHeader = "Part", valueHeader = "Amount", shareHeader = "Share", className, ...whole }) {
|
|
424
|
+
const captionId = React.useId();
|
|
425
|
+
const sum = parts.reduce((n, p) => n + Math.max(0, p.value), 0);
|
|
426
|
+
const total = Math.max(whole.total ?? sum, sum);
|
|
427
|
+
const rest = whole.total !== void 0 ? total - sum : 0;
|
|
428
|
+
const shareOf = (value) => total > 0 ? Math.max(0, value) / total : 0;
|
|
429
|
+
const rows = parts.map((p, i) => ({
|
|
430
|
+
...p,
|
|
431
|
+
colour: colourFor(p, i),
|
|
432
|
+
share: shareOf(p.value)
|
|
433
|
+
}));
|
|
434
|
+
return /* @__PURE__ */ jsxs("figure", {
|
|
435
|
+
className: cn("grid min-w-0 gap-3", className),
|
|
436
|
+
children: [
|
|
437
|
+
/* @__PURE__ */ jsx("figcaption", {
|
|
438
|
+
id: captionId,
|
|
439
|
+
className: "type-label text-foreground",
|
|
440
|
+
children: label
|
|
441
|
+
}),
|
|
442
|
+
/* @__PURE__ */ jsxs("div", {
|
|
443
|
+
"aria-hidden": true,
|
|
444
|
+
className: "flex h-3 gap-0.5 overflow-hidden rounded-pill bg-muted",
|
|
445
|
+
children: [rows.filter((r) => r.value > 0).map((r) => /* @__PURE__ */ jsx("div", {
|
|
446
|
+
className: "h-full min-w-0",
|
|
447
|
+
style: {
|
|
448
|
+
flex: `${r.share} 1 0`,
|
|
449
|
+
background: r.colour
|
|
450
|
+
}
|
|
451
|
+
}, r.key)), rest > 0 && /* @__PURE__ */ jsx("div", {
|
|
452
|
+
className: "h-full min-w-0",
|
|
453
|
+
style: { flex: `${shareOf(rest)} 1 0` }
|
|
454
|
+
})]
|
|
455
|
+
}),
|
|
456
|
+
/* @__PURE__ */ jsxs("table", {
|
|
457
|
+
"aria-labelledby": captionId,
|
|
458
|
+
className: "w-full border-collapse type-body-sm",
|
|
459
|
+
children: [/* @__PURE__ */ jsx("thead", {
|
|
460
|
+
className: "sr-only",
|
|
461
|
+
children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
462
|
+
/* @__PURE__ */ jsx("th", {
|
|
463
|
+
scope: "col",
|
|
464
|
+
children: partHeader
|
|
465
|
+
}),
|
|
466
|
+
/* @__PURE__ */ jsx("th", {
|
|
467
|
+
scope: "col",
|
|
468
|
+
children: valueHeader
|
|
469
|
+
}),
|
|
470
|
+
/* @__PURE__ */ jsx("th", {
|
|
471
|
+
scope: "col",
|
|
472
|
+
children: shareHeader
|
|
473
|
+
})
|
|
474
|
+
] })
|
|
475
|
+
}), /* @__PURE__ */ jsxs("tbody", { children: [rows.map((r) => /* @__PURE__ */ jsxs("tr", {
|
|
476
|
+
className: "border-t border-border first:border-t-0",
|
|
477
|
+
children: [
|
|
478
|
+
/* @__PURE__ */ jsx("th", {
|
|
479
|
+
scope: "row",
|
|
480
|
+
className: "py-1.5 pr-4 text-left font-normal",
|
|
481
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
482
|
+
className: "inline-flex items-center gap-2",
|
|
483
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
484
|
+
"aria-hidden": true,
|
|
485
|
+
className: "size-3 shrink-0 rounded-control",
|
|
486
|
+
style: { background: r.colour }
|
|
487
|
+
}), r.label]
|
|
488
|
+
})
|
|
489
|
+
}),
|
|
490
|
+
/* @__PURE__ */ jsx("td", {
|
|
491
|
+
className: "py-1.5 pr-4 text-right tabular-nums",
|
|
492
|
+
children: formatValue(r.value)
|
|
493
|
+
}),
|
|
494
|
+
/* @__PURE__ */ jsx("td", {
|
|
495
|
+
className: "w-px py-1.5 text-right whitespace-nowrap text-muted-foreground tabular-nums",
|
|
496
|
+
children: formatShare(r.share)
|
|
497
|
+
})
|
|
498
|
+
]
|
|
499
|
+
}, r.key)), whole.total !== void 0 && /* @__PURE__ */ jsxs("tr", {
|
|
500
|
+
className: "border-t border-border",
|
|
501
|
+
children: [
|
|
502
|
+
/* @__PURE__ */ jsx("th", {
|
|
503
|
+
scope: "row",
|
|
504
|
+
className: "py-1.5 pr-4 text-left font-normal",
|
|
505
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
506
|
+
className: "inline-flex items-center gap-2",
|
|
507
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
508
|
+
"aria-hidden": true,
|
|
509
|
+
className: "size-3 shrink-0 rounded-control border border-border bg-muted"
|
|
510
|
+
}), whole.restLabel]
|
|
511
|
+
})
|
|
512
|
+
}),
|
|
513
|
+
/* @__PURE__ */ jsx("td", {
|
|
514
|
+
className: "py-1.5 pr-4 text-right tabular-nums",
|
|
515
|
+
children: formatValue(rest)
|
|
516
|
+
}),
|
|
517
|
+
/* @__PURE__ */ jsx("td", {
|
|
518
|
+
className: "w-px py-1.5 text-right whitespace-nowrap text-muted-foreground tabular-nums",
|
|
519
|
+
children: formatShare(shareOf(rest))
|
|
520
|
+
})
|
|
521
|
+
]
|
|
522
|
+
})] })]
|
|
523
|
+
})
|
|
524
|
+
]
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
// src/components/link-card.tsx
|
|
528
|
+
/** A destination as a card that is one link: its title is the link's name, the description and status marks are its description, and the whole card is the target. */
|
|
529
|
+
function LinkCard({ title, description, marks, as: Heading = "h3", className, ...destination }) {
|
|
530
|
+
const descriptionId = React.useId();
|
|
531
|
+
const marksId = React.useId();
|
|
532
|
+
const describedBy = [description && descriptionId, marks && marksId].filter(Boolean).join(" ") || void 0;
|
|
533
|
+
const linkClass = "rounded-control outline-none after:absolute after:inset-0 after:rounded-surface";
|
|
534
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
535
|
+
className: cn("relative grid content-start gap-1.5 rounded-surface border border-border bg-background p-4 transition-state", "hover:border-muted-foreground has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-ring", className),
|
|
536
|
+
children: [
|
|
537
|
+
/* @__PURE__ */ jsx(Heading, {
|
|
538
|
+
className: "flex items-start justify-between gap-3 type-heading text-foreground",
|
|
539
|
+
children: destination.href !== void 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("a", {
|
|
540
|
+
href: destination.href,
|
|
541
|
+
"aria-describedby": describedBy,
|
|
542
|
+
className: linkClass,
|
|
543
|
+
children: title
|
|
544
|
+
}), /* @__PURE__ */ jsx(ArrowUpRight, {
|
|
545
|
+
"aria-hidden": true,
|
|
546
|
+
className: "mt-0.5 size-4 shrink-0 text-muted-foreground"
|
|
547
|
+
})] }) : /* @__PURE__ */ jsx(Link, {
|
|
548
|
+
to: destination.to,
|
|
549
|
+
"aria-describedby": describedBy,
|
|
550
|
+
className: linkClass,
|
|
551
|
+
children: title
|
|
552
|
+
})
|
|
553
|
+
}),
|
|
554
|
+
description && /* @__PURE__ */ jsx("p", {
|
|
555
|
+
id: descriptionId,
|
|
556
|
+
className: "type-body-sm text-pretty text-muted-foreground",
|
|
557
|
+
children: description
|
|
558
|
+
}),
|
|
559
|
+
marks && /* @__PURE__ */ jsx("div", {
|
|
560
|
+
id: marksId,
|
|
561
|
+
className: "mt-1.5 flex flex-wrap gap-2",
|
|
562
|
+
children: marks
|
|
563
|
+
})
|
|
564
|
+
]
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
/** A labelled list of `LinkCard`s in a grid: one column on a phone, up to three on a wide screen. */
|
|
568
|
+
function LinkCardList({ label, children, className }) {
|
|
569
|
+
return /* @__PURE__ */ jsx("ul", {
|
|
570
|
+
"aria-label": label,
|
|
571
|
+
className: cn("grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3", className),
|
|
572
|
+
children: React.Children.toArray(children).map((child, i) => /* @__PURE__ */ jsx("li", {
|
|
573
|
+
className: "grid",
|
|
574
|
+
children: child
|
|
575
|
+
}, React.isValidElement(child) && child.key != null ? child.key : i))
|
|
576
|
+
});
|
|
577
|
+
}
|
|
307
578
|
// src/components/data-view.tsx
|
|
308
579
|
/** 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. */
|
|
309
580
|
function DataView({ state, isEmpty, skeleton, empty, children, className }) {
|
|
@@ -1815,6 +2086,6 @@ function nextAfter(pages, items, itemKey, hidden) {
|
|
|
1815
2086
|
if (held.length === 0 || pages.length > 1 && !lastPageAddedAny) return last;
|
|
1816
2087
|
return held[held.length - 1];
|
|
1817
2088
|
}
|
|
1818
|
-
export { ActiveList, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorSchemeChoice, DataTable, DataView, Done, EmptyState, Field, HttpError, IconButton, InfiniteList, Input, KeysLegend, LineChart, Metric, MetricStrip, NBSP, NativeSelect, PageHeader, RowAction, SideNav, Skeleton, Status, StrataQueryProvider, TableSkeleton, Tabs, Textarea, ThemeProvider, UndoBar, VirtualList, buttonVariants, cn, colorSchemeScript, createFormat, createQueryClient, describeActionError, describeHttpError, fetchJson, format, isTypingTarget, parseSort, serialiseSort, toLoad, typeSteps, useActiveItem, useAsyncAction, useColorScheme, useHotkeys, useInfiniteLoad, useLoad, useSelection, useSystemColorScheme, useUndoable };
|
|
2089
|
+
export { ActiveList, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorSchemeChoice, CompositionBar, DataTable, DataView, Done, EmptyState, Field, HttpError, IconButton, InfiniteList, Input, KeysLegend, LineChart, LinkCard, LinkCardList, Meter, Metric, MetricStrip, NBSP, NativeSelect, PageHeader, RowAction, SideNav, Skeleton, Status, StrataQueryProvider, TableSkeleton, Tabs, Textarea, ThemeProvider, UndoBar, VirtualList, buttonVariants, cn, colorSchemeScript, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, fetchJson, format, isTypingTarget, parseSort, serialiseSort, toLoad, typeSteps, useActiveItem, useAsyncAction, useColorScheme, useHotkeys, useInfiniteLoad, useLoad, useSelection, useSystemColorScheme, useUndoable };
|
|
1819
2090
|
|
|
1820
2091
|
//# sourceMappingURL=index.js.map
|