@terpjs/react-core 0.30.0 → 0.32.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 (82) 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/ModuleNav.test.tsx +29 -1
  8. package/src/ModuleNav.tsx +5 -1
  9. package/src/Page.test.tsx +192 -0
  10. package/src/Page.tsx +141 -55
  11. package/src/PageActions.test.tsx +64 -3
  12. package/src/PageActions.tsx +40 -15
  13. package/src/PageSequence.tsx +114 -0
  14. package/src/Stat.test.tsx +376 -0
  15. package/src/Stat.tsx +316 -0
  16. package/src/Timeline.test.tsx +74 -0
  17. package/src/Timeline.tsx +71 -0
  18. package/src/admin/AdminHub.tsx +233 -78
  19. package/src/admin/AuditLogAdmin.tsx +3 -1
  20. package/src/admin/GroupCreate.tsx +3 -1
  21. package/src/admin/GroupDetail.tsx +72 -67
  22. package/src/admin/GroupsAdmin.tsx +3 -1
  23. package/src/admin/ModuleAccessPanel.tsx +13 -12
  24. package/src/admin/RecordHistory.tsx +88 -0
  25. package/src/admin/UserCreate.tsx +3 -1
  26. package/src/admin/UserDetail.tsx +8 -1
  27. package/src/admin/UsersAdmin.tsx +3 -0
  28. package/src/admin/admin.test.tsx +389 -19
  29. package/src/bootstrap.test.tsx +31 -7
  30. package/src/bootstrap.tsx +30 -4
  31. package/src/charts/BarChart.tsx +74 -0
  32. package/src/charts/ProportionBar.tsx +118 -0
  33. package/src/charts/StatusHistory.tsx +75 -0
  34. package/src/charts/TrendChart.tsx +232 -0
  35. package/src/charts/charts.test.tsx +409 -0
  36. package/src/charts/scale.ts +103 -0
  37. package/src/currentInView.ts +28 -0
  38. package/src/dataview/DataView.test.tsx +303 -1
  39. package/src/dataview/DataView.tsx +53 -3
  40. package/src/dataview/DataViewCardList.tsx +21 -13
  41. package/src/dataview/DataViewTable.tsx +5 -6
  42. package/src/dataview/DataViewToolbar.tsx +4 -1
  43. package/src/dataview/README.md +18 -0
  44. package/src/dataview/index.ts +1 -0
  45. package/src/dataview/internal.tsx +112 -5
  46. package/src/dataview/types.ts +39 -10
  47. package/src/errorMessages.test.tsx +17 -0
  48. package/src/errorMessages.tsx +18 -0
  49. package/src/format.ts +15 -0
  50. package/src/index.ts +24 -1
  51. package/src/layout.manifest.json +2 -9
  52. package/src/layout.manifest.test.ts +4 -2
  53. package/src/layout.test.tsx +74 -6
  54. package/src/layout.tsx +85 -25
  55. package/src/layoutContract.test.tsx +239 -1
  56. package/src/layoutContract.ts +131 -5
  57. package/src/layoutDeclaration.test.ts +31 -10
  58. package/src/layoutDeclaration.ts +9 -4
  59. package/src/locale.tsx +28 -3
  60. package/src/markers.test.ts +70 -2
  61. package/src/router.test.tsx +15 -3
  62. package/src/router.tsx +11 -2
  63. package/src/ssr.test.tsx +18 -0
  64. package/src/styles.test.ts +288 -190
  65. package/src/styles.ts +1379 -361
  66. package/src/theme.test.tsx +44 -18
  67. package/src/theme.themes.test.ts +22 -2
  68. package/src/theme.tsx +22 -14
  69. package/src/themes.ts +39 -4
  70. package/src/tokens.guard.test.ts +13 -15
  71. package/src/typography.tsx +5 -1
  72. package/src/ui/Alert.test.tsx +24 -1
  73. package/src/ui/Alert.tsx +10 -1
  74. package/src/ui/Card.tsx +5 -4
  75. package/src/ui/Tabs.test.tsx +44 -0
  76. package/src/ui/Tabs.tsx +5 -2
  77. package/src/ui/Tooltip.test.tsx +171 -2
  78. package/src/ui/Tooltip.tsx +144 -8
  79. package/src/ui/controlMessages.tsx +20 -7
  80. package/src/uiText.test.tsx +16 -0
  81. package/src/uiText.tsx +105 -7
  82. package/src/viewerTimeZone.ts +15 -0
