@terpjs/react-core 0.29.0 → 0.31.0

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.
Files changed (75) hide show
  1. package/README.md +35 -14
  2. package/package.json +5 -5
  3. package/src/DashboardPage.tsx +34 -0
  4. package/src/Field.test.tsx +26 -1
  5. package/src/Field.tsx +15 -5
  6. package/src/HubPage.tsx +7 -2
  7. package/src/Page.test.tsx +215 -1
  8. package/src/Page.tsx +145 -54
  9. package/src/PageActions.test.tsx +64 -3
  10. package/src/PageActions.tsx +40 -15
  11. package/src/PageSequence.tsx +114 -0
  12. package/src/Stat.test.tsx +341 -0
  13. package/src/Stat.tsx +314 -0
  14. package/src/Timeline.test.tsx +74 -0
  15. package/src/Timeline.tsx +71 -0
  16. package/src/admin/AdminHub.tsx +11 -3
  17. package/src/admin/AuditLogAdmin.tsx +3 -1
  18. package/src/admin/GroupCreate.tsx +3 -1
  19. package/src/admin/GroupDetail.tsx +72 -67
  20. package/src/admin/GroupsAdmin.tsx +3 -1
  21. package/src/admin/ModuleAccessPanel.tsx +13 -12
  22. package/src/admin/RecordHistory.tsx +83 -0
  23. package/src/admin/UserCreate.tsx +3 -1
  24. package/src/admin/UserDetail.tsx +8 -1
  25. package/src/admin/UsersAdmin.tsx +3 -0
  26. package/src/admin/admin.test.tsx +208 -5
  27. package/src/bootstrap.test.tsx +31 -7
  28. package/src/bootstrap.tsx +30 -4
  29. package/src/charts/BarChart.tsx +74 -0
  30. package/src/charts/ProportionBar.tsx +118 -0
  31. package/src/charts/StatusHistory.tsx +75 -0
  32. package/src/charts/TrendChart.tsx +232 -0
  33. package/src/charts/charts.test.tsx +409 -0
  34. package/src/charts/scale.ts +103 -0
  35. package/src/dataview/DataView.test.tsx +255 -0
  36. package/src/dataview/DataView.tsx +35 -0
  37. package/src/dataview/DataViewCardList.tsx +21 -13
  38. package/src/dataview/DataViewTable.tsx +5 -6
  39. package/src/dataview/README.md +18 -0
  40. package/src/dataview/index.ts +1 -0
  41. package/src/dataview/internal.tsx +112 -5
  42. package/src/dataview/types.ts +39 -10
  43. package/src/errorMessages.test.tsx +17 -0
  44. package/src/errorMessages.tsx +18 -0
  45. package/src/format.ts +15 -0
  46. package/src/index.ts +24 -1
  47. package/src/layout.manifest.json +2 -9
  48. package/src/layout.manifest.test.ts +4 -2
  49. package/src/layout.test.tsx +74 -6
  50. package/src/layout.tsx +85 -25
  51. package/src/layoutContract.test.tsx +239 -1
  52. package/src/layoutContract.ts +131 -5
  53. package/src/layoutDeclaration.test.ts +31 -10
  54. package/src/layoutDeclaration.ts +9 -4
  55. package/src/locale.tsx +20 -3
  56. package/src/markers.test.ts +70 -2
  57. package/src/router.test.tsx +15 -3
  58. package/src/router.tsx +11 -2
  59. package/src/ssr.test.tsx +18 -0
  60. package/src/styles.test.ts +252 -176
  61. package/src/styles.ts +1290 -318
  62. package/src/theme.test.tsx +44 -18
  63. package/src/theme.themes.test.ts +22 -2
  64. package/src/theme.tsx +22 -14
  65. package/src/themes.ts +39 -4
  66. package/src/tokens.guard.test.ts +16 -18
  67. package/src/typography.tsx +5 -1
  68. package/src/ui/Alert.test.tsx +24 -1
  69. package/src/ui/Alert.tsx +10 -1
  70. package/src/ui/Card.tsx +5 -4
  71. package/src/ui/Tooltip.test.tsx +171 -2
  72. package/src/ui/Tooltip.tsx +144 -8
  73. package/src/ui/controlMessages.tsx +20 -7
  74. package/src/uiText.test.tsx +16 -0
  75. package/src/uiText.tsx +76 -7
