@terpjs/react-core 0.22.0 → 0.24.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.
package/README.md CHANGED
@@ -89,7 +89,7 @@ runtime, fail closed (ADR 0059), so every screen keeps the breadcrumb/title/erro
89
89
  | `navPlacement` (shell) | Where the primary navigation lives on desktop: `"sidebar"` (default, stamps nothing) or `"header"` — a horizontal row in the header with no sidebar at all, for an app whose destinations are few enough that 15rem of permanent chrome is a tax. The header then *becomes* the sidebar surface, so every `--color-sidebar-*` an app themes carries over and no property is overridden. Below the mobile breakpoint both placements are the drawer. `defaultCollapsed` is `never` under `"header"`: with no sidebar there is nothing to collapse. Available on `AppShell`, `buildAppRouter` and `renderTerpApp`. |
90
90
  | `contentWidth` (shell) | `"measured"` caps routed content at `--shell-content-max-width` while each page's own header keeps the full track — the subheader band. Default `"full"` stamps no attribute, so nothing moves until an app asks. Available on `AppShell`, `buildAppRouter` and `renderTerpApp`. |
91
91
  | `NavIcon`, `Icon`, `TerpMark`, `ICON_GLYPHS`, `ICON_NAMES` | The dependency-free icon layer. `ICON_NAMES` is published by `@terpjs/contract` as data and `IconName` is derived from it, so `NavItem.icon` and `Icon`'s `name` are **checked names** — a typo is a typecheck error, not a picture of nothing. `NavIcon`'s `name` stays a plain `string` on purpose: its unknown-name behaviour is a designed, visible fallback (the label's initial in a tile), while `Icon` rendered an empty box. The glyph table is held to the name set exhaustively in both directions by `satisfies`, so a glyph without a name or a name without a glyph fails to compile. The bundled catalogue covers common UI, action, object and status glyphs (home, list, folder, users, plus, edit, trash, search, check, x, chevron-{left,right,down}, arrow-left, external, logout, user, bell, key, globe, lock, tag, mail, refresh, filter, download, upload, star, heart, database, code, truck, cart, wallet, map-pin, clock, link, grid, book, briefcase, building, clipboard, layers, send, phone, image, video, music, wrench, zap, …). `TerpMark` is the placeholder brand mark until an app passes its own `logo`. |
92
- | `Page` | The base routed screen: one band carrying the breadcrumb trail — whose leaf **is** the view's single `h1` — plus `badges`, a truncated `description` lead line and the `actions` cluster, then the body with loading/error slots. Every page renders a trail, even one of a single crumb, so an overview's title sits where a detail's does. Inside a shell the band bleeds to the content column's edge and takes `--shell-header-height`; a `measure="narrow"` frame keeps the row and drops the chrome. |
92
+ | `Page` | The base routed screen: a band carrying the breadcrumb trail — whose leaf **is** the view's single `h1` — plus `badges`, a `description` lead line and the `actions` cluster, then the body with loading/error slots. The band places by grid area (ADR 0135): a page with badges or a lead line spends a second row on them and the cluster joins them there at no cost in height, which leaves the trail the whole first row; a page with neither keeps the single row. Crumbs ellipsise rather than wrap, and the lead line is shown only above the second cutover. Every page renders a trail, even one of a single crumb, so an overview's title sits where a detail's does. Inside a shell the band bleeds to the content column's edge and takes `--shell-header-height`; a `measure="narrow"` frame keeps the row and drops the chrome. |
93
93
  | `HubPage`, `HubCard` | Responsive `auto-fit` landing grid. Cards share equal outer and internal tracks even when descriptions/stats differ; nested hubs use the ordinary breadcrumb contract via `parents`. |
94
94
  | `OverviewPage` | A module's top-level listing screen (level 2); detail pages crumb back to it. |
95
95
  | `DetailPage` | One record's screen (level 3); breadcrumb trail = ancestors + record title. |
@@ -103,7 +103,7 @@ runtime, fail closed (ADR 0059), so every screen keeps the breadcrumb/title/erro
103
103
  | `useTerpNavigate` | Navigate by manifest path: `navigate({ to: "/records/:recordId", params: { recordId } })`. An undeclared path is a typecheck error and a parameterised route requires its params — a typo'd path used to be a dead link that shipped green. Takes the manifest's `:id` spelling and translates to the router's `$id`. |
104
104
  | `useRouteSearch` | Read a declared route's query-string keys, typed: `const { status, page } = useRouteSearch("/records")` (ADR 0096). Every value is `string | undefined`, and an undeclared key is a typecheck error — so a filtered list screen stays inside the checked seam instead of reaching for the router's own `useSearch`. Declare them in the manifest: `search: ["status", "page"]`. |
105
105
  | `ModuleNav` | Secondary horizontal tabs for intra-module sub-pages (real routes, not state). |
106
- | `PageActions` | Primary action + overflow menu for a page header. |
106
+ | `PageActions` | The page header's action cluster: `primary`, `secondary` nodes, `secondaryActions` descriptors and an `overflow` menu. The cluster follows the viewport — supporting actions drop to icons alone in the middle region and fold into the overflow menu below the first cutover — while the primary action keeps its label at every width. Only `secondaryActions` can follow the viewport: a `secondary` node's label is inside the caller's tree and can only be shown or hidden. |
107
107
 
108
108
  ### Typed route paths and params (generated, ADR 0092)
109
109
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terpjs/react-core",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "type": "module",
5
5
  "description": "Terp React stack core — typed @terpjs/contract client provider, auth session, capability gates, TanStack Router adapter, app shell, page archetypes, DataView and token-styled UI primitives. First frontend stack; see README.md for the component catalog.",
6
6
  "exports": {
@@ -13,8 +13,8 @@
13
13
  "test": "vitest run"
14
14
  },
15
15
  "dependencies": {
16
- "@tanstack/react-router": "^1.170.32",
17
- "@terpjs/contract": "^0.22.0"
16
+ "@tanstack/react-router": "^1.170.35",
17
+ "@terpjs/contract": "^0.24.0"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "react": "^19.0.0",
@@ -23,14 +23,14 @@
23
23
  "devDependencies": {
24
24
  "@testing-library/jest-dom": "^7.0.1",
25
25
  "@testing-library/react": "^16.3.3",
26
- "@types/react": "^19.2.18",
27
- "@types/react-dom": "^19.2.7",
26
+ "@types/react": "^19.3.0",
27
+ "@types/react-dom": "^19.3.0",
28
28
  "@vitejs/plugin-react": "^6.1.1",
29
29
  "jsdom": "^30.0.1",
30
- "react": "^19.2.7",
31
- "react-dom": "^19.2.7",
30
+ "react": "^19.3.0",
31
+ "react-dom": "^19.3.0",
32
32
  "typescript": "^5.9.3",
33
- "vite": "^8.2.2",
33
+ "vite": "^8.3.0",
34
34
  "vitest": "^5.0.0"
35
35
  },
36
36
  "license": "Apache-2.0",
package/src/Page.test.tsx CHANGED
@@ -106,6 +106,65 @@ describe("Page", () => {
106
106
  expect(bare.container.querySelector('[data-terp="page-description"]')).toBeNull();
107
107
  });
108
108
 
109
+ it("earns its second row only when there is meta to put on it", () => {
110
+ // The conditional half of ADR 0135. A page with badges or a lead line already spends a
111
+ // row on them, so the action cluster joining them costs no height; a page with neither
112
+ // keeps the single row and the measurement the chrome is held to. Both directions are
113
+ // asserted, because the attribute deciding the grid template is the whole mechanism.
114
+ const { container, rerender } = render(
115
+ <Page title="Tasks" actions={<Button>New</Button>}>
116
+ <p>body</p>
117
+ </Page>,
118
+ );
119
+ const bare = container.querySelector('[data-terp="page-header"]');
120
+ expect(bare?.hasAttribute("data-has-meta"), "nothing to show, so no second row").toBe(false);
121
+ expect(container.querySelector('[data-terp="page-meta"]'), "no empty group").toBeNull();
122
+
123
+ rerender(
124
+ <Page title="Tasks" description="A sentence." actions={<Button>New</Button>}>
125
+ <p>body</p>
126
+ </Page>,
127
+ );
128
+ const withMeta = container.querySelector('[data-terp="page-header"]');
129
+ expect(withMeta?.getAttribute("data-has-meta"), "a lead line earns the row").toBe("true");
130
+ expect(container.querySelector('[data-terp="page-meta"]')).not.toBeNull();
131
+ });
132
+
133
+ it("groups the action cluster even when the page passes loose nodes", () => {
134
+ // A page that passed a fragment used to put each button in the band as its own item,
135
+ // which the grid would scatter across cells it has no areas for. The wrapper is Page's,
136
+ // not PageActions', so it holds whether or not the page reached for that component.
137
+ const { container } = render(
138
+ <Page
139
+ title="Tasks"
140
+ actions={
141
+ <>
142
+ <Button>Discard</Button>
143
+ <Button>Publish</Button>
144
+ </>
145
+ }
146
+ >
147
+ <p>body</p>
148
+ </Page>,
149
+ );
150
+ const header = container.querySelector('[data-terp="page-header"]');
151
+ const cluster = container.querySelector('[data-terp="page-actions"]');
152
+ expect(cluster, "the cluster is always a group").not.toBeNull();
153
+ expect(cluster?.parentElement).toBe(header);
154
+ expect(cluster?.querySelectorAll("button")).toHaveLength(2);
155
+ // And the buttons are NOT direct children of the band, which is the failure this prevents.
156
+ expect(header?.querySelectorAll(':scope > button')).toHaveLength(0);
157
+ });
158
+
159
+ it("renders no cluster box at all when the page passes no actions", () => {
160
+ const { container } = render(
161
+ <Page title="Tasks">
162
+ <p>body</p>
163
+ </Page>,
164
+ );
165
+ expect(container.querySelector('[data-terp="page-actions"]')).toBeNull();
166
+ });
167
+
109
168
  it("takes several badges as one row, not one row each", () => {
110
169
  const { container } = render(
111
170
  <Page title="Fix the door" badges={[<span key="a">Open</span>, <span key="b">Urgent</span>]}>
package/src/Page.tsx CHANGED
@@ -175,11 +175,19 @@ export function Page({
175
175
  .concat(badges ?? [])
176
176
  .filter((badge) => badge !== false && badge !== null && badge !== undefined && badge !== "");
177
177
  // Same test for the lead line, for the same reason: `description={error && error.message}`.
178
+ const hasActions = actions !== undefined && actions !== null && actions !== false;
178
179
  const hasDescription =
179
180
  description !== undefined &&
180
181
  description !== null &&
181
182
  description !== false &&
182
183
  description !== "";
184
+ // The band's second row exists when there is meta to put on it, and the action cluster then
185
+ // shares it at no cost in height. A page with neither keeps the single row, and with it the
186
+ // measurement the chrome is held to: the band matches the app header above it.
187
+ const hasMeta = badgeList.length > 0 || hasDescription;
188
+ // Hoisted, the density/collapsed idiom: the default stamps nothing, so the expression has a
189
+ // branch rather than a boolean React would render as the string "false".
190
+ const metaAttribute = hasMeta ? "true" : undefined;
183
191
  const body =
184
192
  error !== null && error !== undefined ? (
185
193
  (errorState ?? <ErrorState error={error} />)
@@ -200,24 +208,37 @@ export function Page({
200
208
  additive; the tag is load-bearing. For the same reason the body below takes no
201
209
  wrapper of its own — not even a display: contents one, since article.children is a
202
210
  DOM traversal and would see it. */}
203
- <header data-terp="page-header">
211
+ <header data-terp="page-header" data-has-meta={metaAttribute}>
204
212
  <div data-terp="page-heading">
205
213
  {/* The trail carries the h1 as its leaf. No wrapper of its own any more: the crumb
206
214
  row it used to sit in existed to hold a 2rem floor above the title row, and
207
215
  there is no title row to be above. */}
208
216
  <Breadcrumbs items={trail} renderLink={renderLink} currentAs="h1" />
209
- {badgeList.length > 0 && (
210
- <div data-terp="page-badges">
211
- {badgeList.map((badge, index) => (
212
- <Fragment key={index}>{badge}</Fragment>
213
- ))}
217
+ {/* Badges and the lead line travel together as one grid item: with meta present
218
+ they share the band's second row with the action cluster, and a group is what
219
+ lets them be left of it rather than competing for the same cells. Rendered only
220
+ when there is something in it, because the empty box would still take a row. */}
221
+ {hasMeta && (
222
+ <div data-terp="page-meta">
223
+ {badgeList.length > 0 && (
224
+ <div data-terp="page-badges">
225
+ {badgeList.map((badge, index) => (
226
+ <Fragment key={index}>{badge}</Fragment>
227
+ ))}
228
+ </div>
229
+ )}
230
+ {hasDescription && (
231
+ <p data-terp="page-description">{resolveUiTextNode(description, resolve)}</p>
232
+ )}
214
233
  </div>
215
234
  )}
216
- {hasDescription && (
217
- <p data-terp="page-description">{resolveUiTextNode(description, resolve)}</p>
218
- )}
219
235
  </div>
220
- {actions}
236
+ {/* Always a group, never the caller's nodes loose in the band. A page that passed a
237
+ fragment of buttons used to put each one in the band as its own item, which the
238
+ grid would now scatter across cells it has no areas for. One wrapper means the
239
+ cluster is one item wherever the areas put it, whether or not the page reached
240
+ for PageActions. */}
241
+ {hasActions && <div data-terp="page-actions">{actions}</div>}
221
242
  </header>
222
243
  {/* Reset the slot for the body's own subtree, so nested content is never judged
223
244
  by an ancestor archetype's slot. */}
@@ -8,6 +8,35 @@ import { UiTextProvider } from "./uiText";
8
8
 
9
9
  afterEach(cleanup);
10
10
 
11
+ /**
12
+ * Put the cluster in one of its three regions.
13
+ *
14
+ * `readDensity` asks NARROW first and MEDIUM second, so the stub answers per query rather than
15
+ * with one boolean: a width in the middle region matches MEDIUM and not NARROW, and that pair
16
+ * is the only thing separating icons from a menu.
17
+ */
18
+ function stubRegion(region: "narrow" | "medium" | "roomy") {
19
+ vi.stubGlobal(
20
+ "matchMedia",
21
+ vi.fn().mockImplementation((query: string) => ({
22
+ matches:
23
+ query === "(max-width: 768px)"
24
+ ? region === "narrow"
25
+ : query === "(max-width: 1024px)"
26
+ ? region !== "roomy"
27
+ : false,
28
+ addEventListener: vi.fn(),
29
+ removeEventListener: vi.fn(),
30
+ })),
31
+ );
32
+ }
33
+
34
+ // A text-free icon on purpose: the icon-only assertion below is that the BOX carries no
35
+ // text, and a glyph that is itself text would satisfy it for the wrong reason.
36
+ const SUPPORTING = [
37
+ { label: "Discard", icon: <svg aria-hidden="true" focusable={false} />, onSelect: () => {} },
38
+ ];
39
+
11
40
  describe("PageActions", () => {
12
41
  it("returns no wrapper when no actions are supplied", () => {
13
42
  const { container } = render(<PageActions />);
@@ -92,6 +121,50 @@ describe("PageActions", () => {
92
121
  expect(screen.queryByRole("menu")).not.toBeInTheDocument();
93
122
  });
94
123
 
124
+ it("shows supporting actions as labelled buttons above the second cutover", () => {
125
+ stubRegion("roomy");
126
+ render(<PageActions primary={<Button>Publish</Button>} secondaryActions={SUPPORTING} />);
127
+ expect(screen.getByRole("button", { name: "Discard" })).toHaveTextContent("Discard");
128
+ expect(screen.queryByRole("button", { name: "More actions" })).toBeNull();
129
+ });
130
+
131
+ it("drops supporting actions to icons alone in the middle region, keeping their names", () => {
132
+ stubRegion("medium");
133
+ render(<PageActions primary={<Button>Publish</Button>} secondaryActions={SUPPORTING} />);
134
+ const discard = screen.getByRole("button", { name: "Discard" });
135
+ // The label moves to the accessible name rather than being dropped: the control has to
136
+ // read the same to a screen reader at every width, which is the whole cost of an icon.
137
+ expect(discard).toHaveTextContent("");
138
+ expect(discard).toHaveAttribute("title", "Discard");
139
+ // Still a button, not a menu — the fold happens at the FIRST cutover, not this one.
140
+ expect(screen.queryByRole("button", { name: "More actions" })).toBeNull();
141
+ });
142
+
143
+ it("folds supporting actions into the menu below the first cutover", () => {
144
+ stubRegion("narrow");
145
+ render(
146
+ <PageActions
147
+ primary={<Button>Publish</Button>}
148
+ secondaryActions={SUPPORTING}
149
+ overflow={[{ label: "Delete", variant: "destructive", onSelect: () => {} }]}
150
+ />,
151
+ );
152
+ // Gone from the band...
153
+ expect(screen.queryByRole("button", { name: "Discard" })).toBeNull();
154
+ // ...and present in the menu, above the page's own rare items.
155
+ fireEvent.click(screen.getByRole("button", { name: "More actions" }));
156
+ const items = screen.getAllByRole("menuitem").map((item) => item.textContent);
157
+ expect(items).toEqual(["Discard", "Delete"]);
158
+ });
159
+
160
+ it("keeps the primary action labelled at every width", () => {
161
+ // The decision ADR 0135 records: everything around the primary gives way, the primary
162
+ // never does. Asserted in the narrowest region, where the pressure to fold it is highest.
163
+ stubRegion("narrow");
164
+ render(<PageActions primary={<Button>Publish</Button>} secondaryActions={SUPPORTING} />);
165
+ expect(screen.getByRole("button", { name: "Publish" })).toHaveTextContent("Publish");
166
+ });
167
+
95
168
  it("localises the overflow trigger label", () => {
96
169
  render(
97
170
  <UiTextProvider strings={{ moreActions: "Meer acties" }}>
@@ -1,8 +1,11 @@
1
+ import { useEffect, useState } from "react";
1
2
  import type { ReactNode } from "react";
2
3
 
4
+ import { MEDIUM_VIEWPORT, NARROW_VIEWPORT } from "./breakpoints";
3
5
  import { injectTerpStyles } from "./styles";
6
+ import { Button } from "./ui/Button";
4
7
  import { Menu, MenuItem } from "./ui/Menu";
5
- import { useStrings } from "./uiText";
8
+ import { useStrings, useUiText } from "./uiText";
6
9
  import type { UiText } from "./uiText";
7
10
 
8
11
  injectTerpStyles();
@@ -23,29 +26,116 @@ export interface PageActionsProps {
23
26
  primary?: ReactNode;
24
27
  /** Supporting action(s), supplied by the page as styled element(s). */
25
28
  secondary?: ReactNode;
29
+ /**
30
+ * Supporting actions as DESCRIPTIONS rather than elements, which is what lets the cluster
31
+ * change form with the viewport: a label and an icon can be a button, an icon alone, or a
32
+ * line in a menu, and the same tuple renders all three. An element cannot — by the time a
33
+ * caller hands over a `<Button>` the label is inside someone else's tree, so `secondary`
34
+ * below can only ever be shown or hidden.
35
+ *
36
+ * Prefer this over `secondary` for anything that should survive a narrow viewport.
37
+ */
38
+ secondaryActions?: readonly OverflowAction[];
26
39
  /** Rare or destructive actions, kept out of the primary click path. */
27
40
  overflow?: readonly OverflowAction[];
28
41
  className?: string;
29
42
  }
30
43
 
31
- /** Standard right-aligned action cluster for page headers. */
32
- export function PageActions({ primary, secondary, overflow, className }: PageActionsProps) {
44
+ /**
45
+ * Which form the supporting actions take at this width.
46
+ *
47
+ * Read from the two cutovers rather than one: `labels` above the second, `icons` in the middle
48
+ * region, `menu` below the first. The regions come out of asking NARROW first and MEDIUM
49
+ * second — see ./breakpoints for why that is two queries and not three.
50
+ *
51
+ * `labels` is also the answer with no `window` at all, so a server render and a first paint
52
+ * agree on the widest form and hydration only ever takes things away.
53
+ */
54
+ type ActionDensity = "labels" | "icons" | "menu";
55
+
56
+ function readDensity(): ActionDensity {
57
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
58
+ return "labels";
59
+ }
60
+ if (window.matchMedia(NARROW_VIEWPORT).matches) {
61
+ return "menu";
62
+ }
63
+ if (window.matchMedia(MEDIUM_VIEWPORT).matches) {
64
+ return "icons";
65
+ }
66
+ return "labels";
67
+ }
68
+
69
+ function useActionDensity(): ActionDensity {
70
+ const [density, setDensity] = useState(readDensity);
71
+ useEffect(() => {
72
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
73
+ return;
74
+ }
75
+ // Both cutovers, because a drag across the middle region crosses one of them without
76
+ // touching the other and the cluster has to change form either way.
77
+ const narrow = window.matchMedia(NARROW_VIEWPORT);
78
+ const medium = window.matchMedia(MEDIUM_VIEWPORT);
79
+ const onChange = () => setDensity(readDensity());
80
+ narrow.addEventListener("change", onChange);
81
+ medium.addEventListener("change", onChange);
82
+ return () => {
83
+ narrow.removeEventListener("change", onChange);
84
+ medium.removeEventListener("change", onChange);
85
+ };
86
+ }, []);
87
+ return density;
88
+ }
89
+
90
+ function actionKey(action: OverflowAction): string {
91
+ return typeof action.label === "string" ? action.label : action.label.id;
92
+ }
93
+
94
+ /**
95
+ * Standard right-aligned action cluster for page headers.
96
+ *
97
+ * The primary action keeps its label at every width, and that is a decision rather than an
98
+ * oversight: it is the one thing the page is for, and a glyph or a menu line makes the main
99
+ * act of the screen a guess or a second tap. Everything around it gives way instead —
100
+ * `secondaryActions` drop to icons in the middle region and fold into the overflow menu below
101
+ * the first cutover, where they sit above the page's own rare and destructive items.
102
+ */
103
+ export function PageActions({
104
+ primary,
105
+ secondary,
106
+ secondaryActions,
107
+ overflow,
108
+ className,
109
+ }: PageActionsProps) {
33
110
  const strings = useStrings();
34
- const hasOverflow = overflow !== undefined && overflow.length > 0;
111
+ const resolve = useUiText();
112
+ const density = useActionDensity();
113
+ const supporting = secondaryActions ?? [];
114
+ const rare = overflow ?? [];
115
+ // Below the first cutover the supporting actions stop being buttons and become the top of
116
+ // the menu. Order is deliberate: what the page offers first, then what it keeps back.
117
+ const inMenu = density === "menu" ? [...supporting, ...rare] : rare;
118
+ const asButtons = density === "menu" ? [] : supporting;
119
+ const hasMenu = inMenu.length > 0;
35
120
 
36
- if (primary === undefined && secondary === undefined && !hasOverflow) {
121
+ if (
122
+ primary === undefined &&
123
+ secondary === undefined &&
124
+ supporting.length === 0 &&
125
+ rare.length === 0
126
+ ) {
37
127
  return null;
38
128
  }
39
129
 
40
130
  return (
41
131
  <div className={className} data-terp="page-actions">
42
- {hasOverflow && (
132
+ {hasMenu && (
43
133
  <Menu trigger="⋯" triggerLabel={strings.moreActions}>
44
134
  {({ close }) => (
45
135
  <>
46
- {overflow.map((action) => (
136
+ {inMenu.map((action) => (
47
137
  <MenuItem
48
- key={typeof action.label === "string" ? action.label : action.label.id}
138
+ key={actionKey(action)}
49
139
  label={action.label}
50
140
  icon={action.icon}
51
141
  destructive={action.variant === "destructive"}
@@ -60,6 +150,33 @@ export function PageActions({ primary, secondary, overflow, className }: PageAct
60
150
  )}
61
151
  </Menu>
62
152
  )}
153
+ {asButtons.map((action) => {
154
+ const label = resolve(action.label);
155
+ // Icon-only still has to SAY what it is: the label moves from the box to the
156
+ // accessible name and the tooltip rather than being dropped, so the control reads the
157
+ // same to a screen reader at every width and hovers legibly for everyone else.
158
+ return density === "icons" && action.icon !== undefined ? (
159
+ <Button
160
+ key={actionKey(action)}
161
+ variant={action.variant === "destructive" ? "danger" : "secondary"}
162
+ icon={action.icon}
163
+ aria-label={label}
164
+ title={label}
165
+ disabled={action.disabled}
166
+ onClick={action.onSelect}
167
+ />
168
+ ) : (
169
+ <Button
170
+ key={actionKey(action)}
171
+ variant={action.variant === "destructive" ? "danger" : "secondary"}
172
+ icon={action.icon}
173
+ disabled={action.disabled}
174
+ onClick={action.onSelect}
175
+ >
176
+ {label}
177
+ </Button>
178
+ );
179
+ })}
63
180
  {secondary}
64
181
  {primary}
65
182
  </div>
@@ -1,41 +1,70 @@
1
1
  /**
2
- * The one viewport cutover the framework has, in the one place it is written.
2
+ * The viewport cutovers the framework has, in the one place they are written.
3
3
  *
4
- * It was written in three: `AppShell` and `DataView` each declared
4
+ * They were written in three: `AppShell` and `DataView` each declared
5
5
  * `const MOBILE_BREAKPOINT = "(max-width: 768px)"` verbatim — the duplication the diagnosis
6
6
  * named — and the responsive `Stack` props would have made a third copy, this time in the
7
7
  * stylesheet where the first two could not see it.
8
8
  *
9
- * ## Why the value is a literal and not `var(--breakpoint-md)`
9
+ * ## Why the values are literals and not `var(--breakpoint-md)`
10
10
  *
11
- * The contract publishes `--breakpoint-md: 768px`, and neither consumer can read it. CSS
12
- * forbids a custom property in a media-query condition, and `matchMedia` takes a string, so
13
- * a component would have to resolve the property off `document.documentElement` at runtime —
14
- * which is a layout read on every mount, breaks under SSR where there is no document, and
15
- * turns a static query into a value that can change after first paint.
11
+ * The contract publishes `--breakpoint-md: 768px` and `--breakpoint-lg: 1024px`, and neither
12
+ * consumer can read them. CSS forbids a custom property in a media-query condition, and
13
+ * `matchMedia` takes a string, so a component would have to resolve the property off
14
+ * `document.documentElement` at runtime — which is a layout read on every mount, breaks under
15
+ * SSR where there is no document, and turns a static query into a value that can change after
16
+ * first paint.
16
17
  *
17
- * So the literal stays, and the drift it invites is gated instead:
18
- * `styles.test.ts` reads `--breakpoint-md` out of the contract's token sheet and refuses a
19
- * mismatch here or in the stylesheet. The token remains the published source of truth about
20
- * what the number IS; this module is the single place it is spelled for use.
18
+ * So the literals stay, and the drift they invite is gated instead:
19
+ * `tokens.guard.test.ts` reads `--breakpoint-md` and `--breakpoint-lg` out of the contract's
20
+ * token sheet and refuses a mismatch here or in the stylesheet. The tokens remain the
21
+ * published source of truth about what the numbers ARE; this module is the single place they
22
+ * are spelled for use.
21
23
  *
22
- * ## Why WIDE is a negation
24
+ * ## Why WIDE and ROOMY are negations
23
25
  *
24
- * `NARROW` and `WIDE` have to partition the viewport exactly: a width that satisfies both
26
+ * A cutover's two sides have to partition the viewport exactly: a width that satisfied both
25
27
  * would render the shell's drawer beside a row-direction toolbar, and a width satisfying
26
28
  * neither would render nothing at all. Two independent queries cannot guarantee that — the
27
29
  * conventional pairing is `max-width: 767.98px` with `min-width: 768px`, which works but
28
30
  * makes the partition depend on an epsilon somebody chose, and picking one here would also
29
31
  * have moved the shell's existing behaviour at exactly 768px.
30
32
  *
31
- * `not all and (max-width: 768px)` is the complement of `NARROW` by construction. The
33
+ * `not all and (max-width: N)` is the complement of `(max-width: N)` by construction. The
32
34
  * `not all and` spelling rather than the shorter `not (…)` because it is the form every
33
35
  * browser has supported since media queries existed, and this is a stylesheet a consumer
34
36
  * cannot patch.
37
+ *
38
+ * ## Why two cutovers still make no third query
39
+ *
40
+ * The page band wants three regions, not two: below 768 it drops its lead line and folds its
41
+ * action cluster to a menu, between 768 and 1024 it keeps the cluster but shows icons alone,
42
+ * and above 1024 it shows everything. The obvious spelling of a middle region is an
43
+ * `and` of a min and a max — which reintroduces exactly the epsilon the cutover above refuses,
44
+ * and, worse, needs a negation nested inside an `and` that Media Queries 3 has no syntax for.
45
+ *
46
+ * So the regions are not three queries; they are two cutovers applied in cascade order. A rule
47
+ * block writes the narrow case unconditionally, `WIDE_VIEWPORT_QUERY` corrects it for
48
+ * everything above the first cutover, and `ROOMY_VIEWPORT_QUERY` corrects it again for
49
+ * everything above the second. The middle region is what the first correction leaves standing
50
+ * when the second does not apply — never named, never queried, and therefore never able to
51
+ * disagree with its neighbours about who owns 768px or 1024px.
52
+ *
53
+ * `matchMedia` callers get the same shape from the other end: a component asks `NARROW` first
54
+ * and `MEDIUM` second, and the first match wins.
35
55
  */
36
56
 
37
57
  /** The condition both narrow-viewport components match on (`matchMedia`, so no `@media`). */
38
58
  export const NARROW_VIEWPORT = "(max-width: 768px)";
39
59
 
40
- /** The stylesheet's complement of {@link NARROW_VIEWPORT} — everything above the cutover. */
60
+ /** The stylesheet's complement of {@link NARROW_VIEWPORT} — everything above the first cutover. */
41
61
  export const WIDE_VIEWPORT_QUERY = "not all and (max-width: 768px)";
62
+
63
+ /**
64
+ * At or below the second cutover — narrow AND the middle region together. Asked after
65
+ * {@link NARROW_VIEWPORT}, so a match that is not already narrow IS the middle region.
66
+ */
67
+ export const MEDIUM_VIEWPORT = "(max-width: 1024px)";
68
+
69
+ /** The stylesheet's complement of {@link MEDIUM_VIEWPORT} — everything above the second cutover. */
70
+ export const ROOMY_VIEWPORT_QUERY = "not all and (max-width: 1024px)";
package/src/index.ts CHANGED
@@ -171,6 +171,7 @@ export type {
171
171
  TextProps,
172
172
  TextTone,
173
173
  TextSize,
174
+ TextWeight,
174
175
  CodeProps,
175
176
  LinkProps,
176
177
  } from "./typography";
@@ -207,6 +207,7 @@ const MARKERS = [
207
207
  "page-description",
208
208
  "page-header",
209
209
  "page-heading",
210
+ "page-meta",
210
211
  "page-title",
211
212
  "popover",
212
213
  "popover-panel",
@@ -1,6 +1,7 @@
1
1
  // @vitest-environment jsdom
2
2
  import { afterEach, describe, expect, it } from "vitest";
3
3
 
4
+ import { ROOMY_VIEWPORT_QUERY } from "./breakpoints";
4
5
  import { TERP_STYLES_ID, TERP_STYLES_CSS, injectTerpStyles } from "./styles";
5
6
 
6
7
  /** The sheet with comments removed — prose must not satisfy a structural assertion. */
@@ -946,6 +947,22 @@ describe("cascade structure", () => {
946
947
  expect(base.slice(termAt, base.indexOf("}", termAt))).not.toContain("color:");
947
948
  });
948
949
 
950
+ it("gives body copy an emphasis step without re-weighting the copy that asks for none", () => {
951
+ const base = layerBody("terp.base");
952
+ // Both steps read the published weight tokens rather than a literal.
953
+ expect(base).toContain(
954
+ '[data-terp="text"][data-weight="medium"] { font-weight: var(--font-weight-medium); }',
955
+ );
956
+ expect(base).toContain(
957
+ '[data-terp="text"][data-weight="semibold"] { font-weight: var(--font-weight-semibold); }',
958
+ );
959
+ // The base rule states no weight on purpose: a Text that asks for none keeps
960
+ // inheriting what it inherited before the axis existed, so nothing re-renders.
961
+ const textAt = base.indexOf('[data-terp="text"] {');
962
+ expect(textAt, "the base text rule should exist").toBeGreaterThan(-1);
963
+ expect(base.slice(textAt, base.indexOf("}", textAt))).not.toContain("font-weight");
964
+ });
965
+
949
966
  it("keeps a Card's actions slot on the title's line, description or not", () => {
950
967
  // The measured inconsistency: `actions` is documented as a header-row slot and delivered
951
968
  // one only while `description` was unset. The heading declared min-width: 0 alone, so it
@@ -986,43 +1003,87 @@ describe("cascade structure", () => {
986
1003
  expect(base.slice(headerAt, base.indexOf("}", headerAt))).toContain("align-items: center");
987
1004
  });
988
1005
 
989
- it("keeps the page band one row: trail, description and actions", () => {
990
- // Measured in Chromium at a 1024px viewport, against these exact declarations, with a
991
- // description too long for the space left beside the trail:
1006
+ it("lays the page band out in areas, and spends a second row only when one is earned", () => {
1007
+ // What this replaced, and why the argument had to change shape. The band was a wrapping
1008
+ // flex row, and the bug it kept producing was always the same one: flex collects items
1009
+ // into lines using HYPOTHETICAL main sizes and only shrinks what is already on a line, so
1010
+ // any item whose max-content was wide -- a deep trail, an unwrapped sentence -- took the
1011
+ // line and pushed the action cluster onto the next one. A zero basis bought the single
1012
+ // row back, and measured 48px against 76px, which is why it was pinned here.
992
1013
  //
993
- // flex: 1 1 auto -> band 76px tall, h1 at top 0, description 1024px wide on its own
994
- // line, actions on a THIRD line, and no ellipsis anywhere
995
- // flex: 1 1 0 -> band 48px (the header's height), h1 / description / actions all
996
- // on one row, description ellipsised
1014
+ // Two things that basis could never fix, both of which arrive the moment the band DOES
1015
+ // wrap. Wrap order follows source order, so the meta group and the cluster cannot share a
1016
+ // row while staying two groups. And justify-content: space-between then has free space to
1017
+ // distribute, which scatters a page's buttons across the full width -- or left-aligns a
1018
+ // single cluster on the row whose whole job was to right-align it.
997
1019
  //
998
- // Page.tsx promises the second ("badges and description sit after the title and actions
999
- // at the right edge, all on that one line") and the sheet shipped the first. The
1000
- // description already declared min-width: 0, overflow: hidden and text-overflow, so the
1001
- // truncation looked wired -- but flex collects items into lines using HYPOTHETICAL main
1002
- // sizes and only shrinks what is already on a line, so an auto basis wraps the box before
1003
- // any of those three can run. This is the same defect card-heading fixed, one component
1004
- // over; that test records the same argument from the other end.
1020
+ // Areas answer both by construction: nothing is placed by flow and no free space is
1021
+ // distributed anywhere, so neither failure has a place to happen.
1005
1022
  const base = layerBody("terp.base");
1023
+ const headerAt = base.indexOf('[data-terp="page-header"] {');
1024
+ expect(headerAt, "page-header should have a base rule").toBeGreaterThan(-1);
1025
+ const header = base.slice(headerAt, base.indexOf("}", headerAt));
1026
+ expect(header, "the band places by area, never by flow").toContain("display: grid");
1027
+ // minmax(0, 1fr) rather than 1fr: a grid track's automatic minimum is its content's, so a
1028
+ // long unbreakable title would refuse to shrink past it and push the cluster out of the
1029
+ // band. This is the same job the old zero flex basis did, done by the track instead.
1030
+ expect(header, "the trail column must be allowed to shrink below its content").toContain(
1031
+ "grid-template-columns: minmax(0, 1fr) auto",
1032
+ );
1033
+ expect(header, "with nothing else to show, the band is one row").toContain(
1034
+ 'grid-template-areas: "trail actions"',
1035
+ );
1036
+ // The second row, and the reason it is conditional. A page with badges or a lead line
1037
+ // already spends a row on them, so the cluster joining them costs no height at all -- and
1038
+ // it buys the trail the whole first row, which is what stops a deep trail truncating. A
1039
+ // page with neither keeps the single row, and with it the measurement the chrome is held
1040
+ // to further down this file: the band matches the app header above it.
1041
+ const metaAt = base.indexOf('[data-terp="page-header"][data-has-meta] {');
1042
+ expect(metaAt, "the two-row band should have a rule of its own").toBeGreaterThan(-1);
1043
+ const withMeta = base.slice(metaAt, base.indexOf("}", metaAt));
1044
+ expect(withMeta, "the trail owns the first row outright once there is a second").toContain(
1045
+ '"trail trail"',
1046
+ );
1047
+ expect(withMeta, "meta sits left of the cluster on the second row").toContain(
1048
+ '"meta actions"',
1049
+ );
1050
+ // Same-height lines. 1fr rather than auto, and in a box whose height nobody declared that
1051
+ // is not a share of anything: fr rows in an indefinite container resolve to the LARGEST
1052
+ // row's content, so both lines come out at the taller one. Two content-sized rows would be
1053
+ // a short trail line above a tall control line, which reads as two bands rather than one
1054
+ // of two lines. The computed half is next door in the workbench, which measures the
1055
+ // resolved tracks rather than the box: a total carries the gap and the border too, so only
1056
+ // the tracks can say whether the two lines actually agree.
1057
+ expect(withMeta, "a band of two lines gives them the same height").toContain(
1058
+ "grid-auto-rows: 1fr",
1059
+ );
1060
+ // The left group generates no box, which is what lets its two children be grid items of
1061
+ // the BAND and therefore sit on different rows. The marker survives for the scanner.
1006
1062
  const headingAt = base.indexOf('[data-terp="page-heading"] {');
1007
1063
  expect(headingAt, "page-heading should have a base rule").toBeGreaterThan(-1);
1008
1064
  const heading = base.slice(headingAt, base.indexOf("}", headingAt));
1009
- expect(heading, "an auto basis wraps the action cluster onto its own line").toContain(
1010
- "flex: 1 1 0",
1065
+ expect(heading, "a boxed wrapper would put the trail and the meta in one cell").toContain(
1066
+ "display: contents",
1011
1067
  );
1012
- expect(heading, "min-width: 0 is what lets an unbreakable title shrink").toContain(
1013
- "min-width: 0",
1014
- );
1015
- // The lead line needs the same, one level in: nowrap makes its max-content the whole
1016
- // sentence, so an auto basis breaks the heading's own line before it can ellipsise.
1068
+ // The lead line is written as a correction, not a rule: hidden everywhere, shown again
1069
+ // above the SECOND cutover. That is what makes three regions out of two queries -- the
1070
+ // middle one is the width at which this correction has not applied yet.
1017
1071
  const descAt = base.indexOf('[data-terp="page-description"] {');
1018
1072
  expect(descAt, "page-description should have a base rule").toBeGreaterThan(-1);
1019
1073
  const description = base.slice(descAt, base.indexOf("}", descAt));
1020
- expect(description, "an auto basis gives the lead line its own row").toContain("flex: 1 1 0");
1021
- // And the three declarations that do the truncating, which are only reachable from a
1022
- // line the box actually shares.
1023
- expect(description).toContain("min-width: 0");
1024
- expect(description).toContain("white-space: nowrap");
1025
- expect(description).toContain("text-overflow: ellipsis");
1074
+ expect(description, "the lead line is the first thing to go when room is short").toContain(
1075
+ "display: none",
1076
+ );
1077
+ const roomy = base.indexOf(`@media ${ROOMY_VIEWPORT_QUERY}`);
1078
+ expect(roomy, "the lead line comes back above the second cutover").toBeGreaterThan(descAt);
1079
+ // And the truncation, which still matters on the row it does get: the sentence shares
1080
+ // that row with the badges, so its max-content must not decide the row's width.
1081
+ const shown = base.slice(base.indexOf('[data-terp="page-description"] {', roomy));
1082
+ expect(shown).toContain("display: block");
1083
+ const full = base.slice(base.lastIndexOf('[data-terp="page-description"] {'));
1084
+ expect(full).toContain("min-width: 0");
1085
+ expect(full).toContain("white-space: nowrap");
1086
+ expect(full).toContain("text-overflow: ellipsis");
1026
1087
  });
1027
1088
 
1028
1089
  it("gives the breadcrumb trail one line box, leaf included", () => {
package/src/styles.ts CHANGED
@@ -103,7 +103,7 @@
103
103
  * touched.
104
104
  */
105
105
 
106
- import { WIDE_VIEWPORT_QUERY } from "./breakpoints";
106
+ import { ROOMY_VIEWPORT_QUERY, WIDE_VIEWPORT_QUERY } from "./breakpoints";
107
107
 
108
108
  /** The `<style>` element id used to detect a prior injection. */
109
109
  export const TERP_STYLES_ID = "terp-core-styles";
@@ -564,12 +564,15 @@ textarea[data-terp="input"] {
564
564
  Same for every gap pair. styles.test.ts pins the order, because getting it backwards
565
565
  renders the narrow value at every width and looks like the prop not working.
566
566
 
567
- The query is INTERPOLATED from ./breakpoints, which is the one \${…} in this sheet and is
568
- deliberate rather than a slip: it is the complement of the exact string AppShell and
569
- DataView hand to matchMedia, so the two halves of the cutover partition the viewport by
570
- construction. Written out here they would be two literals that agree until someone edits
571
- one. (The convention of grepping this literal for \${ still holds — there should be
572
- exactly this one.) */
567
+ The query is INTERPOLATED from ./breakpoints, and that is deliberate rather than a slip:
568
+ it is the complement of the exact string AppShell and DataView hand to matchMedia, so the
569
+ two halves of the cutover partition the viewport by construction. Written out here they
570
+ would be two literals that agree until someone edits one.
571
+
572
+ There are TWO \${…} in this sheet now, one per cutover — this one and the page band's
573
+ ROOMY block. Both come from ./breakpoints and neither spells a number, which is the
574
+ property worth grepping for: a third interpolation is fine if it names a constant from
575
+ that module, and a literal pixel width in a media query here is not. */
573
576
  @media ${WIDE_VIEWPORT_QUERY} {
574
577
  [data-terp="stack"][data-direction-wide="column"] { flex-direction: column; }
575
578
  [data-terp="stack"][data-direction-wide="row"] { flex-direction: row; }
@@ -1183,6 +1186,12 @@ textarea[data-terp="input"] {
1183
1186
  font-size: var(--font-size-lg);
1184
1187
  line-height: var(--font-line-height-relaxed);
1185
1188
  }
1189
+ /* Emphasis. Opt-in only: the base rule deliberately sets no font-weight, so a Text that
1190
+ asks for nothing keeps inheriting exactly what it inherited before this axis existed.
1191
+ Stating the default here would be tidier and would re-weight every Text nested in an
1192
+ emphasised container, which is a rendering change dressed as a tidy-up. */
1193
+ [data-terp="text"][data-weight="medium"] { font-weight: var(--font-weight-medium); }
1194
+ [data-terp="text"][data-weight="semibold"] { font-weight: var(--font-weight-semibold); }
1186
1195
  [data-terp="text"][data-tone="muted"] { color: var(--color-fg-muted); }
1187
1196
  [data-terp="text"][data-tone="subtle"] { color: var(--color-fg-subtle); }
1188
1197
  [data-terp="text"][data-measure="narrow"] { max-width: 48ch; }
@@ -1374,15 +1383,39 @@ textarea[data-terp="input"] {
1374
1383
  line-height: var(--font-line-height-snug);
1375
1384
  color: var(--color-neutral-600);
1376
1385
  }
1386
+ /* NOWRAP on both, and the li is the one that matters. A crumb's chevron lives inside the li
1387
+ beside its label, so a wrapping li let a long label push its own separator onto the next
1388
+ line -- where it sat at the start of the row pointing at nothing. The ol follows for the
1389
+ band's sake: the trail is one row of the grid, and a trail that wraps is a row whose height
1390
+ nobody declared.
1391
+
1392
+ What gives instead is the text, below. Every crumb can shrink and ellipsise, so a deep
1393
+ trail degrades by losing characters rather than by growing the chrome. */
1377
1394
  [data-terp="breadcrumbs"] ol,
1378
1395
  [data-terp="breadcrumbs"] li {
1379
1396
  list-style: none;
1380
1397
  margin: 0;
1381
1398
  padding: 0;
1382
1399
  display: flex;
1383
- flex-wrap: wrap;
1400
+ flex-wrap: nowrap;
1384
1401
  align-items: center;
1385
1402
  gap: var(--space-2);
1403
+ min-width: 0;
1404
+ }
1405
+ /* Each crumb's own text: shrinkable, and cut rather than wrapped. The automatic minimum of a
1406
+ flex item is its content's, so min-width: 0 is what admits the other three declarations --
1407
+ the same pairing the lead line makes, one level in. */
1408
+ [data-terp="breadcrumbs"] li > a,
1409
+ [data-terp="breadcrumbs"] li > h1,
1410
+ [data-terp="breadcrumbs"] li > span:not([data-terp="breadcrumbs-separator"]) {
1411
+ min-width: 0;
1412
+ overflow: hidden;
1413
+ white-space: nowrap;
1414
+ text-overflow: ellipsis;
1415
+ }
1416
+ /* The chevron is 0.85em of glyph and never the thing worth losing. */
1417
+ [data-terp="breadcrumbs"] li > [data-terp="breadcrumbs-separator"] {
1418
+ flex: 0 0 auto;
1386
1419
  }
1387
1420
  /* Keyed on our own marker, not on [aria-current="page"]. The trail's ancestor
1388
1421
  crumbs are the app router's links, and TanStack stamps aria-current="page" on
@@ -1975,35 +2008,85 @@ textarea[data-terp="input"] {
1975
2008
  meeting a wide action cluster takes a second line instead of overflowing — and the band
1976
2009
  grows past its floor when it does. */
1977
2010
  [data-terp="page-header"] {
1978
- display: flex;
1979
- flex-wrap: wrap;
2011
+ display: grid;
2012
+ grid-template-columns: minmax(0, 1fr) auto;
2013
+ grid-template-areas: "trail actions";
1980
2014
  align-items: center;
1981
- justify-content: space-between;
1982
2015
  gap: var(--space-2) var(--space-4);
1983
2016
  min-width: 0;
1984
2017
  }
1985
- /* The band's left group: the trail (whose leaf is the h1), then badges, then the lead line.
1986
- A base size of ZERO, and that is the whole of what keeps the band one row. The comment
1987
- here used to claim a flex of 1 1 auto with min-width: 0 was what let the lead line truncate
1988
- instead of pushing the action cluster off the row, and it is the same mistake Card made
1989
- and fixed (see card-heading, and the test that records the measurement): flex collects
1990
- items into lines using their HYPOTHETICAL main sizes, and only then shrinks what is on a
1991
- line. With an auto basis the heading's hypothetical size is the max-content width of a
1992
- trail AND a sentence, so with the band's flex-wrap the heading takes the line and the
1993
- actions wrap underneath -- and the description, having reached its own line, has room and
1994
- never ellipsises. Neither of the two things the comment promised actually held.
1995
-
1996
- min-width: 0 stays, for the other half: a flex item's automatic minimum is its content's,
1997
- so a long unbreakable title would otherwise refuse to shrink past it. Both are asserted in
1998
- styles.test.ts, because dropping either brings a different half of the bug back. */
2018
+ /* The two-row band, and it costs nothing to the pages that get it. A page with badges or a
2019
+ lead line ALREADY spends a second row on them; putting the action cluster there too fills
2020
+ space that was empty, and it buys the trail the whole of the first row -- which is what
2021
+ stops a deep trail having to truncate at all. A page with neither keeps the single row,
2022
+ and with it the promise the chrome is measured against: the band matches the app header
2023
+ above it.
2024
+
2025
+ A grid rather than the flex-wrap this was: wrap order follows source order, so the meta
2026
+ group and the cluster could not share a row while staying two groups, and the moment the
2027
+ band did wrap justify-content: space-between had free space to distribute -- which
2028
+ spread a page's buttons across the full width, or left-aligned a single cluster on a row
2029
+ whose whole job was to right-align it. Areas say where things go and no free space is
2030
+ distributed anywhere, so neither failure has anywhere to happen. */
2031
+ [data-terp="page-header"][data-has-meta] {
2032
+ grid-template-areas:
2033
+ "trail trail"
2034
+ "meta actions";
2035
+ /* Same-height lines, and 1fr is what spells that in a box whose height nobody declared:
2036
+ with an indefinite container the fr rows resolve to the LARGEST row's content rather
2037
+ than to a share of a height that does not exist, so both rows come out at the taller
2038
+ one. A band of two content-sized rows would otherwise be a short trail line above a
2039
+ tall control line, which reads as two different bands rather than one of two lines. */
2040
+ grid-auto-rows: 1fr;
2041
+ }
2042
+ /* The band's left group, and it generates NO box. The trail and the meta group have to be
2043
+ grid items of the band itself -- they sit on different rows -- but the marker is published
2044
+ and a wrapper that boxed them would put them both in one cell. display: contents is the
2045
+ sheet's existing answer to exactly that shape (see the markdown wrapper): the children
2046
+ stay in flow as the grid's own items, and the marker survives for the scanner and for
2047
+ anything reading the DOM.
2048
+
2049
+ The flex basis this used to carry is gone with the box. What it bought -- a heading that
2050
+ shrinks instead of pushing the cluster off the row -- is now the grid's minmax(0, 1fr)
2051
+ first column, which does the same job by construction rather than by getting a flex
2052
+ hypothetical size right. */
1999
2053
  [data-terp="page-heading"] {
2054
+ display: contents;
2055
+ }
2056
+ /* The trail owns the first row outright once there is a second one to own. */
2057
+ [data-terp="page-header"] > [data-terp="breadcrumbs"] {
2058
+ grid-area: trail;
2059
+ min-width: 0;
2060
+ }
2061
+ /* Badges and the lead line, grouped so they share the second row as one left-hand item
2062
+ rather than competing for cells with the cluster opposite them. */
2063
+ [data-terp="page-meta"] {
2064
+ grid-area: meta;
2000
2065
  display: flex;
2001
2066
  flex-wrap: wrap;
2002
2067
  align-items: center;
2003
2068
  gap: var(--space-2) var(--space-3);
2004
- flex: 1 1 0;
2005
2069
  min-width: 0;
2006
2070
  }
2071
+ [data-terp="page-header"] > [data-terp="page-actions"] {
2072
+ grid-area: actions;
2073
+ }
2074
+ /* The lead line is desktop-only, and it is written as the correction rather than the rule:
2075
+ hidden at every width, shown again above the SECOND cutover. Mobile-first in the literal
2076
+ sense, and it is what lets the three regions come out of two queries (see ./breakpoints) —
2077
+ the middle region is simply the width at which this correction has not applied yet.
2078
+
2079
+ A sentence about the page is the first thing to go when the band is short of room: the
2080
+ trail says where you are and the cluster says what you can do, and neither has a smaller
2081
+ form that still works. */
2082
+ [data-terp="page-description"] {
2083
+ display: none;
2084
+ }
2085
+ @media ${ROOMY_VIEWPORT_QUERY} {
2086
+ [data-terp="page-description"] {
2087
+ display: block;
2088
+ }
2089
+ }
2007
2090
  /* The single h1 of the view, and now also the trail's current crumb: one node instead of two
2008
2091
  copies of one string. margin: 0 is load-bearing twice over — the browser default h1 margin
2009
2092
  would fight the band's own gap, and an h1 inside the trail's <li> would otherwise break the
@@ -1,7 +1,12 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import { describe, expect, it } from "vitest";
3
3
 
4
- import { NARROW_VIEWPORT, WIDE_VIEWPORT_QUERY } from "./breakpoints";
4
+ import {
5
+ MEDIUM_VIEWPORT,
6
+ NARROW_VIEWPORT,
7
+ ROOMY_VIEWPORT_QUERY,
8
+ WIDE_VIEWPORT_QUERY,
9
+ } from "./breakpoints";
5
10
  import { TERP_STYLES_CSS } from "./styles";
6
11
 
7
12
  // Vitest stubs .css imports to empty modules, so the sheet is read from disk.
@@ -189,11 +194,21 @@ describe("design tokens", () => {
189
194
  expect(WIDE_VIEWPORT_QUERY).toBe(`not all and ${NARROW_VIEWPORT}`);
190
195
  expect(sheet).toContain(`@media ${WIDE_VIEWPORT_QUERY}`);
191
196
 
197
+ // The second cutover, held the same way. It buys a third region without a third query
198
+ // (see breakpoints.ts): the regions are two cutovers in cascade order, so this pair has
199
+ // to satisfy exactly the invariants the pair above does, and the middle region is
200
+ // whatever the first correction leaves standing when this one does not apply.
201
+ const declaredLg = /--breakpoint-lg:\s*([^;]+);/.exec(tokensCss)?.[1]?.trim();
202
+ expect(declaredLg, "the contract should publish --breakpoint-lg").toBe("1024px");
203
+ expect(MEDIUM_VIEWPORT).toBe(`(max-width: ${declaredLg})`);
204
+ expect(ROOMY_VIEWPORT_QUERY).toBe(`not all and ${MEDIUM_VIEWPORT}`);
205
+ expect(sheet).toContain(`@media ${ROOMY_VIEWPORT_QUERY}`);
206
+
192
207
  // And nobody re-spells it. The two components import the constant now; a third copy is
193
208
  // exactly how the first two came to disagree with nothing noticing.
194
209
  const offenders = Object.entries(sources)
195
210
  .filter(([file]) => !file.includes(".test.") && file !== "./breakpoints.ts")
196
- .filter(([, text]) => text.includes("max-width: 768px"))
211
+ .filter(([, text]) => text.includes("max-width: 768px") || text.includes("max-width: 1024px"))
197
212
  .map(([file]) => file);
198
213
  expect(offenders, "the breakpoint belongs in ./breakpoints.ts and nowhere else").toEqual([]);
199
214
  });
@@ -51,13 +51,14 @@ describe("Text", () => {
51
51
  expect(el).toHaveAttribute("data-terp", "text");
52
52
  expect(el.hasAttribute("data-tone")).toBe(false);
53
53
  expect(el.hasAttribute("data-size")).toBe(false);
54
+ expect(el.hasAttribute("data-weight")).toBe(false);
54
55
  expect(el.hasAttribute("data-measure")).toBe(false);
55
56
  expect(el.getAttribute("style")).toBeNull();
56
57
  });
57
58
 
58
- it("names a tone, a step, a measure and its element", () => {
59
+ it("names a tone, a step, a weight, a measure and its element", () => {
59
60
  render(
60
- <Text data-testid="copy" as="span" tone="muted" size="sm" measure="narrow">
61
+ <Text data-testid="copy" as="span" tone="muted" size="sm" weight="semibold" measure="narrow">
61
62
  body
62
63
  </Text>,
63
64
  );
@@ -65,8 +66,39 @@ describe("Text", () => {
65
66
  expect(el.tagName).toBe("SPAN");
66
67
  expect(el).toHaveAttribute("data-tone", "muted");
67
68
  expect(el).toHaveAttribute("data-size", "sm");
69
+ expect(el).toHaveAttribute("data-weight", "semibold");
68
70
  expect(el).toHaveAttribute("data-measure", "narrow");
69
71
  });
72
+
73
+ it("carries emphasis on its own axis, so it composes with tone", () => {
74
+ // The pairing the missing axis used to force a size change for: a receding label
75
+ // above a value that carries the card. Both are body copy at the same step.
76
+ render(
77
+ <>
78
+ <Text data-testid="label" tone="muted" weight="medium">
79
+ Open incidents
80
+ </Text>
81
+ <Text data-testid="value" weight="semibold">
82
+ 14
83
+ </Text>
84
+ </>,
85
+ );
86
+ expect(screen.getByTestId("label")).toHaveAttribute("data-weight", "medium");
87
+ expect(screen.getByTestId("label")).toHaveAttribute("data-tone", "muted");
88
+ const value = screen.getByTestId("value");
89
+ expect(value).toHaveAttribute("data-weight", "semibold");
90
+ // Emphasis is not a size change, which is what a screen had to reach for before.
91
+ expect(value.hasAttribute("data-size")).toBe(false);
92
+ });
93
+
94
+ it("leaves an explicit normal weight unstamped, like every other default", () => {
95
+ render(
96
+ <Text data-testid="copy" weight="normal">
97
+ body
98
+ </Text>,
99
+ );
100
+ expect(screen.getByTestId("copy").hasAttribute("data-weight")).toBe(false);
101
+ });
70
102
  });
71
103
 
72
104
  describe("Code", () => {
@@ -81,19 +81,39 @@ export function Heading({ level, size, children, ...rest }: HeadingProps) {
81
81
  );
82
82
  }
83
83
 
84
- /** Ink weight for body copy. */
84
+ /** Ink tone for body copy. */
85
85
  export type TextTone = "default" | "muted" | "subtle";
86
86
 
87
87
  /** Type step for body copy. */
88
88
  export type TextSize = "xs" | "sm" | "base" | "lg";
89
89
 
90
+ /**
91
+ * Emphasis for body copy — the axis `tone` does not have.
92
+ *
93
+ * Every tone is a step *away* from the reader: `muted` and `subtle` recede, and the third
94
+ * option is not receding. That covers secondary copy and leaves nothing for the opposite
95
+ * case, which is just as common — the number a stat card is about, the answer in a
96
+ * definition row, the one word in a sentence that carries it. With no step for it the
97
+ * reach is for `size`, which says "this is bigger" when the thing meant was "this
98
+ * matters", and under the layout contract a screen cannot fall back on rendering its own
99
+ * heading either.
100
+ *
101
+ * Weight is kept separate from tone on purpose: tone is the ink, weight is the type, and
102
+ * they compose (a `medium` `muted` label above a `semibold` value is an ordinary pairing).
103
+ * `bold` is deliberately absent — the token exists, but body copy that needs 700 is a
104
+ * heading wearing a disguise.
105
+ */
106
+ export type TextWeight = "normal" | "medium" | "semibold";
107
+
90
108
  export interface TextProps extends Omit<HTMLAttributes<HTMLElement>, "style"> {
91
109
  /** The rendered element — `"p"` by default; `"span"` for text inside a line. */
92
110
  as?: "p" | "span" | "div";
93
- /** Ink weight (default `"default"`; `"muted"` for secondary copy, `"subtle"` for hints). */
111
+ /** Ink tone (default `"default"`; `"muted"` for secondary copy, `"subtle"` for hints). */
94
112
  tone?: TextTone;
95
113
  /** Type step (default `"base"`). */
96
114
  size?: TextSize;
115
+ /** Emphasis step (default `"normal"`). Composes with `tone`. */
116
+ weight?: TextWeight;
97
117
  /**
98
118
  * Cap the line length for readability (default off).
99
119
  *
@@ -115,6 +135,7 @@ export function Text({
115
135
  as: Component = "p",
116
136
  tone = "default",
117
137
  size = "base",
138
+ weight = "normal",
118
139
  measure,
119
140
  children,
120
141
  ...rest
@@ -123,10 +144,12 @@ export function Text({
123
144
  <Component
124
145
  {...rest}
125
146
  data-terp="text"
126
- // `default` and `base` are the base rule, so their attributes would describe the default
127
- // twice — the idiom density, Button's `md`, Grid's `auto` and Card's `boxed` all use.
147
+ // `default`, `base` and `normal` are the base rule, so their attributes would describe
148
+ // the default twice — the idiom density, Button's `md`, Grid's `auto` and Card's
149
+ // `boxed` all use.
128
150
  data-tone={tone === "default" ? undefined : tone}
129
151
  data-size={size === "base" ? undefined : size}
152
+ data-weight={weight === "normal" ? undefined : weight}
130
153
  data-measure={measure}
131
154
  >
132
155
  {children}