strata-react 1.0.2 → 1.0.3
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 +2 -1
- package/dist/components/field.d.ts +13 -0
- package/dist/components/value-controls.d.ts +72 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +310 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/number-input.d.ts +4 -0
- package/dist/{query-BVh4zv7Y.js → query-gC6I6Cen.js} +19 -6
- package/dist/query-gC6I6Cen.js.map +1 -0
- package/dist/testing.js +1 -1
- package/package.json +1 -1
- package/dist/query-BVh4zv7Y.js.map +0 -1
package/README.md
CHANGED
|
@@ -131,7 +131,8 @@ function KilnRoom() {
|
|
|
131
131
|
| Toolbar and toggles | `Toolbar`, `ToolbarSeparator`, `Toggle`, `ToggleGroup`, `Switch` | A toolbar is one tab stop with arrows, Home and End inside; needs a `label`. `Toggle` (`aria-pressed`) and `ToggleGroup` (one of 2 to 7, always one chosen) show chosen as an ink border on a tint, never the filled primary, so they do not break the one-filled-button rule; an icon-only toggle still needs its `label` (shown as a tooltip). `Switch` is only for a setting that applies at once, label and control one target |
|
|
132
132
|
| Commands | `Command`, `useCommands`, `Menu`, `ContextMenu`, `CommandMenu`, `CommandLegend`, `formatChord`, `matchesChord` | A command is declared once (label or label function, chords, `disabled` with a reason, `destructive`, `checked`) and drives the key handler, dropdown and menu-bar menus, the context menu, the searchable command menu (Mod+K) and the legend, so they cannot disagree. Chords are written once ("Mod+Shift+Z") and shown per platform (⇧⌘Z, Ctrl+Shift+Z); they never fire while typing or during IME composition, and a chord the browser keeps (Ctrl+S) needs `claim: true`. `useHotkeys` is unchanged for single keys |
|
|
133
133
|
| Overlays | `Dialog`, `DialogProps`, `AlertDialog`, `Popover`, `Tooltip` | React Aria underneath. A dialog always has a title and, via `actions`'s close render prop, a way out; `closable={false}` while work cannot stop; `placement="end"` is a sheet. `AlertDialog` is the only confirm: required verb on the confirm button, Cancel focused first, no outside dismiss, stays open with the reason when an async confirm fails. `Popover` needs a `label`. `Tooltip` opens on hover and focus and `IconButton` uses it. All portal onto the `layer-*` stacking utilities |
|
|
134
|
-
|
|
|
134
|
+
| Value controls | `NumberField`, `Slider`, `ColorField` | Set a number or colour precisely, inside `Field`. `NumberField` and `Slider` are React Aria's; the number field runs with `commitBehavior="validate"`, so a typed value outside `min`/`max` is kept on screen, explained in the `Field` ("Enter a value from 0% to 500%.") and never passed to `onChange`. A value that is not known is `null` and shows an en dash, never 0 or NaN. Digits and decimal mark follow `locale`. The unit sits inside the control, and in the slider's spoken value when `Intl` has it (%, °, ms, s, kB, MB, GB, kbps, Mbps). Arrows step, Home/End jump to the limits; `Slider editable` adds a number field. `ColorField`: platform picker, typed hex that is normalised, app suggestions, and a contrast note against `against`. No motion on value changes |
|
|
135
|
+
| Notices and progress | `Alert`, `toast`, `StrataToastRegion`, `useClientWork`, `JobStatus` | Three weights. A `toast` confirms finished work and goes by itself (5 s plus 40 ms a character, 8 s minimum with an action, paused under the pointer or focus, always dismissable); it has no danger tone, because an error a person must act on is an inline `Alert` with its recovery as `action` (`announce` makes it `role="alert"` only when it answers something the person just did). `StrataToastRegion` goes once at the app root. `useClientWork` runs browser work with progress, cancel (aborts its `signal`, ends `cancelled`, never `failed`) and a double-start guard; `JobStatus` shows it exactly as it shows a server job, with `onCancel`, `cancelled` and `onDismiss` |
|
|
135
136
|
| 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 |
|
|
136
137
|
| 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); `format.date(at)` ("8 Nov 2026") and `format.dateTime(at)` ("8 Nov 2026, 06:05"), like `clock`, `day` and `shortDay`, take a Date, ISO string or epoch ms; `format.ago(at, now?)` ("3 weeks ago"), `format.compact(n)` ("1.2k", and `count(n, one, many, { compact: true })`), `format.runningTime(seconds)` ("1:02:09") and `format.share(n)` ("<1%" for a part that rounds to 0); every number and date formatter prints the placeholder (`format.missing`, an en dash) for `null` or `undefined`; `createFormat(locale, { timeZone, missing })` fixes the zone and the placeholder; units and counts join with a non-breaking space |
|
|
137
138
|
| Testing | `strata-react/testing`: `renderWithStrata`, `renderRoutes`, `createTestQueryClient`, `installLayoutShims`, `installFakeIntersectionObserver`, `filledButtons`, `expectOneFilledButton`, `asyncButtonPhase` | Router + query client around Testing Library's `render`; `renderRoutes(routes, { route, basename })` renders the app's own `RouteObject[]` in a memory data router, so layout routes, redirects, loaders and error elements run, and returns the `router` (where a redirect landed is `router.state.location`) and an act-wrapped `navigate`; a fixed box and ResizeObserver so measuring components render in jsdom; an IntersectionObserver the test fires with `scrollToEnd()` or `intersect(el)`; `filledButtons()` and `expectOneFilledButton()` check "one filled button per view" from `data-variant`, and `asyncButtonPhase(el)` reads an `AsyncButton`'s phase. Role names keep the non-breaking space from `format.count`, so match them with the same call or a `\s` regex |
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
type FieldState = {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
describedBy?: string;
|
|
6
|
+
invalid: boolean;
|
|
7
|
+
report: (message: string | undefined) => void;
|
|
8
|
+
};
|
|
9
|
+
/** @internal The surrounding Field, and where a control reports its own message. */
|
|
10
|
+
export declare function useFieldControl(): {
|
|
11
|
+
field: FieldState | null;
|
|
12
|
+
report: (message: string | undefined) => void;
|
|
13
|
+
};
|
|
2
14
|
export type FieldProps = {
|
|
3
15
|
label: string;
|
|
4
16
|
/** The control's id, when the page needs a known one (an anchor, a test). Generated otherwise. */
|
|
@@ -34,3 +46,4 @@ export declare function ChoiceGroup({ legend, name, choices, value, onChange, er
|
|
|
34
46
|
onChange: (value: string) => void;
|
|
35
47
|
error?: string;
|
|
36
48
|
}): React.JSX.Element;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/** Props shared by the number field and the slider. */
|
|
3
|
+
export type RangeProps = {
|
|
4
|
+
min?: number;
|
|
5
|
+
max?: number;
|
|
6
|
+
/** The size of one arrow-key step. Default 1. */
|
|
7
|
+
step?: number;
|
|
8
|
+
/** The unit shown with the value: "%", "°", "Mbps", "px". Spoken too when `Intl` has it (%, °, ms, s, kB, MB, GB, kbps, Mbps). */
|
|
9
|
+
unit?: string;
|
|
10
|
+
/** The locale for digits and the decimal mark. Default the app's `format` locale. */
|
|
11
|
+
locale?: string;
|
|
12
|
+
};
|
|
13
|
+
/** Props for `NumberField`. */
|
|
14
|
+
export type NumberFieldProps = RangeProps & {
|
|
15
|
+
/** The current value; `null` when it is not known (shown as an en dash, not 0). */
|
|
16
|
+
value: number | null;
|
|
17
|
+
/** Receives a number inside the limits, or `null` when the field is cleared. Never NaN, never out of range. */
|
|
18
|
+
onChange: (value: number | null) => void;
|
|
19
|
+
/** Decimal places to show and keep. Default the places in `step` (and `min`). */
|
|
20
|
+
places?: number;
|
|
21
|
+
/** An empty field is an error ("Enter a value.") rather than `null`. */
|
|
22
|
+
required?: boolean;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
/** Names the control when it is used without a `Field`. */
|
|
25
|
+
"aria-label"?: string;
|
|
26
|
+
id?: string;
|
|
27
|
+
name?: string;
|
|
28
|
+
className?: string;
|
|
29
|
+
};
|
|
30
|
+
/** A number with a unit on React Aria's number field: typed input is validated, not clamped, so an out-of-range value is explained in the surrounding `Field` and never passed on; empty stays `null`. */
|
|
31
|
+
export declare function NumberField({ value, onChange, min, max, step, places, unit, locale, required, disabled, id: idProp, name, className, "aria-label": ariaLabel, }: NumberFieldProps): React.JSX.Element;
|
|
32
|
+
/** Props for `Slider`. */
|
|
33
|
+
export type SliderProps = RangeProps & {
|
|
34
|
+
value: number;
|
|
35
|
+
onChange: (value: number) => void;
|
|
36
|
+
/** Both limits are required: a slider with no ends is not a slider. */
|
|
37
|
+
min: number;
|
|
38
|
+
max: number;
|
|
39
|
+
/** Replace the printed value with a `NumberField` beside the track, so an exact value can be typed. */
|
|
40
|
+
editable?: boolean;
|
|
41
|
+
/** Hide the printed value (when something else beside it already shows it). */
|
|
42
|
+
hideValue?: boolean;
|
|
43
|
+
/** Decimal places in the printed and spoken value. Default the places in `step`. */
|
|
44
|
+
places?: number;
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
/** Names the slider when it is used without a `Field`. */
|
|
47
|
+
"aria-label"?: string;
|
|
48
|
+
className?: string;
|
|
49
|
+
};
|
|
50
|
+
/** A slider on React Aria with its current value always printed beside the track (and spoken with the unit when `Intl` knows it); `editable` adds a number field to type an exact value. */
|
|
51
|
+
export declare function Slider({ value, onChange, min, max, step, unit, locale, editable, hideValue, places, disabled, className, "aria-label": ariaLabel, }: SliderProps): React.JSX.Element;
|
|
52
|
+
/** Props for `ColorField`. */
|
|
53
|
+
export type ColorFieldProps = {
|
|
54
|
+
/** `#rrggbb`, or `null` when no colour is set. */
|
|
55
|
+
value: string | null;
|
|
56
|
+
/** Receives a valid `#rrggbb` (lower case) or `null` when cleared; never a half-typed value. */
|
|
57
|
+
onChange: (value: string | null) => void;
|
|
58
|
+
/** A short list the app suggests, as `#rrggbb`. Pressing one chooses it. */
|
|
59
|
+
suggestions?: readonly string[];
|
|
60
|
+
/** The colour this will be drawn on, `#rrggbb`: a note appears when the contrast would be low. */
|
|
61
|
+
against?: string;
|
|
62
|
+
/** What it is drawn on, in words: "the map". Completes the note. */
|
|
63
|
+
againstLabel?: string;
|
|
64
|
+
/** The lowest contrast ratio accepted before the note shows. Default 3, the WCAG minimum for graphics. */
|
|
65
|
+
minContrast?: number;
|
|
66
|
+
disabled?: boolean;
|
|
67
|
+
"aria-label"?: string;
|
|
68
|
+
id?: string;
|
|
69
|
+
className?: string;
|
|
70
|
+
};
|
|
71
|
+
/** Choose a colour with the platform picker, see and type its hex value, pick from the app's suggestions, and get a note when it would be hard to see on `against`. A half-typed value is never passed on. */
|
|
72
|
+
export declare function ColorField({ value, onChange, suggestions, against, againstLabel, minContrast, disabled, id: idProp, className, "aria-label": ariaLabel }: ColorFieldProps): React.JSX.Element;
|
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export { Meter, crossedThreshold, type MeterProps, type MeterThreshold } from '.
|
|
|
27
27
|
export { CompositionBar, type CompositionBarProps, type CompositionPart } from './components/composition';
|
|
28
28
|
export { LinkCard, LinkCardList, type LinkCardProps } from './components/link-card';
|
|
29
29
|
export { DataView, EmptyState, LoadError, Skeleton, StaleNotice, type Load, type LoadFailure, type Stale } from './components/data-view';
|
|
30
|
+
export { NumberField, Slider, ColorField, type NumberFieldProps, type SliderProps, type ColorFieldProps, type RangeProps } from './components/value-controls';
|
|
30
31
|
export { Alert, type AlertProps } from './components/alert';
|
|
31
32
|
export { toast, toastTimeout, StrataToastRegion, type ToastContentProps, type StrataToastRegionProps } from './components/toast';
|
|
32
33
|
export { useClientWork, type ClientWork, type WorkContext, type WorkPhase } from './lib/client-work';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as readErrorBody, E as typeSteps, S as fieldErrorsOf, T as cn, _ as Textarea, a as toLoad, b as describeActionError, c as ColorSchemeChoice, d as useColorScheme, f as useSystemColorScheme, g as NativeSelect, h as Input, i as staleOf, l as ThemeProvider, m as Field, n as createQueryClient, o as useLoad, p as ChoiceGroup, r as fetchJson, s as COLOR_SCHEME_STORAGE_KEY, t as StrataQueryProvider, u as colorSchemeScript, v as useFieldControl, w as Tooltip, x as describeHttpError, y as HttpError } from "./query-gC6I6Cen.js";
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import { Autocomplete, Button as Button$1, Checkbox as Checkbox$1, Dialog as Dialog$1, DialogTrigger, Header, Heading, Input as Input$1, Keyboard, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, Popover as Popover$1, SearchField, Separator, SubmenuTrigger, Switch as Switch$1, Tab, TabList, TabPanel, Tabs as Tabs$1, Text, ToggleButton, ToggleButtonGroup, Toolbar as Toolbar$1, UNSTABLE_Toast, UNSTABLE_ToastContent, UNSTABLE_ToastQueue, UNSTABLE_ToastRegion, useFilter } from "react-aria-components";
|
|
3
|
+
import { Autocomplete, Button as Button$1, Checkbox as Checkbox$1, Dialog as Dialog$1, DialogTrigger, Header, Heading, I18nProvider, Input as Input$1, Keyboard, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, NumberField as NumberField$1, Popover as Popover$1, SearchField, Separator, Slider as Slider$1, SliderOutput, SliderThumb, SliderTrack, SubmenuTrigger, Switch as Switch$1, Tab, TabList, TabPanel, Tabs as Tabs$1, Text, ToggleButton, ToggleButtonGroup, Toolbar as Toolbar$1, UNSTABLE_Toast, UNSTABLE_ToastContent, UNSTABLE_ToastQueue, UNSTABLE_ToastRegion, useFilter } from "react-aria-components";
|
|
4
4
|
import { cva } from "class-variance-authority";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronRight, CircleAlert, CircleCheck, History, ImageOff, Info, LoaderCircle, Minus, RotateCcw, Search, Trash2, TriangleAlert, X } from "lucide-react";
|
|
@@ -1658,6 +1658,313 @@ function Skeleton({ className }) {
|
|
|
1658
1658
|
className: cn("rounded-control bg-muted motion-safe:animate-pulse", className)
|
|
1659
1659
|
});
|
|
1660
1660
|
}
|
|
1661
|
+
// src/lib/number-input.ts
|
|
1662
|
+
/** Reads `#rgb`, `#rrggbb` (with or without the #) as lower-case `#rrggbb`, or null. */
|
|
1663
|
+
function parseHex(text) {
|
|
1664
|
+
const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(text.trim());
|
|
1665
|
+
if (!m) return null;
|
|
1666
|
+
const h = m[1].toLowerCase();
|
|
1667
|
+
return "#" + (h.length === 3 ? [...h].map((c) => c + c).join("") : h);
|
|
1668
|
+
}
|
|
1669
|
+
function luminance(hex) {
|
|
1670
|
+
const v = [
|
|
1671
|
+
1,
|
|
1672
|
+
3,
|
|
1673
|
+
5
|
|
1674
|
+
].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255).map((c) => c <= .03928 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4);
|
|
1675
|
+
return .2126 * v[0] + .7152 * v[1] + .0722 * v[2];
|
|
1676
|
+
}
|
|
1677
|
+
/** WCAG contrast ratio between two `#rrggbb` colours, 1 to 21. */
|
|
1678
|
+
function contrastRatio(a, b) {
|
|
1679
|
+
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
|
|
1680
|
+
return (hi + .05) / (lo + .05);
|
|
1681
|
+
}
|
|
1682
|
+
// src/components/value-controls.tsx
|
|
1683
|
+
var box = "flex h-(--control-h) w-full min-w-0 items-center rounded-control border border-input bg-background px-3 type-body text-foreground transition-state data-[disabled]:cursor-not-allowed data-[disabled]:bg-muted data-[disabled]:opacity-70 has-[input:disabled]:cursor-not-allowed has-[input:disabled]:bg-muted has-[input:disabled]:opacity-70 aria-invalid:border-danger has-[input:focus-visible]:outline-2 has-[input:focus-visible]:outline-offset-2 has-[input:focus-visible]:outline-ring";
|
|
1684
|
+
/** A number with its unit joined by a non-breaking space; `%` and `°` stay attached. */
|
|
1685
|
+
function withUnit(text, unit) {
|
|
1686
|
+
if (!unit) return text;
|
|
1687
|
+
return unit === "%" || unit === "°" ? text + unit : text + "\xA0" + unit;
|
|
1688
|
+
}
|
|
1689
|
+
var intlUnits = {
|
|
1690
|
+
"%": "percent",
|
|
1691
|
+
"°": "degree",
|
|
1692
|
+
ms: "millisecond",
|
|
1693
|
+
s: "second",
|
|
1694
|
+
kB: "kilobyte",
|
|
1695
|
+
MB: "megabyte",
|
|
1696
|
+
GB: "gigabyte",
|
|
1697
|
+
kbps: "kilobit-per-second",
|
|
1698
|
+
Mbps: "megabit-per-second"
|
|
1699
|
+
};
|
|
1700
|
+
function decimalsOf(n) {
|
|
1701
|
+
const s = String(n);
|
|
1702
|
+
if (s.includes("e-")) return Number(s.split("e-")[1]) + (s.split("e-")[0].split(".")[1]?.length ?? 0);
|
|
1703
|
+
return s.split(".")[1]?.length ?? 0;
|
|
1704
|
+
}
|
|
1705
|
+
function useNumberText(locale, places) {
|
|
1706
|
+
return React.useMemo(() => {
|
|
1707
|
+
const f = new Intl.NumberFormat(locale, {
|
|
1708
|
+
maximumFractionDigits: places,
|
|
1709
|
+
minimumFractionDigits: 0
|
|
1710
|
+
});
|
|
1711
|
+
return (n) => f.format(n);
|
|
1712
|
+
}, [locale, places]);
|
|
1713
|
+
}
|
|
1714
|
+
function formatOptionsFor(places, unit) {
|
|
1715
|
+
const base = {
|
|
1716
|
+
maximumFractionDigits: places,
|
|
1717
|
+
minimumFractionDigits: 0
|
|
1718
|
+
};
|
|
1719
|
+
const known = unit ? intlUnits[unit] : void 0;
|
|
1720
|
+
return known ? {
|
|
1721
|
+
...base,
|
|
1722
|
+
style: "unit",
|
|
1723
|
+
unit: known,
|
|
1724
|
+
unitDisplay: "narrow"
|
|
1725
|
+
} : base;
|
|
1726
|
+
}
|
|
1727
|
+
function describeRange(min, max, show, unit) {
|
|
1728
|
+
const a = min === void 0 ? "" : withUnit(show(min), unit);
|
|
1729
|
+
const b = max === void 0 ? "" : withUnit(show(max), unit);
|
|
1730
|
+
if (min !== void 0 && max !== void 0) return `Enter a value from ${a} to ${b}.`;
|
|
1731
|
+
if (min !== void 0) return `Enter ${a} or more.`;
|
|
1732
|
+
if (max !== void 0) return `Enter ${b} or less.`;
|
|
1733
|
+
return "Enter a number.";
|
|
1734
|
+
}
|
|
1735
|
+
/** A number with a unit on React Aria's number field: typed input is validated, not clamped, so an out-of-range value is explained in the surrounding `Field` and never passed on; empty stays `null`. */
|
|
1736
|
+
function NumberField({ value, onChange, min, max, step = 1, places, unit, locale = format.locale, required = false, disabled, id: idProp, name, className, "aria-label": ariaLabel }) {
|
|
1737
|
+
const { field, report } = useFieldControl();
|
|
1738
|
+
const digits = places ?? Math.max(decimalsOf(step), min === void 0 ? 0 : decimalsOf(min));
|
|
1739
|
+
const show = useNumberText(locale, digits);
|
|
1740
|
+
const [own, setOwn] = React.useState(false);
|
|
1741
|
+
const unitId = React.useId();
|
|
1742
|
+
const [local, setLocal] = React.useState(value ?? NaN);
|
|
1743
|
+
const [seen, setSeen] = React.useState(value);
|
|
1744
|
+
if (seen !== value) {
|
|
1745
|
+
setSeen(value);
|
|
1746
|
+
setLocal(value ?? NaN);
|
|
1747
|
+
}
|
|
1748
|
+
const fail = (message) => {
|
|
1749
|
+
setOwn(true);
|
|
1750
|
+
report(message);
|
|
1751
|
+
};
|
|
1752
|
+
const ok = () => {
|
|
1753
|
+
setOwn(false);
|
|
1754
|
+
report(void 0);
|
|
1755
|
+
};
|
|
1756
|
+
const handle = (n) => {
|
|
1757
|
+
setLocal(n);
|
|
1758
|
+
if (Number.isNaN(n)) {
|
|
1759
|
+
if (required) return fail("Enter a value.");
|
|
1760
|
+
ok();
|
|
1761
|
+
if (value !== null) onChange(null);
|
|
1762
|
+
return;
|
|
1763
|
+
}
|
|
1764
|
+
if (min !== void 0 && n < min || max !== void 0 && n > max) return fail(describeRange(min, max, show, unit));
|
|
1765
|
+
ok();
|
|
1766
|
+
if (n !== value) onChange(n);
|
|
1767
|
+
};
|
|
1768
|
+
const invalid = field?.invalid || own;
|
|
1769
|
+
return /* @__PURE__ */ jsx(I18nProvider, {
|
|
1770
|
+
locale,
|
|
1771
|
+
children: /* @__PURE__ */ jsxs(NumberField$1, {
|
|
1772
|
+
value: local,
|
|
1773
|
+
onChange: handle,
|
|
1774
|
+
minValue: min,
|
|
1775
|
+
maxValue: max,
|
|
1776
|
+
step,
|
|
1777
|
+
formatOptions: {
|
|
1778
|
+
maximumFractionDigits: digits,
|
|
1779
|
+
minimumFractionDigits: 0
|
|
1780
|
+
},
|
|
1781
|
+
commitBehavior: "validate",
|
|
1782
|
+
isDisabled: disabled,
|
|
1783
|
+
isInvalid: invalid || void 0,
|
|
1784
|
+
name,
|
|
1785
|
+
"aria-label": ariaLabel ?? field?.label,
|
|
1786
|
+
className: cn(box, className),
|
|
1787
|
+
children: [/* @__PURE__ */ jsx(Input$1, {
|
|
1788
|
+
id: idProp ?? field?.id,
|
|
1789
|
+
placeholder: format.missing,
|
|
1790
|
+
"aria-describedby": [field?.describedBy, unit ? unitId : void 0].filter(Boolean).join(" ") || void 0,
|
|
1791
|
+
className: "min-w-0 flex-1 bg-transparent tabular-nums outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed"
|
|
1792
|
+
}), unit && /* @__PURE__ */ jsxs("span", {
|
|
1793
|
+
id: unitId,
|
|
1794
|
+
className: "ml-2 shrink-0 type-body-sm text-muted-foreground",
|
|
1795
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1796
|
+
"aria-hidden": true,
|
|
1797
|
+
children: unit
|
|
1798
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
1799
|
+
className: "sr-only",
|
|
1800
|
+
children: intlUnits[unit] ? intlUnits[unit].replace(/-/g, " ") : unit
|
|
1801
|
+
})]
|
|
1802
|
+
})]
|
|
1803
|
+
})
|
|
1804
|
+
});
|
|
1805
|
+
}
|
|
1806
|
+
/** A slider on React Aria with its current value always printed beside the track (and spoken with the unit when `Intl` knows it); `editable` adds a number field to type an exact value. */
|
|
1807
|
+
function Slider({ value, onChange, min, max, step = 1, unit, locale = format.locale, editable = false, hideValue = false, places, disabled, className, "aria-label": ariaLabel }) {
|
|
1808
|
+
const { field } = useFieldControl();
|
|
1809
|
+
const digits = places ?? Math.max(decimalsOf(step), decimalsOf(min));
|
|
1810
|
+
const show = useNumberText(locale, digits);
|
|
1811
|
+
const name = ariaLabel ?? field?.label ?? "Value";
|
|
1812
|
+
const text = withUnit(show(value), unit);
|
|
1813
|
+
return /* @__PURE__ */ jsx(I18nProvider, {
|
|
1814
|
+
locale,
|
|
1815
|
+
children: /* @__PURE__ */ jsxs(Slider$1, {
|
|
1816
|
+
value,
|
|
1817
|
+
onChange: (v) => onChange(v),
|
|
1818
|
+
minValue: min,
|
|
1819
|
+
maxValue: max,
|
|
1820
|
+
step,
|
|
1821
|
+
formatOptions: formatOptionsFor(digits, unit),
|
|
1822
|
+
isDisabled: disabled,
|
|
1823
|
+
"aria-label": name,
|
|
1824
|
+
"aria-describedby": field?.describedBy,
|
|
1825
|
+
className: cn("flex min-w-0 items-center gap-3", className),
|
|
1826
|
+
children: [/* @__PURE__ */ jsx(SliderTrack, {
|
|
1827
|
+
className: "relative flex h-(--control-h) min-w-0 flex-1 cursor-pointer items-center data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50",
|
|
1828
|
+
children: ({ state }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1829
|
+
/* @__PURE__ */ jsx("span", {
|
|
1830
|
+
"aria-hidden": true,
|
|
1831
|
+
className: "absolute inset-x-0 h-1.5 rounded-pill bg-muted"
|
|
1832
|
+
}),
|
|
1833
|
+
/* @__PURE__ */ jsx("span", {
|
|
1834
|
+
"aria-hidden": true,
|
|
1835
|
+
className: "absolute left-0 h-1.5 rounded-pill bg-primary",
|
|
1836
|
+
style: { width: `${state.getThumbPercent(0) * 100}%` }
|
|
1837
|
+
}),
|
|
1838
|
+
/* @__PURE__ */ jsx(SliderThumb, { className: "top-1/2 size-5 rounded-pill border-2 border-primary bg-background data-[focus-visible]:outline-2 data-[focus-visible]:outline-offset-2 data-[focus-visible]:outline-ring" })
|
|
1839
|
+
] })
|
|
1840
|
+
}), editable ? /* @__PURE__ */ jsx(NumberField, {
|
|
1841
|
+
className: "w-28 shrink-0",
|
|
1842
|
+
"aria-label": `${name}, exact value`,
|
|
1843
|
+
value,
|
|
1844
|
+
onChange: (v) => v !== null && onChange(v),
|
|
1845
|
+
min,
|
|
1846
|
+
max,
|
|
1847
|
+
step,
|
|
1848
|
+
unit,
|
|
1849
|
+
locale,
|
|
1850
|
+
places: digits,
|
|
1851
|
+
required: true,
|
|
1852
|
+
disabled
|
|
1853
|
+
}) : !hideValue && /* @__PURE__ */ jsx(SliderOutput, {
|
|
1854
|
+
"aria-hidden": true,
|
|
1855
|
+
className: "w-16 shrink-0 text-right type-body-sm tabular-nums text-foreground",
|
|
1856
|
+
children: text
|
|
1857
|
+
})]
|
|
1858
|
+
})
|
|
1859
|
+
});
|
|
1860
|
+
}
|
|
1861
|
+
/** Choose a colour with the platform picker, see and type its hex value, pick from the app's suggestions, and get a note when it would be hard to see on `against`. A half-typed value is never passed on. */
|
|
1862
|
+
function ColorField({ value, onChange, suggestions, against, againstLabel = "the background", minContrast = 3, disabled, id: idProp, className, "aria-label": ariaLabel }) {
|
|
1863
|
+
const { field, report } = useFieldControl();
|
|
1864
|
+
const [draft, setDraft] = React.useState(null);
|
|
1865
|
+
const [own, setOwn] = React.useState(false);
|
|
1866
|
+
const text = draft ?? value ?? "";
|
|
1867
|
+
const ratio = value && against ? contrastRatio(value, against) : null;
|
|
1868
|
+
const commitText = (t) => {
|
|
1869
|
+
if (t.trim() === "") {
|
|
1870
|
+
setOwn(false);
|
|
1871
|
+
report(void 0);
|
|
1872
|
+
if (value !== null) onChange(null);
|
|
1873
|
+
return true;
|
|
1874
|
+
}
|
|
1875
|
+
const hex = parseHex(t);
|
|
1876
|
+
if (!hex) {
|
|
1877
|
+
setOwn(true);
|
|
1878
|
+
report("Enter a colour like #1a7f64.");
|
|
1879
|
+
return false;
|
|
1880
|
+
}
|
|
1881
|
+
setOwn(false);
|
|
1882
|
+
report(void 0);
|
|
1883
|
+
if (hex !== value) onChange(hex);
|
|
1884
|
+
return true;
|
|
1885
|
+
};
|
|
1886
|
+
const pick = (hex) => {
|
|
1887
|
+
setDraft(null);
|
|
1888
|
+
setOwn(false);
|
|
1889
|
+
report(void 0);
|
|
1890
|
+
if (hex !== value) onChange(hex);
|
|
1891
|
+
};
|
|
1892
|
+
const invalid = field?.invalid || own;
|
|
1893
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1894
|
+
className: cn("grid min-w-0 gap-2", className),
|
|
1895
|
+
children: [
|
|
1896
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1897
|
+
className: cn(box, "gap-2 px-2"),
|
|
1898
|
+
"aria-invalid": invalid || void 0,
|
|
1899
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
1900
|
+
className: "relative size-6 shrink-0 overflow-hidden rounded-control border border-input",
|
|
1901
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1902
|
+
"aria-hidden": true,
|
|
1903
|
+
className: cn("absolute inset-0", value === null && "bg-muted"),
|
|
1904
|
+
style: value ? { background: value } : void 0
|
|
1905
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
1906
|
+
type: "color",
|
|
1907
|
+
"aria-label": ariaLabel ? `${ariaLabel}, picker` : "Colour picker",
|
|
1908
|
+
value: value ?? "#000000",
|
|
1909
|
+
disabled,
|
|
1910
|
+
onChange: (e) => pick(e.target.value),
|
|
1911
|
+
className: "absolute inset-0 size-full cursor-pointer opacity-0 disabled:cursor-not-allowed"
|
|
1912
|
+
})]
|
|
1913
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
1914
|
+
id: idProp ?? field?.id,
|
|
1915
|
+
type: "text",
|
|
1916
|
+
autoComplete: "off",
|
|
1917
|
+
spellCheck: false,
|
|
1918
|
+
disabled,
|
|
1919
|
+
"aria-label": ariaLabel,
|
|
1920
|
+
"aria-describedby": field?.describedBy,
|
|
1921
|
+
"aria-invalid": invalid || void 0,
|
|
1922
|
+
placeholder: format.missing,
|
|
1923
|
+
value: text,
|
|
1924
|
+
onChange: (e) => setDraft(e.target.value),
|
|
1925
|
+
onBlur: () => {
|
|
1926
|
+
if (draft !== null && commitText(draft)) setDraft(null);
|
|
1927
|
+
},
|
|
1928
|
+
onKeyDown: (e) => {
|
|
1929
|
+
if (e.key === "Enter" && draft !== null && commitText(draft)) setDraft(null);
|
|
1930
|
+
if (e.key === "Escape" && draft !== null) {
|
|
1931
|
+
setDraft(null);
|
|
1932
|
+
setOwn(false);
|
|
1933
|
+
report(void 0);
|
|
1934
|
+
}
|
|
1935
|
+
},
|
|
1936
|
+
className: "min-w-0 flex-1 bg-transparent tabular-nums outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed"
|
|
1937
|
+
})]
|
|
1938
|
+
}),
|
|
1939
|
+
suggestions && suggestions.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
1940
|
+
role: "group",
|
|
1941
|
+
"aria-label": "Suggested colours",
|
|
1942
|
+
className: "flex flex-wrap gap-1.5",
|
|
1943
|
+
children: suggestions.map((hex) => /* @__PURE__ */ jsx("button", {
|
|
1944
|
+
type: "button",
|
|
1945
|
+
disabled,
|
|
1946
|
+
"aria-label": hex,
|
|
1947
|
+
"aria-pressed": value === hex,
|
|
1948
|
+
onClick: () => pick(hex),
|
|
1949
|
+
className: "size-6 cursor-pointer rounded-control border border-input transition-state aria-pressed:outline-2 aria-pressed:outline-offset-2 aria-pressed:outline-foreground disabled:cursor-not-allowed disabled:opacity-50",
|
|
1950
|
+
style: { background: hex }
|
|
1951
|
+
}, hex))
|
|
1952
|
+
}),
|
|
1953
|
+
ratio !== null && ratio < minContrast && /* @__PURE__ */ jsxs("p", {
|
|
1954
|
+
className: "type-body-sm text-warning",
|
|
1955
|
+
children: [
|
|
1956
|
+
"Hard to see on ",
|
|
1957
|
+
againstLabel,
|
|
1958
|
+
": contrast ",
|
|
1959
|
+
format.decimal(ratio),
|
|
1960
|
+
":1, aim for ",
|
|
1961
|
+
format.decimal(minContrast),
|
|
1962
|
+
":1 or more."
|
|
1963
|
+
]
|
|
1964
|
+
})
|
|
1965
|
+
]
|
|
1966
|
+
});
|
|
1967
|
+
}
|
|
1661
1968
|
// src/components/alert.tsx
|
|
1662
1969
|
var tones = {
|
|
1663
1970
|
info: {
|
|
@@ -3849,6 +4156,6 @@ function useJob({ isRunning, every = 2e3, invalidates = [], describeError, ...op
|
|
|
3849
4156
|
poll
|
|
3850
4157
|
};
|
|
3851
4158
|
}
|
|
3852
|
-
export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorSchemeChoice, CommandLegend, CommandMenu, CompositionBar, ContextMenu, DataTable, DataView, Dialog, Disclosure, Done, EmptyState, Field, HttpError, IconButton, InfiniteList, Input, JobStatus, KeysLegend, LineChart, LinkCard, LinkCardList, LoadError, LoadMore, MISSING, Menu, Meter, Metric, MetricStrip, NBSP, NativeSelect, PageHeader, Popover, RowAction, SelectableGrid, SideNav, Skeleton, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, UndoBar, VirtualList, buttonVariants, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, fetchJson, fieldErrorsOf, format, formatChord, isReservedChord, isTypingTarget, labelOf, matchesChord, parseChord, parseSort, readErrorBody, serialiseSort, staleOf, toDate, toLoad, toast, toastTimeout, typeSteps, useActiveItem, useAsyncAction, useClientWork, useColorScheme, useCommands, useExpanded, useHotkeys, useInView, useInfiniteLoad, useJob, useLoad, useSelection, useSystemColorScheme, useUndoable };
|
|
4159
|
+
export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, CompositionBar, ContextMenu, DataTable, DataView, Dialog, Disclosure, Done, EmptyState, Field, HttpError, IconButton, InfiniteList, Input, JobStatus, KeysLegend, LineChart, LinkCard, LinkCardList, LoadError, LoadMore, MISSING, Menu, Meter, Metric, MetricStrip, NBSP, NativeSelect, NumberField, PageHeader, Popover, RowAction, SelectableGrid, SideNav, Skeleton, Slider, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, UndoBar, VirtualList, buttonVariants, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, fetchJson, fieldErrorsOf, format, formatChord, isReservedChord, isTypingTarget, labelOf, matchesChord, parseChord, parseSort, readErrorBody, serialiseSort, staleOf, toDate, toLoad, toast, toastTimeout, typeSteps, useActiveItem, useAsyncAction, useClientWork, useColorScheme, useCommands, useExpanded, useHotkeys, useInView, useInfiniteLoad, useJob, useLoad, useSelection, useSystemColorScheme, useUndoable };
|
|
3853
4160
|
|
|
3854
4161
|
//# sourceMappingURL=index.js.map
|