@@ -2,12 +2,14 @@ import { createContext, useCallback, useContext, useMemo } from "react";
2
2
  import type { ReactNode } from "react";
3
3
 
4
4
  import { useFormatDate } from "../format";
5
+ import { StatusHistory } from "../charts/StatusHistory";
6
+ import { Meter } from "../Meter";
5
7
  import { injectTerpStyles } from "../styles";
6
8
  import { Menu, MenuItem } from "../ui/Menu";
7
- import { isPluralText, usePlural, useStrings, useUiText } from "../uiText";
9
+ import { fillPlaceholders, isPluralText, usePlural, useStrings, useUiText } from "../uiText";
8
10
  import type { PluralText, ResolveUiText, TerpStrings, UiText } from "../uiText";
9
- import { formatDataViewString } from "./types";
10
- import type { DataViewStrings } from "./types";
11
+
12
+ import type { DataViewColumn, DataViewStrings } from "./types";
11
13
 
12
14
  injectTerpStyles();
13
15
 
@@ -108,9 +110,9 @@ export function useDataViewText(): DataViewTextApi {
108
110
  () => ({
109
111
  strings: { ...dataViewStrings(framework), ...overrides },
110
112
  resolve,
111
- format: (text, values) => formatDataViewString(resolve(text), values),
113
+ format: (text, values) => fillPlaceholders(resolve(text), values),
112
114
  formatCount: (text, count, values) =>
113
- formatDataViewString(isPluralText(text) ? plural(text, count) : resolve(text), values),
115
+ fillPlaceholders(isPluralText(text) ? plural(text, count) : resolve(text), values),
114
116
  }),
115
117
  [framework, overrides, resolve, plural],
116
118
  );
@@ -145,6 +147,111 @@ export function useCellFormatter(): (value: unknown) => ReactNode {
145
147
  );
146
148
  }
147
149
 