@@ -30,9 +30,9 @@ describe("ThemeProvider + ThemeToggle", () => {
30
30
  </ThemeProvider>,
31
31
  );
32
32
  fireEvent.click(screen.getByRole("button", { name: "Theme" }));
33
- fireEvent.click(screen.getByRole("menuitemradio", { name: "Dark" }));
34
- expect(document.documentElement.getAttribute("data-theme")).toBe("dark");
35
- expect(window.localStorage.getItem(THEME_STORAGE_KEY)).toBe("dark");
33
+ fireEvent.click(screen.getByRole("menuitemradio", { name: "Evening" }));
34
+ expect(document.documentElement.getAttribute("data-theme")).toBe("evening");
35
+ expect(window.localStorage.getItem(THEME_STORAGE_KEY)).toBe("evening");
36
36
  });
37
37
 
38
38
  it("hands back the pre-paint bootstrap's inline color-scheme", () => {
@@ -43,9 +43,9 @@ describe("ThemeProvider + ThemeToggle", () => {
43
43
  // every rule in every layer, so a viewer who loaded on a dark palette and then chose a
44
44
  // light one would keep dark scrollbars, a dark caret and a dark select popup for the
45
45
  // rest of the session, on a page that is no longer dark.
46
- document.documentElement.setAttribute("data-theme", "dark");
46
+ document.documentElement.setAttribute("data-theme", "evening");
47
47
  document.documentElement.style.colorScheme = "dark";
48
- window.localStorage.setItem(THEME_STORAGE_KEY, "dark");
48
+ window.localStorage.setItem(THEME_STORAGE_KEY, "evening");
49
49
 
50
50
  render(
51
51
  <ThemeProvider>
@@ -55,12 +55,12 @@ describe("ThemeProvider + ThemeToggle", () => {
55
55
  // Taken back on mount, while the palette it described is still the live one — so the
56
56
  // token sheet's own per-theme declaration is what governs from here.
57
57
  expect(document.documentElement.style.getPropertyValue("color-scheme")).toBe("");
58
- expect(document.documentElement.getAttribute("data-theme")).toBe("dark");
58
+ expect(document.documentElement.getAttribute("data-theme")).toBe("evening");
59
59
 
60
60
  // And it does not come back when the choice changes, which is the case it exists for.
61
61
  fireEvent.click(screen.getByRole("button", { name: "Theme" }));
62
- fireEvent.click(screen.getByRole("menuitemradio", { name: "Light" }));
63
- expect(document.documentElement.getAttribute("data-theme")).toBe("light");
62
+ fireEvent.click(screen.getByRole("menuitemradio", { name: "Midday" }));
63
+ expect(document.documentElement.getAttribute("data-theme")).toBe("midday");
64
64
  expect(document.documentElement.style.getPropertyValue("color-scheme")).toBe("");
65
65
  });
66
66
 
@@ -74,9 +74,9 @@ describe("ThemeProvider + ThemeToggle", () => {
74
74
  </ThemeProvider>,
75
75
  );
76
76
  fireEvent.click(screen.getByRole("button", { name: "Theme" }));
77
- fireEvent.click(screen.getByRole("menuitemradio", { name: "Midnight" }));
78
- expect(document.documentElement.getAttribute("data-theme")).toBe("midnight");
79
- expect(window.localStorage.getItem(THEME_STORAGE_KEY)).toBe("midnight");
77
+ fireEvent.click(screen.getByRole("menuitemradio", { name: "Night" }));
78
+ expect(document.documentElement.getAttribute("data-theme")).toBe("night");
79
+ expect(window.localStorage.getItem(THEME_STORAGE_KEY)).toBe("night");
80
80
  });
81
81
 
82
82
  it("offers every shipped theme, not only light and dark", () => {
@@ -88,7 +88,7 @@ describe("ThemeProvider + ThemeToggle", () => {
88
88
  </ThemeProvider>,
89
89
  );
90
90
  fireEvent.click(screen.getByRole("button", { name: "Theme" }));
91
- for (const label of ["Light", "Dark", "Midnight", "Twilight", "High contrast", "System"]) {
91
+ for (const label of ["Midday", "Twilight", "Evening", "Night", "High contrast", "System"]) {
92
92
  expect(screen.getByRole("menuitemradio", { name: label })).toBeInTheDocument();
93
93
  }
94
94
  });
@@ -104,13 +104,39 @@ describe("ThemeProvider + ThemeToggle", () => {
104
104
  });
105
105
 
106
106
  it("restores a persisted choice over the app default", () => {
107
- window.localStorage.setItem(THEME_STORAGE_KEY, "light");
107
+ window.localStorage.setItem(THEME_STORAGE_KEY, "midday");
108
+ render(
109
+ <ThemeProvider defaultTheme="evening">
110
+ <ThemeToggle />
111
+ </ThemeProvider>,
112
+ );
113
+ expect(document.documentElement.getAttribute("data-theme")).toBe("midday");
114
+ });
115
+
116
+ it("restores a choice stored before the rename as the theme it now names", () => {
117
+ // A viewer who picked "Dark" last week has "dark" in storage. The rename must not change
118
+ // their palette or forget the choice: it resolves to evening, the same colours, and the
119
+ // menu shows it checked under its new name.
120
+ // Mutation: validate a stored name against THEMES alone again, and this falls back to the
121
+ // app default instead.
122
+ window.localStorage.setItem(THEME_STORAGE_KEY, "dark");
123
+ render(
124
+ <ThemeProvider defaultTheme="contrast">
125
+ <ThemeToggle />
126
+ </ThemeProvider>,
127
+ );
128
+ expect(document.documentElement.getAttribute("data-theme")).toBe("evening");
129
+ fireEvent.click(screen.getByRole("button", { name: "Theme" }));
130
+ expect(screen.getByRole("menuitemradio", { name: "Evening" })).toBeChecked();
131
+ });
132
+
133
+ it("accepts an earlier theme name as the app default", () => {
108
134
  render(
109
- <ThemeProvider defaultTheme="dark">
135
+ <ThemeProvider defaultTheme="midnight">
110
136
  <ThemeToggle />
111
137
  </ThemeProvider>,
112
138
  );
113
- expect(document.documentElement.getAttribute("data-theme")).toBe("light");
139
+ expect(document.documentElement.getAttribute("data-theme")).toBe("night");
114
140
  });
115
141
 
116
142
  it("restores a persisted SYSTEM choice over the app default", () => {
@@ -121,7 +147,7 @@ describe("ThemeProvider + ThemeToggle", () => {
121
147
  // who asked to follow their own platform.
122
148
  window.localStorage.setItem(THEME_STORAGE_KEY, "system");
123
149
  render(
124
- <ThemeProvider defaultTheme="midnight">
150
+ <ThemeProvider defaultTheme="night">
125
151
  <ThemeToggle />
126
152
  </ThemeProvider>,
127
153
  );
@@ -144,11 +170,11 @@ describe("ThemeProvider + ThemeToggle", () => {
144
170
 
145
171
  it("switching back to system removes the attribute (OS preference wins)", () => {
146
172
  render(
147
- <ThemeProvider defaultTheme="dark">
173
+ <ThemeProvider defaultTheme="evening">
148
174
  <ThemeToggle />
149
175
  </ThemeProvider>,
150
176
  );
151
- expect(document.documentElement.getAttribute("data-theme")).toBe("dark");
177
+ expect(document.documentElement.getAttribute("data-theme")).toBe("evening");
152
178
  fireEvent.click(screen.getByRole("button", { name: "Theme" }));
153
179
  fireEvent.click(screen.getByRole("menuitemradio", { name: "System" }));
154
180
  expect(document.documentElement.hasAttribute("data-theme")).toBe(false);
@@ -2,6 +2,7 @@ import { readFileSync } from "node:fs";
2
2
 
3
3
  import { describe, expect, it } from "vitest";
4
4
 
5
+ import { THEME_ALIASES } from "./themes";
5
6
  import { DEFAULT_STRINGS } from "./uiText";
6
7
 
7
8
  // react-core's theme list against the contract's published one.
@@ -26,7 +27,7 @@ import { DEFAULT_STRINGS } from "./uiText";
26
27
  const manifest: {
27
28
  base: string;
28
29
  systemDark: string;
29
- themes: { name: string; label: string; appearance: "light" | "dark" }[];
30
+ themes: { name: string; label: string; aliases: string[]; appearance: "light" | "dark" }[];
30
31
  } = JSON.parse(
31
32
  readFileSync(new URL("../../contract/src/tokens.manifest.json", import.meta.url), "utf-8"),
32
33
  );
@@ -107,8 +108,13 @@ describe("react-core's theme list", () => {
107
108
  it("has a translated label for every theme", () => {
108
109
  // The label map is `Record<Theme, string>` so the compiler catches a missing entry, but
109
110
  // not one pointing at a string key that does not exist in the catalog.
111
+ //
112
+ // A renamed theme's key keeps the name the theme had when the key was written (its first
113
+ // alias): an app's own language catalog must supply every key, so renaming the keys would
114
+ // refuse every such catalog for a change no reader sees. midday's label is themeLight.
110
115
  for (const name of expected) {
111
- const key = `theme${name[0]!.toUpperCase()}${name.slice(1)}`;
116
+ const keyed = manifest.themes.find((theme) => theme.name === name)?.aliases[0] ?? name;
117
+ const key = `theme${keyed[0]!.toUpperCase()}${keyed.slice(1)}`;
112
118
  expect(
113
119
  Object.hasOwn(DEFAULT_STRINGS, key),
114
120
  `${name} needs a ${key} string (LOCALE_NL's completeness gate then forces the Dutch one)`,
@@ -128,3 +134,17 @@ describe("react-core's theme list", () => {
128
134
  expect(shipped).toContain(manifest.base);
129
135
  });
130
136
  });
137
+
138
+ describe("the earlier theme names", () => {
139
+ it("resolves exactly the earlier names the registry publishes", () => {
140
+ // themes.json lists each theme's earlier names, the generator compiles them into the sheet
141
+ // and the manifest publishes them -- and THEME_ALIASES is a second, hand-written copy that
142
+ // the provider, the layout resolver and the bootstrap option all resolve through. An alias
143
+ // added to the registry alone was styled and published, and refused at runtime.
144
+ // Mutation: drop "midnight" from THEME_ALIASES, and this fails.
145
+ const published = Object.fromEntries(
146
+ manifest.themes.flatMap((theme) => theme.aliases.map((alias) => [alias, theme.name])),
147
+ );
148
+ expect(THEME_ALIASES).toEqual(published);
149
+ });
150
+ });
package/src/theme.tsx CHANGED
@@ -3,8 +3,8 @@ import { createContext, useCallback, useContext, useEffect, useMemo, useState }
3
3
  import type { ReactNode } from "react";
4
4
 
5
5
  import { Icon } from "./icons";
6
- import { THEMES } from "./themes";
7
- import type { Theme } from "./themes";
6
+ import { THEMES, resolveTheme } from "./themes";
7
+ import type { LegacyTheme, Theme } from "./themes";
8
8
  import { Menu, MenuItem } from "./ui/Menu";
9
9
  import { useStrings } from "./uiText";
10
10
 
@@ -14,13 +14,13 @@ import { useStrings } from "./uiText";
14
14
  * palette an app's checked-in file names — and it must not import this file to get it.
15
15
  * Re-exported here so `ThemeProvider`'s own type stays where its props are documented.
16
16
  */
17
- export type { Theme } from "./themes";
17
+ export type { LegacyTheme, Theme } from "./themes";
18
18
 
19
19
  const THEME_ICONS: Record<Theme, IconName> = {
20
- light: "sun",
21
- dark: "moon",
22
- midnight: "moon-stars",
20
+ midday: "sun",
23
21
  twilight: "sunset",
22
+ evening: "moon",
23
+ night: "moon-stars",
24
24
  contrast: "contrast",
25
25
  system: "monitor",
26
26
  };
@@ -51,8 +51,9 @@ const ThemeContext = createContext<ThemeContextValue | null>(null);
51
51
  */
52
52
  function readStoredTheme(): Theme | null {
53
53
  try {
54
- const stored = window.localStorage.getItem(THEME_STORAGE_KEY);
55
- return THEMES.includes(stored as Theme) ? (stored as Theme) : null;
54
+ // A choice stored before the rename ("dark", "midnight", "light") resolves to the theme it
55
+ // now names, so nobody's palette changes because the theme did.
56
+ return resolveTheme(window.localStorage.getItem(THEME_STORAGE_KEY));
56
57
  } catch {
57
58
  return null;
58
59
  }
@@ -60,7 +61,8 @@ function readStoredTheme(): Theme | null {
60
61
 
61
62
  export interface ThemeProviderProps {
62
63
  /** Starting theme when the user has not chosen one yet; default "system". */
63
- defaultTheme?: Theme;
64
+ /** Today's theme name, or an earlier one ({@link LegacyTheme}), which resolves to it. */
65
+ defaultTheme?: Theme | LegacyTheme;
64
66
  children: ReactNode;
65
67
  }
66
68
 
@@ -70,13 +72,15 @@ export interface ThemeProviderProps {
70
72
  * `renderTerpApp` mounts one for every app; pair with {@link ThemeToggle} (the default
71
73
  * {@link UserMenu} already includes it).
72
74
  *
73
- * `defaultTheme` is how an app ships on a named theme — `defaultTheme="midnight"` and
75
+ * `defaultTheme` is how an app ships on a named theme — `defaultTheme="night"` and
74
76
  * nothing else — since it applies until the user chooses otherwise, INCLUDING when what they
75
77
  * choose is "system". Prefer declaring it in the app's own `frontend/layout-contract.json`,
76
78
  * which is the form a tool can read and rewrite.
77
79
  */
78
80
  export function ThemeProvider({ defaultTheme = "system", children }: ThemeProviderProps) {
79
- const [theme, setThemeState] = useState<Theme>(() => readStoredTheme() ?? defaultTheme);
81
+ const [theme, setThemeState] = useState<Theme>(
82
+ () => readStoredTheme() ?? resolveTheme(defaultTheme) ?? "system",
83
+ );
80
84
 
81
85
  useEffect(() => {
82
86
  const root = document.documentElement;
@@ -141,11 +145,15 @@ export function ThemeToggle({ variant = "stacked" }: ThemeToggleProps) {
141
145
  if (context === null) {
142
146
  return null;
143
147
  }
148
+ // The string keys keep the names the themes had when they were written (themeLight is
149
+ // midday's label, themeDark evening's, themeMidnight night's): an app shipping its own
150
+ // language catalog must supply every key, and renaming them would refuse that catalog for a
151
+ // change no reader sees. The VALUES are the new names.
144
152
  const labels: Record<Theme, string> = {
145
- light: strings.themeLight,
146
- dark: strings.themeDark,
147
- midnight: strings.themeMidnight,
153
+ midday: strings.themeLight,
148
154
  twilight: strings.themeTwilight,
155
+ evening: strings.themeDark,
156
+ night: strings.themeMidnight,
149
157
  contrast: strings.themeContrast,
150
158
  system: strings.themeSystem,
151
159
  };
package/src/themes.ts CHANGED
@@ -35,7 +35,19 @@
35
35
  * dark palette under `@media (prefers-color-scheme: dark)`, so `"system"` simply removes the
36
36
  * attribute.
37
37
  */
38
- export type Theme = "light" | "dark" | "midnight" | "twilight" | "contrast" | "system";
38
+ export type Theme = "midday" | "twilight" | "evening" | "night" | "contrast" | "system";
39
+
40
+ /**
41
+ * The names three themes had before they were renamed for the time of day they suit:
42
+ * `light` is now `midday`, `dark` is `evening` and `midnight` is `night`.
43
+ *
44
+ * Still accepted wherever a theme is NAMED -- a stored choice, `defaultTheme`, an app's
45
+ * `layout-contract.json`, a hand-written `data-theme` -- and mapped to today's name by
46
+ * {@link resolveTheme}, so no app changes palette because of the rename. The token sheet paints
47
+ * each one as the theme it now names (`aliases` in the contract's `themes.json`). New code
48
+ * writes the new names; these exist so old code and old storage keep working.
49
+ */
50
+ export type LegacyTheme = "light" | "dark" | "midnight";
39
51
 
40
52
  /**
41
53
  * Every value {@link Theme} admits, in the order the theme control offers them: the shipped
@@ -45,10 +57,33 @@ export type Theme = "light" | "dark" | "midnight" | "twilight" | "contrast" | "s
45
57
  * string, a JSON file and a bootstrap option are all `string` until something checks them.
46
58
  */
47
59
  export const THEMES: readonly Theme[] = [
48
- "light",
49
- "dark",
50
- "midnight",
60
+ "midday",
51
61
  "twilight",
62
+ "evening",
63
+ "night",
52
64
  "contrast",
53
65
  "system",
54
66
  ];
67
+
68
+ /** Each {@link LegacyTheme} and the theme it now names. Mirrors `aliases` in `themes.json`. */
69
+ export const THEME_ALIASES: Readonly<Record<LegacyTheme, Theme>> = {
70
+ light: "midday",
71
+ dark: "evening",
72
+ midnight: "night",
73
+ };
74
+
75
+ /**
76
+ * The theme a stored, declared or passed name stands for: itself if it is one, today's name if
77
+ * it is an earlier one, and `null` if it is neither. The one place an old name becomes a new
78
+ * one, so the provider, the layout declaration and the bootstrap all agree on it.
79
+ */
80
+ export function resolveTheme(name: string | null | undefined): Theme | null {
81
+ if (name === null || name === undefined) {
82
+ return null;
83
+ }
84
+ if ((THEMES as readonly string[]).includes(name)) {
85
+ return name as Theme;
86
+ }
87
+ // Own keys only: "constructor" is not a theme.
88
+ return Object.hasOwn(THEME_ALIASES, name) ? THEME_ALIASES[name as LegacyTheme] : null;
89
+ }
@@ -100,30 +100,28 @@ const UNREAD_TOKENS: Record<string, string[]> = {
100
100
  // `--color-border-` and `--color-chart-` are each STILL read by nothing, and the assertion
101
101
  // below requires a tracked family to publish more than it books — a deliberate "is the prefix
102
102
  // right?" check that a wholly-unread family would trip. The broader prefix subsumes them and
103
- // still catches the sixteenth. `--color-sidebar-` stays above because it makes a narrower
103
+ // still catches the next one. `--color-sidebar-` stays above because it makes a narrower
104
104
  // claim worth keeping: that family is read in full.
105
105
  //
106
- // None of these fourteen is a defect on its own. They are a published vocabulary that shipped
107
- // ahead of its consumers — three surface tokens, three borders, one interactive state, a
108
- // five-step chart ramp and two neutrals — and the point of booking them is that the list can
109
- // only shrink from here, so wiring one is visible and adding a fifteenth has to argue.
106
+ // None of these is a defect on its own. They are a published vocabulary that shipped ahead of
107
+ // its consumers — a surface token, borders, an interactive state, the chart ramp and two
108
+ // neutrals — and the point of booking them is that the list can only shrink from here, so
109
+ // wiring one is visible and adding one has to argue.
110
110
  //
111
111
  // --color-bg-surface came off it when the surface model went back to filling its in-flow
112
- // blocks: card, hubcard-body, profile-card, resource-list-row, empty-state, dataview-card and
113
- // the full DataView's frame all name it now. That is the shrink this list was booked for.
112
+ // blocks. --color-bg-canvas came off it when ADR 0169's surface ladder gave the page ground a
113
+ // reader: the body, the AppShell and the login view name it now. --color-bg-subtle, the
114
+ // ladder's new rung, shipped with its readers in the same change and so never joined. The
115
+ // chart ramp came off it with the charts of ADR 0169's fourth phase, which read all five.
116
+ // --color-border-strong came off it when every control's outline moved onto it from the raw
117
+ // neutral-300 step (ADR 0170), and --color-neutral-500 with it, as the hovered field's border
118
+ // one step past that outline: a theme now retunes the boundary of every control without
119
+ // repainting the disabled ink and the scrollbar that still read the ramp step.
114
120
  "--color-": [
115
- "--color-bg-canvas",
116
121
  "--color-bg-raised",
117
122
  "--color-border-default",
118
- "--color-border-strong",
119
123
  "--color-border-subtle",
120
- "--color-chart-1",
121
- "--color-chart-2",
122
- "--color-chart-3",
123
- "--color-chart-4",
124
- "--color-chart-5",
125
124
  "--color-interactive-active",
126
- "--color-neutral-500",
127
125
  "--color-neutral-800",
128
126
  ],
129
127
  };
@@ -108,7 +108,11 @@ export type TextWeight = "normal" | "medium" | "semibold";
108
108
  export interface TextProps extends Omit<HTMLAttributes<HTMLElement>, "style"> {
109
109
  /** The rendered element — `"p"` by default; `"span"` for text inside a line. */
110
110
  as?: "p" | "span" | "div";
111
- /** Ink tone (default `"default"`; `"muted"` for secondary copy, `"subtle"` for hints). */
111
+ /**
112
+ * Ink tone (default `"default"`). `"muted"` for secondary copy a reader still has to take in
113
+ * — a note, a hint, a caption. `"subtle"` only for what orients rather than informs — a
114
+ * count, a position, a timestamp — because it is held to a lower contrast (ADR 0170).
115
+ */
112
116
  tone?: TextTone;
113
117
  /** Type step (default `"base"`). */
114
118
  size?: TextSize;
@@ -1,5 +1,5 @@
1
1
  // @vitest-environment jsdom
2
- import { cleanup, render, screen } from "@testing-library/react";
2
+ import { cleanup, render, screen, within } from "@testing-library/react";
3
3
  import { afterEach, describe, expect, it } from "vitest";
4
4
 
5
5
  import { Alert } from "./Alert";
@@ -29,3 +29,26 @@ describe("Alert", () => {
29
29
  expect(screen.getByRole("status")).toHaveAttribute("data-tone", "info");
30
30
  });
31
31
  });
32
+
33
+ describe("Alert's actions (ADR 0169 §5)", () => {
34
+ it("renders what to do inside the alert, under its message", () => {
35
+ // The remedy belongs to the alert it answers; a second row beside it left the tint behind.
36
+ render(
37
+ <Alert tone="warning" actions={<button type="button">Revoke</button>}>
38
+ Access to a module that is no longer declared.
39
+ </Alert>,
40
+ );
41
+ const alert = screen.getByRole("alert");
42
+ const actions = alert.querySelector('[data-terp="alert-actions"]')!;
43
+ expect(actions).not.toBeNull();
44
+ expect(within(actions as HTMLElement).getByRole("button", { name: "Revoke" })).toBeInTheDocument();
45
+ });
46
+
47
+ it("renders no empty row for actions that render nothing", () => {
48
+ for (const actions of [undefined, null, false] as const) {
49
+ const { unmount } = render(<Alert actions={actions}>A message.</Alert>);
50
+ expect(document.querySelector('[data-terp="alert-actions"]')).toBeNull();
51
+ unmount();
52
+ }
53
+ });
54
+ });
package/src/ui/Alert.tsx CHANGED
@@ -13,6 +13,12 @@ export interface AlertProps {
13
13
  tone?: AlertTone;
14
14
  title?: UiText;
15
15
  children: ReactNode;
16
+ /**
17
+ * What the reader can do about it — one or two `Button`s, rendered inside the alert under its
18
+ * message (ADR 0169 §5). An action beside an alert used to be a second row the caller built,
19
+ * which separated the remedy from the problem it remedies and left the alert's tint behind.
20
+ */
21
+ actions?: ReactNode;
16
22
  }
17
23
 
18
24
  const glyphProps = {
@@ -68,7 +74,7 @@ const toneIcon: Record<AlertTone, ReactNode> = {
68
74
  * frame, the tint and the glyph from it, and the body restates the reading colour so the
69
75
  * copy stays neutral while the frame carries the tone (ADR 0094).
70
76
  */
71
- export function Alert({ tone = "info", title, children }: AlertProps) {
77
+ export function Alert({ tone = "info", title, children, actions }: AlertProps) {
72
78
  const resolve = useUiText();
73
79
  return (
74
80
  <div
@@ -80,6 +86,9 @@ export function Alert({ tone = "info", title, children }: AlertProps) {
80
86
  <div data-terp="alert-body">
81
87
  {title !== undefined && <strong data-terp="alert-title">{resolve(title)}</strong>}
82
88
  <div>{children}</div>
89
+ {actions !== undefined && actions !== null && actions !== false && (
90
+ <div data-terp="alert-actions">{actions}</div>
91
+ )}
83
92
  </div>
84
93
  </div>
85
94
  );
package/src/ui/Card.tsx CHANGED
@@ -56,10 +56,11 @@ export interface CardProps
56
56
  * A token-styled frame that groups one block of a page — the sanctioned way to give
57
57
  * sections visual separation (a border, a radius and padding) without module CSS, and
58
58
  * allowed directly in `OverviewPage` / `DetailPage` body slots under the `standard`
59
- * layout contract. It carries no fill: what shows through a card is the page's own
60
- * canvas, so a card sits on a themed background instead of repainting it. An optional header row carries a semantic `<h3>` title, a muted
61
- * description and an `actions` slot; the body stacks its children on the token
62
- * spacing scale.
59
+ * layout contract. A boxed card is a container, so it paints `--color-bg-subtle`, the
60
+ * rung of the surface ladder between the canvas and the surface where data is read
61
+ * (ADR 0169): a card steps back from the collection beside it rather than competing with
62
+ * it. An optional header row carries a semantic `<h3>` title, a muted description and an
63
+ * `actions` slot; the body stacks its children on the token spacing scale.
63
64
  */
64
65
  export function Card({
65
66
  variant = "boxed",
@@ -55,3 +55,47 @@ describe("Tabs with a single tab", () => {
55
55
  expect(screen.getByRole("tab", { name: "Only" })).toBeDisabled();
56
56
  });
57
57
  });
58
+
59
+ describe("Tabs on a strip too narrow for them", () => {
60
+ // jsdom lays nothing out, so the boxes are given: the strip is 100 to 300, and whichever tab
61
+ // is selected sits where each test puts it.
62
+ function boxes(selected: [number, number]) {
63
+ return vi
64
+ .spyOn(HTMLElement.prototype, "getBoundingClientRect")
65
+ .mockImplementation(function (this: HTMLElement) {
66
+ const at = (left: number, right: number) =>
67
+ ({ left, right, top: 0, bottom: 20, width: right - left, height: 20, x: left, y: 0 }) as DOMRect;
68
+ if (this.dataset.terp === "tab-list") return at(100, 300);
69
+ if (this.getAttribute("aria-selected") === "true") return at(...selected);
70
+ return at(0, 0);
71
+ });
72
+ }
73
+
74
+ it("scrolls the strip forward to a selected tab past its end, and follows the selection", () => {
75
+ const spy = boxes([320, 360]);
76
+ try {
77
+ render(<Tabs label="Sections" tabs={tabs} defaultValue="audit" />);
78
+ const list = screen.getByRole("tablist");
79
+ // Mutation: no scroll, which leaves the selected tab out of sight on a phone.
80
+ expect(list.scrollLeft).toBe(60);
81
+ fireEvent.click(screen.getByRole("tab", { name: "Overview" }));
82
+ // Mutation: scrolling on mount only, not as the selection moves.
83
+ expect(list.scrollLeft).toBe(120);
84
+ } finally {
85
+ spy.mockRestore();
86
+ }
87
+ });
88
+
89
+ it("scrolls it back to a selected tab before its start", () => {
90
+ // jsdom keeps a negative scroll position where a browser clamps it, which is what makes the
91
+ // backward step visible here.
92
+ const spy = boxes([60, 90]);
93
+ try {
94
+ render(<Tabs label="Sections" tabs={tabs} defaultValue="audit" />);
95
+ // Mutation: scrolling only forwards, which leaves a tab before the strip's start hidden.
96
+ expect(screen.getByRole("tablist").scrollLeft).toBe(-40);
97
+ } finally {
98
+ spy.mockRestore();
99
+ }
100
+ });
101
+ });
package/src/ui/Tabs.tsx CHANGED
@@ -1,6 +1,7 @@
1
- import { useId, useMemo, useState } from "react";
1
+ import { useId, useMemo, useRef, useState } from "react";
2
2
  import type { KeyboardEvent, ReactNode } from "react";
3
3
 
4
+ import { useCurrentInView } from "../currentInView";
4
5
  import { injectTerpStyles } from "../styles";
5
6
  import { useUiText } from "../uiText";
6
7
  import type { UiText } from "../uiText";
@@ -37,6 +38,8 @@ export function Tabs({ tabs, value, defaultValue, onChange, label }: TabsProps)
37
38
  // Nothing reports that — axe sees a well-formed reference to nothing. The same refusal to
38
39
  // interpolate caller strings into ids is written out at AppShell's nav-group labels.
39
40
  const selectedIndex = tabs.findIndex((tab) => tab.value === selectedTab?.value);
41
+ const list = useRef<HTMLDivElement>(null);
42
+ useCurrentInView(list, selectedTab?.value, '[aria-selected="true"]');
40
43
 
41
44
  // One usable tab is not a choice, so it gets no chrome. A tablist over a single tab costs
42
45
  // a row of the screen to offer nothing, and it is worse than decorative to a screen
@@ -92,7 +95,7 @@ export function Tabs({ tabs, value, defaultValue, onChange, label }: TabsProps)
92
95
 
93
96
  return (
94
97
  <div data-terp="tabs">
95
- <div role="tablist" data-terp="tab-list" aria-label={label === undefined ? undefined : resolve(label)} onKeyDown={onKeyDown}>
98
+ <div ref={list} role="tablist" data-terp="tab-list" aria-label={label === undefined ? undefined : resolve(label)} onKeyDown={onKeyDown}>
96
99
  {tabs.map((tab, index) => {
97
100
  const selected = tab.value === selectedTab?.value;
98
101
  return (