strata-react 0.1.11 → 0.1.13

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 CHANGED
@@ -36,7 +36,7 @@ it against the built files:
36
36
  | Import | Needs | Why |
37
37
  |---|---|---|
38
38
  | `strata-react` | `react`, `react-dom`, `react-router`, `@tanstack/react-query`, `tailwindcss` | The stack is fixed: `DataTable` and `Tabs` keep sort and tab in the URL, `AppShell` links with `NavLink`, every remote read is `useLoad`. The barrel imports both libraries, so an app that uses only a `Button` still installs them (both are needed for anything past a static page) |
39
- | `strata-react/testing` | the above, plus `@testing-library/react` | `renderWithStrata` wraps Testing Library's `render` |
39
+ | `strata-react/testing` | the above, plus `@testing-library/react` | `renderWithStrata` and `renderRoutes` wrap Testing Library's `render` |
40
40
  | `strata-react/visual`, `strata-visual` | `playwright` (exact version), `msw`, `vite` | The screenshot runner; see [Visual regression for apps](#visual-regression-for-apps) |
41
41
 
42
42
  The last three are optional peers: an app that never imports those entries never needs them.
@@ -126,8 +126,8 @@ function KilnRoom() {
126
126
  | Keyboard | `useHotkeys`, `KeysLegend`, `Shortcut`, `useActiveItem`, `ActiveList`, `isTypingTarget` | For queues worked from the keyboard; one shortcut list drives the handler and the legend; keys never fire while typing; answering moves focus to the next item |
127
127
  | Theme | `ThemeProvider`, `useColorScheme`, `useSystemColorScheme`, `ColorSchemeChoice`, `colorSchemeScript` | System, light or dark; sets `.dark`, persists in localStorage when it can; `ColorSchemeChoice` is a radio list for a settings page, or `compact` icon segments named "Appearance" for an app with no settings page |
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; `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
- | 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 |
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); `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; `createFormat(locale, { timeZone })` fixes the zone; units and counts join with a non-breaking space |
130
+ | Testing | `strata-react/testing`: `renderWithStrata`, `renderRoutes`, `createTestQueryClient`, `installLayoutShims`, `installFakeIntersectionObserver` | 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)`. 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
 
133
133
  Specs for the components not built yet (dialogs, sheets, menus, toasts, command menu, prose)
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 ByteUnit, type Format, type NumberFormatter } from './lib/format';
9
+ export { createFormat, format, NBSP, toDate, type ByteUnit, type DateFormatter, type DateInput, type Format, type FormatOptions, type NumberFormatter } from './lib/format';
10
10
  export type { IconComponent } from './lib/icon';
11
11
  export { Button, IconButton, RowAction, buttonVariants, type ButtonProps, type IconButtonProps, type RowActionProps, } from './components/button';
12
12
  export { Checkbox, type CheckboxProps } from './components/checkbox';
package/dist/index.js CHANGED
@@ -19,6 +19,21 @@ var BYTE_UNITS = [
19
19
  "PB"
20
20
  ];
21
21
  var BYTE_SIZE = Object.fromEntries(BYTE_UNITS.map((u, i) => [u, 1e3 ** i]));
22
+ /** A Date from a Date, an ISO string or epoch milliseconds; throws a RangeError naming the input when it is not a date. */
23
+ function toDate(value) {
24
+ const date = value instanceof Date ? value : new Date(value);
25
+ if (Number.isNaN(date.getTime())) throw new RangeError(`Not a date: ${JSON.stringify(String(value))}`);
26
+ return date;
27
+ }
28
+ function callableDate(df) {
29
+ const format = (value) => df.format(toDate(value));
30
+ return Object.assign(format, {
31
+ format,
32
+ formatToParts: (value) => df.formatToParts(toDate(value)),
33
+ formatRange: (start, end) => df.formatRange(toDate(start), toDate(end)),
34
+ resolvedOptions: () => df.resolvedOptions()
35
+ });
36
+ }
22
37
  function callable(nf) {
23
38
  const format = (value) => nf.format(value);
24
39
  return Object.assign(format, {
@@ -27,40 +42,59 @@ function callable(nf) {
27
42
  resolvedOptions: () => nf.resolvedOptions()
28
43
  });
29
44
  }
30
- /** Intl formatters for one locale: integers, decimals, percent, times, days, units with a non-breaking space, byte sizes, and counted nouns. */
31
- function createFormat(locale) {
45
+ /** Intl formatters for one locale (and optionally one time zone): integers, decimals, percent, dates, times, units with a non-breaking space, byte sizes, and counted nouns. */
46
+ function createFormat(locale, options = {}) {
47
+ const { timeZone } = options;
48
+ const dates = (opts) => callableDate(new Intl.DateTimeFormat(locale, {
49
+ ...opts,
50
+ timeZone
51
+ }));
32
52
  const integer = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }));
33
53
  const decimal = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }));
34
54
  const percent = callable(new Intl.NumberFormat(locale, {
35
55
  style: "percent",
36
56
  maximumFractionDigits: 0
37
57
  }));
38
- const clock = new Intl.DateTimeFormat(locale, {
58
+ const clock = dates({
39
59
  hour: "2-digit",
40
60
  minute: "2-digit"
41
61
  });
42
- const day = new Intl.DateTimeFormat(locale, {
62
+ const day = dates({
43
63
  weekday: "long",
44
64
  day: "numeric",
45
65
  month: "long"
46
66
  });
47
- const shortDay = new Intl.DateTimeFormat(locale, {
67
+ const shortDay = dates({
48
68
  weekday: "short",
49
69
  hour: "2-digit",
50
70
  minute: "2-digit"
51
71
  });
72
+ const date = dates({ dateStyle: "medium" });
73
+ const dateTime = dates({
74
+ dateStyle: "medium",
75
+ timeStyle: "short"
76
+ });
52
77
  const withUnit = (value, unit, fmt = integer) => `${fmt.format(value)} ${unit}`;
53
78
  return {
54
79
  locale,
80
+ /** The zone times are shown in, or `undefined` for the viewer's own. */
81
+ timeZone,
55
82
  /** Whole numbers with grouping: `format.integer(1222)` is "1,222". */
56
83
  integer,
57
84
  /** One decimal place at most: `format.decimal(3.14)` is "3.1". */
58
85
  decimal,
59
86
  /** A ratio as a whole percent: `format.percent(0.42)` is "42%". */
60
87
  percent,
88
+ /** A time of day: `format.clock(at)` is "06:05". */
61
89
  clock,
90
+ /** A day without its year, for this week's things: `format.day(at)` is "Sunday 8 November". */
62
91
  day,
92
+ /** A weekday and time, for chart axes and recent rows: `format.shortDay(at)` is "Sun 06:05". */
63
93
  shortDay,
94
+ /** A date with its year, for a record or a deadline: `format.date(at)` is "8 Nov 2026". */
95
+ date,
96
+ /** A date and time, for a log or history row: `format.dateTime(at)` is "8 Nov 2026, 06:05". */
97
+ dateTime,
64
98
  /** A figure and its unit joined by a non-breaking space (`NBSP`), so they never wrap apart. */
65
99
  withUnit,
66
100
  /** A temperature in °C, joined by a non-breaking space. */
@@ -2086,6 +2120,6 @@ function nextAfter(pages, items, itemKey, hidden) {
2086
2120
  if (held.length === 0 || pages.length > 1 && !lastPageAddedAny) return last;
2087
2121
  return held[held.length - 1];
2088
2122
  }
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 };
2123
+ 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, toDate, toLoad, typeSteps, useActiveItem, useAsyncAction, useColorScheme, useHotkeys, useInfiniteLoad, useLoad, useSelection, useSystemColorScheme, useUndoable };
2090
2124
 
2091
2125
  //# sourceMappingURL=index.js.map