150
+ /** A bar's value prints as a plain number unless the column says otherwise. */
151
+ const PLAIN_NUMBER: Intl.NumberFormatOptions = {};
152
+
153
+ /**
154
+ * The top of each bar column's range for the rows shown: the column's own `max`, or the largest
155
+ * number among the rows. Computed once per render of the rows rather than per cell.
156
+ */
157
+ export function barMaxima<T>(
158
+ columns: readonly DataViewColumn<T>[],
159
+ rows: readonly T[],
160
+ ): ReadonlyMap<string, number> {
161
+ const maxima = new Map<string, number>();
162
+ for (const column of columns) {
163
+ if (column.bar === undefined) {
164
+ continue;
165
+ }
166
+ const declared = column.bar === true ? undefined : column.bar.max;
167
+ const percent = column.bar !== true && column.bar.format?.style === "percent";
168
+ if (percent) {
169
+ // A rate's range is 0 to 1, and only there does a Meter's percentage -- the share of its
170
+ // range -- print the rate itself. Another top would print a share nobody asked for.
171
+ if (declared !== undefined) {
172
+ throw new Error(
173
+ `DataView column "${column.id}": a percent bar is drawn against 100%, so it takes no ` +
174
+ "max. Drop max, or format the value as a plain number to scale it to a max.",
175
+ );
176
+ }
177
+ maxima.set(column.id, 1);
178
+ continue;
179
+ }
180
+ if (declared !== undefined) {
181
+ maxima.set(column.id, declared);
182
+ continue;
183
+ }
184
+ let top = 0;
185
+ for (const row of rows) {
186
+ const value = column.accessor?.(row);
187
+ if (typeof value === "number" && Number.isFinite(value) && value > top) {
188
+ top = value;
189
+ }
190
+ }
191
+ maxima.set(column.id, top);
192
+ }
193
+ return maxima;
194
+ }
195
+
196
+ /**
197
+ * A cell's content, the same in the table and in the cards: the column's own renderer or the
198
+ * shared default, and then its presentation — a bar drawn as a `Meter`, or a status dot before
199
+ * the text.
200
+ *
201
+ * One function for both layouts for the reason {@link useCellFormatter} gives: two copies agree
202
+ * until the first change to either, and then a row renders one way on a desk and another on a
203
+ * phone.
204
+ */
205
+ export function useCellRenderer(): <T>(
206
+ column: DataViewColumn<T>,
207
+ row: T,
208
+ maxima: ReadonlyMap<string, number>,
209
+ ) => ReactNode {
210
+ const formatCell = useCellFormatter();
211
+ return useCallback(
212
+ <T,>(column: DataViewColumn<T>, row: T, maxima: ReadonlyMap<string, number>) => {
213
+ if (column.history !== undefined) {
214
+ const runs = column.history(row);
215
+ return runs.length === 0 ? null : <StatusHistory label={column.header} runs={runs} />;
216
+ }
217
+ if (column.bar !== undefined) {
218
+ const value = column.accessor?.(row);
219
+ if (typeof value === "number" && Number.isFinite(value)) {
220
+ return (
221
+ <Meter
222
+ label={column.header}
223
+ value={value}
224
+ max={maxima.get(column.id) ?? value}
225
+ format={(column.bar === true ? undefined : column.bar.format) ?? PLAIN_NUMBER}
226
+ />
227
+ );
228
+ }
229
+ }
230
+ const content =
231
+ column.cell !== undefined ? column.cell(row) : formatCell(column.accessor?.(row));
232
+ const tone = column.status?.(row);
233
+ // The dot stands for a word, so it is drawn only beside one.
234
+ if (
235
+ tone === undefined ||
236
+ tone === null ||
237
+ content === null ||
238
+ content === undefined ||
239
+ content === false ||
240
+ content === ""
241
+ ) {
242
+ return content;
243
+ }
244
+ return (
245
+ <span data-terp="dataview-status">
246
+ <span data-terp="dataview-status-dot" data-tone={tone} aria-hidden="true" />
247
+ {content}
248
+ </span>
249
+ );
250
+ },
251
+ [formatCell],
252
+ );
253
+ }
254
+
148
255
  export function DataViewTextProvider({
149
256
  overrides,
150
257
  children,
@@ -1,5 +1,7 @@
1
1
  import type { ReactNode } from "react";
2
2
 
3
+ import type { StatusRun } from "../charts/StatusHistory";
4
+ import type { BadgeTone } from "../ui/Badge";
3
5
  import type { UiText } from "../uiText";
4
6
 
5
7
  /**
@@ -135,6 +137,23 @@ export interface DataViewColumnMeta {
135
137
  width?: ColumnWidth;
136
138
  }
137
139
 
140
+ /**
141
+ * A numeric column drawn as an inline bar (ADR 0169 §5): the cell's number beside a `Meter`,
142
+ * so the column reads as magnitudes at a glance and every value is still printed.
143
+ */
144
+ export interface DataViewBar {
145
+ /**
146
+ * The top of every bar's range (default: the largest value among the rows shown).
147
+ *
148
+ * Not for a percentage: a rate's range is 0 to 1 already, and a `Meter` prints a percentage
149
+ * as the value's share of its range, so any other top would print the share rather than the
150
+ * rate. A percent bar is drawn against 100% and a `max` beside it is refused.
151
+ */
152
+ max?: number;
153
+ /** How the value prints, as `Intl.NumberFormatOptions` (default: a plain number). */
154
+ format?: Intl.NumberFormatOptions;
155
+ }
156
+
138
157
  /** Generic, typed column definition for {@link DataView}. */
139
158
  export interface DataViewColumn<T> {
140
159
  /** Stable id — used for sorting/filter ids, visibility, ordering and sizing. */
@@ -152,6 +171,26 @@ export interface DataViewColumn<T> {
152
171
  cell?: (row: T) => ReactNode;
153
172
  /** Whether the header offers the 3-state sort toggle (default true). */
154
173
  enableSorting?: boolean;
174
+ /**
175
+ * A status dot before the cell's text, in the tone the row's state calls for (ADR 0169 §5):
176
+ * the quiet form of a status column, for a column where most rows are fine and a pill on
177
+ * every one of them is noise. The text is the word the tone stands for, so a cell with no
178
+ * text gets no dot; `null` or `undefined` leaves the row's cell plain.
179
+ */
180
+ status?: (row: T) => BadgeTone | null | undefined;
181
+ /**
182
+ * Draw the column's number as an inline bar (ADR 0169 §5), scaled to the largest value on
183
+ * the rows shown unless `max` is given — so a page of results compares at a glance and a
184
+ * page you move to rescales. The accessor's number is what is drawn and printed; a `cell`
185
+ * renderer is not used for a bar, and a row whose value is not a number renders as text.
186
+ */
187
+ bar?: true | DataViewBar;
188
+ /**
189
+ * Draw the column as a status history (ADR 0169 §6): one cell per run, oldest first, the
190
+ * latest run's ending in words, every run read out. For a collection of things that run --
191
+ * syncs, webhooks, checks -- where the column's question is "how have its recent runs gone".
192
+ */
193
+ history?: (row: T) => readonly StatusRun[];
155
194
  meta?: DataViewColumnMeta;
156
195
  }
157
196
 
@@ -242,16 +281,6 @@ export interface DataViewStrings {
242
281
  resizeColumn: UiText;
243
282
  }
244
283
 
245
- /** Tiny `{placeholder}` formatter for the countable strings above. */
246
- export function formatDataViewString(
247
- template: string,
248
- values: Record<string, string | number>,
249
- ): string {
250
- return template.replace(/\{(\w+)\}/g, (match, key: string) =>
251
- key in values ? String(values[key]) : match,
252
- );
253
- }
254
-
255
284
  /** Resolve a row-action boolean-or-predicate flag against a row. */
256
285
  export function resolveRowFlag<T>(
257
286
  flag: boolean | ((row: T) => boolean) | undefined,
@@ -24,6 +24,23 @@ describe("useErrorMessage", () => {
24
24
  );
25
25
  });
26
26
 
27
+ it.each([
28
+ ["rate_limited", 429, "Te veel verzoeken tegelijk. Wacht even en probeer het opnieuw."],
29
+ ["request_too_large", 413, "Dit is te groot om te versturen. Maak het kleiner en probeer het opnieuw."],
30
+ ["internal_error", 500, "Er ging iets mis op de server. Probeer het zo opnieuw."],
31
+ ["idempotency_in_flight", 409, "Dit wordt nog verwerkt. Wacht even en kijk dan opnieuw."],
32
+ ["non_finite_number", 422, "Sommige velden zijn ongeldig. Controleer het formulier en probeer het opnieuw."],
33
+ ])("words %s, which the platform's middleware emits, in the active locale", (code, status, words) => {
34
+ // Their English detail used to reach a Dutch screen as written: the rate limiter's
35
+ // "Too many requests; please retry later." under "Er is iets misgegaan.".
36
+ render(
37
+ <LocaleProvider locales={{ nl: LOCALE_NL, en: LOCALE_EN }} defaultLocale="nl">
38
+ <Probe error={new ApiError("English detail", { code, status })} />
39
+ </LocaleProvider>,
40
+ );
41
+ expect(screen.getByRole("status")).toHaveTextContent(words);
42
+ });
43
+
27
44
  it("returns null for unknown codes and non-envelope errors", () => {
28
45
  render(
29
46
  <>
@@ -37,6 +37,24 @@ function builtInErrorMessages(strings: TerpStrings): ErrorMessages {
37
37
  not_found: strings.errorCodeNotFound,
38
38
  conflict: strings.errorCodeConflict,
39
39
  stale_data: strings.errorCodeStaleData,
40
+ rate_limited: strings.errorCodeRateLimited,
41
+ request_too_large: strings.errorCodeRequestTooLarge,
42
+ internal_error: strings.errorCodeInternalError,
43
+ // The middleware's own refusals. A malformed or reused idempotency key and a NaN in a body
44
+ // are the client's mistakes, which a reader can only retry or correct, so they take the
45
+ // generic wording; a request still running is the one with advice of its own.
46
+ non_finite_number: strings.errorCodeValidationFailed,
47
+ invalid_idempotency_key: strings.errorCodeBadRequest,
48
+ idempotency_key_mismatch: strings.errorCodeBadRequest,
49
+ idempotency_body_too_large: strings.errorCodeRequestTooLarge,
50
+ idempotency_unavailable: strings.errorCodeInternalError,
51
+ idempotency_in_flight: strings.errorCodeStillProcessing,
52
+ // The core's other refusals: work another process holds is still being done, work whose
53
+ // lease ran out is a conflict to refresh past, and sealed configuration that cannot be read
54
+ // is the server's failure. A weak password keeps its detail: it names the policy's numbers.
55
+ lease_held: strings.errorCodeStillProcessing,
56
+ lease_lost: strings.errorCodeConflict,
57
+ secrets_error: strings.errorCodeInternalError,
40
58
  };
41
59
  }
42
60
 
package/src/format.ts CHANGED
@@ -74,6 +74,7 @@ const DATE_TIME_OPTIONS: Intl.DateTimeFormatOptions = {
74
74
  */
75
75
  const DATE_FORMATTERS = new Map<string, Intl.DateTimeFormat>();
76
76
  const NUMBER_FORMATTERS = new Map<string, Intl.NumberFormat>();
77
+ const LIST_FORMATTERS = new Map<string, Intl.ListFormat>();
77
78
 
78
79
  function dateFormatter(locale: string | undefined, withTime: boolean): Intl.DateTimeFormat {
79
80
  const key = `${withTime ? "t" : "d"}|${locale ?? ""}`;
@@ -101,6 +102,20 @@ function numberFormatter(
101
102
  return formatter;
102
103
  }
103
104
 
105
+ /**
106
+ * Items joined as the locale joins a list -- "A, B and C", "A, B en C" -- for a sentence that
107
+ * reads a figure's points or a history's runs aloud. A history column calls it once per row.
108
+ */
109
+ export function formatList(items: readonly string[], locale: string | undefined): string {
110
+ const key = locale ?? "";
111
+ let formatter = LIST_FORMATTERS.get(key);
112
+ if (formatter === undefined) {
113
+ formatter = new Intl.ListFormat(locale, { style: "long", type: "conjunction" });
114
+ LIST_FORMATTERS.set(key, formatter);
115
+ }
116
+ return formatter.format(items);
117
+ }
118
+
104
119
  /** Locale-explicit short date, e.g. `7 jul 2026` under `nl`. `EMPTY` for absent or unparseable. */
105
120
  export function formatDate(value: FormattableDate, locale: string | undefined): string {
106
121
  const date = toDate(value);
package/src/index.ts CHANGED
@@ -61,6 +61,7 @@ export { NavLinkContext, useNavLink } from "./navLink";
61
61
  export type { NavLinkRenderer } from "./navLink";
62
62
  export { Page } from "./Page";
63
63
  export type { PageProps } from "./Page";
64
+ export type { PageSequence, PageSequenceLink } from "./PageSequence";
64
65
  export { LAYOUT_CONTRACTS } from "./layoutContract";
65
66
  export type { LayoutContractSpec, LayoutSlotSpec } from "./layoutContract";
66
67
  // `ResolvedLayout` is deliberately NOT exported: nothing hands one to app code, so it
@@ -71,6 +72,8 @@ export type { OverflowAction, PageActionsProps } from "./PageActions";
71
72
  export { ModuleNav } from "./ModuleNav";
72
73
  export type { ModuleNavProps, ModuleNavTab } from "./ModuleNav";
73
74
  export { OverviewPage } from "./OverviewPage";
75
+ export { DashboardPage } from "./DashboardPage";
76
+ export type { DashboardPageProps } from "./DashboardPage";
74
77
  export type { OverviewPageProps } from "./OverviewPage";
75
78
  export { DetailPage } from "./DetailPage";
76
79
  export type { DetailPageProps } from "./DetailPage";
@@ -180,15 +183,35 @@ export type {
180
183
  export { Field, FieldRow } from "./Field";
181
184
  export { QuietActions } from "./QuietActions";
182
185
  export { Meter } from "./Meter";
186
+ export { Stat, StatGroup } from "./Stat";
187
+ export { TrendChart } from "./charts/TrendChart";
188
+ export { BarChart } from "./charts/BarChart";
189
+ export { ProportionBar } from "./charts/ProportionBar";
190
+ export { StatusHistory } from "./charts/StatusHistory";
191
+ export { Timeline } from "./Timeline";
192
+ export type { TimelineEvent, TimelineProps } from "./Timeline";
193
+ export type { ChartPoint, ChartSeries, TrendChartProps, TrendMark } from "./charts/TrendChart";
194
+ export type { BarChartProps } from "./charts/BarChart";
195
+ export type { ProportionBarProps, ProportionPart } from "./charts/ProportionBar";
196
+ export type { StatusHistoryProps, StatusOutcome, StatusRun } from "./charts/StatusHistory";
183
197
  export type { FieldProps, FieldRowProps } from "./Field";
184
198
  export type { QuietActionsProps } from "./QuietActions";
185
199
  export type { MeterProps } from "./Meter";
200
+ export type {
201
+ StatProps,
202
+ StatGroupProps,
203
+ StatDelta,
204
+ StatPoint,
205
+ StatSentiment,
206
+ StatTarget,
207
+ } from "./Stat";
186
208
  export { Stack, Grid, Divider, DetailList, DetailListGroup } from "./layout";
187
209
  export type {
188
210
  StackProps,
189
211
  GridProps,
190
212
  GridColumns,
191
213
  GridMinColumn,
214
+ GridTemplate,
192
215
  DividerProps,
193
216
  Responsive,
194
217
  DetailListProps,
@@ -245,7 +268,7 @@ export { GroupCreate } from "./admin/GroupCreate";
245
268
  export { GroupDetail } from "./admin/GroupDetail";
246
269
  export { AuditLogAdmin } from "./admin/AuditLogAdmin";
247
270
  export { ThemeProvider, ThemeToggle, useTheme, THEME_STORAGE_KEY } from "./theme";
248
- export type { Theme, ThemeProviderProps, ThemeToggleProps } from "./theme";
271
+ export type { LegacyTheme, Theme, ThemeProviderProps, ThemeToggleProps } from "./theme";
249
272
  export {
250
273
  LocaleProvider,
251
274
  defineAppLocales,
@@ -18,15 +18,8 @@
18
18
  "type": "string",
19
19
  "minLength": 1,
20
20
  "title": "Starting palette",
21
- "enum": [
22
- "light",
23
- "dark",
24
- "midnight",
25
- "twilight",
26
- "contrast",
27
- "system"
28
- ],
29
- "description": "The palette the app opens on, until a person picks another from the theme menu and for as long as they have not. \"system\" opens on whatever light or dark preference the viewer's own device reports."
21
+ "enum": ["midday", "twilight", "evening", "night", "contrast", "system", "light", "dark", "midnight"],
22
+ "description": "The palette the app opens on, until a person picks another from the theme menu and for as long as they have not. \"system\" opens on whatever light or dark preference the viewer's own device reports. \"light\", \"dark\" and \"midnight\" are the earlier names of midday, evening and night, accepted and resolved to them."
30
23
  },
31
24
  "shell": {
32
25
  "type": "object",
@@ -11,7 +11,7 @@ import {
11
11
  SHELL_VALUES,
12
12
  TOP_LEVEL_KEYS,
13
13
  } from "./layoutDeclaration";
14
- import { THEMES } from "./themes";
14
+ import { THEME_ALIASES, THEMES } from "./themes";
15
15
 
16
16
  // The published layout vocabulary against the module that enforces it.
17
17
  //
@@ -103,7 +103,9 @@ describe("the published layout vocabulary", () => {
103
103
  it("offers every palette this release ships, and no other", () => {
104
104
  // Including "system", which is a real thing to declare rather than the absence of one — an
105
105
  // absent key leaves whatever was in force alone, this one pins the platform preference.
106
- expect(properties.defaultTheme?.enum).toEqual([...THEMES]);
106
+ // Then the earlier names, which the resolver accepts and maps (THEME_ALIASES): a file
107
+ // written before the rename is still a valid file, to a tool as to the runtime.
108
+ expect(properties.defaultTheme?.enum).toEqual([...THEMES, ...Object.keys(THEME_ALIASES)]);
107
109
  });
108
110
 
109
111
  it("offers every layout contract this release knows, and no other", () => {
@@ -196,6 +196,36 @@ describe("Grid", () => {
196
196
  expect(fixed.hasAttribute("data-min-column")).toBe(false);
197
197
  });
198
198
 
199
+ it("names a track template, and stamps no count or floor beside it", () => {
200
+ // A template decides the tracks on its own (ADR 0169 §2). A count stamped beside it would
201
+ // be a second rule on the same property, won or lost on source order.
202
+ render(
203
+ <Grid data-testid="grid" template="2:1">
204
+ <span>a</span>
205
+ </Grid>,
206
+ );
207
+ const el = screen.getByTestId("grid");
208
+ expect(el).toHaveAttribute("data-template", "2:1");
209
+ expect(el.hasAttribute("data-columns")).toBe(false);
210
+ expect(el.hasAttribute("data-min-column")).toBe(false);
211
+ expect(el.getAttribute("style")).toBeNull();
212
+ });
213
+
214
+ it("lets a template win over a count an untyped caller passes beside it", () => {
215
+ // The types refuse the pair; a call the typecheck never saw still stamps one decision.
216
+ // Mutation: stamp `columns` whatever the template, and data-columns appears.
217
+ const untyped = { template: "1:1:1", columns: 4, minColumn: "lg" } as never;
218
+ render(
219
+ <Grid data-testid="grid" {...(untyped as object)}>
220
+ <span>a</span>
221
+ </Grid>,
222
+ );
223
+ const el = screen.getByTestId("grid");
224
+ expect(el).toHaveAttribute("data-template", "1:1:1");
225
+ expect(el.hasAttribute("data-columns")).toBe(false);
226
+ expect(el.hasAttribute("data-min-column")).toBe(false);
227
+ });
228
+
199
229
  it("keeps alignment an attribute, unlike Stack's, and takes no style", () => {
200
230
  // The deliberate divergence: Stack's align is an open set of CSS keywords and stays inline
201
231
  // (ADR 0094 §3); Grid's is a closed four, so it is an attribute and Grid renders no inline
@@ -211,6 +241,39 @@ describe("Grid", () => {
211
241
  });
212
242
  });
213
243
 
244
+ describe("DetailList's ruled grid (ADR 0169 §5)", () => {
245
+ it("stamps the grid layout and follows its container by default", () => {
246
+ // A grid of one fixed column is a ruled stack; the grid's default is the auto reflow.
247
+ // Mutation: default the columns to 1 for every layout, and data-columns disappears.
248
+ render(
249
+ <DetailList
250
+ data-testid="list"
251
+ layout="grid"
252
+ items={[
253
+ { label: "Status", value: "Active" },
254
+ { label: "Owner", value: "Operations" },
255
+ ]}
256
+ />,
257
+ );
258
+ const list = screen.getByTestId("list");
259
+ expect(list).toHaveAttribute("data-layout", "grid");
260
+ expect(list).toHaveAttribute("data-columns", "auto");
261
+ expect(list.getAttribute("style")).toBeNull();
262
+ });
263
+
264
+ it("keeps a closed count when asked for one", () => {
265
+ render(
266
+ <DetailList
267
+ data-testid="list"
268
+ layout="grid"
269
+ columns={2}
270
+ items={[{ label: "Status", value: "Active" }]}
271
+ />,
272
+ );
273
+ expect(screen.getByTestId("list")).toHaveAttribute("data-columns", "2");
274
+ });
275
+ });
276
+
214
277
  describe("Divider", () => {
215
278
  it("is an hr, so the separation reaches the accessibility tree", () => {
216
279
  // A bordered div is what a module reaches for without a primitive, and it says nothing to
@@ -232,17 +295,22 @@ describe("Divider", () => {
232
295
  });
233
296
 
234
297
  describe("DetailList", () => {
235
- it("leaves the inline default unstamped, and marks each row", () => {
236
- // `inline` and one column are the base rule. The row marker is new and load-bearing: the
237
- // aligned layout turns the wrapper into `display: contents` so the dt and dd become grid
238
- // items of the dl itself, which is the only way to align labels across rows without
239
- // changing the DOM — and a rule cannot reach an unmarked wrapper.
298
+ it("stacks by default, leaves inline unstamped, and marks each row", () => {
299
+ // Stacked is the default: the label above its value, the one layout with no label-to-value
300
+ // spacing to get wrong. It is the default LAYOUT but not the base rule, so it stamps its
301
+ // name; `inline` and one column are the base rule and stamp nothing. The row marker is
302
+ // load-bearing: the aligned layout turns the wrapper into `display: contents` so the dt and
303
+ // dd become grid items of the dl itself -- and a rule cannot reach an unmarked wrapper.
304
+ // Mutation: put the default back to "inline", and the first assertion fails.
240
305
  render(<DetailList data-testid="dl" items={[{ label: "Owner", value: "Ada" }]} />);
241
306
  const el = screen.getByTestId("dl");
242
- expect(el.hasAttribute("data-layout")).toBe(false);
307
+ expect(el).toHaveAttribute("data-layout", "stacked");
243
308
  expect(el.hasAttribute("data-columns")).toBe(false);
244
309
  expect(el.querySelector('[data-terp="detail-list-row"]')).not.toBeNull();
245
310
  expect(el.getAttribute("style")).toBeNull();
311
+
312
+ render(<DetailList data-testid="inline" layout="inline" items={[{ label: "Owner", value: "Ada" }]} />);
313
+ expect(screen.getByTestId("inline").hasAttribute("data-layout")).toBe(false);
246
314
  });
247
315
 
248
316
  it("names a layout and a column count", () => {