@terpjs/react-core 0.30.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.
- package/README.md +35 -14
- package/package.json +5 -5
- package/src/DashboardPage.tsx +34 -0
- package/src/Field.test.tsx +26 -1
- package/src/Field.tsx +15 -5
- package/src/HubPage.tsx +7 -2
- package/src/Page.test.tsx +192 -0
- package/src/Page.tsx +141 -55
- package/src/PageActions.test.tsx +64 -3
- package/src/PageActions.tsx +40 -15
- package/src/PageSequence.tsx +114 -0
- package/src/Stat.test.tsx +341 -0
- package/src/Stat.tsx +314 -0
- package/src/Timeline.test.tsx +74 -0
- package/src/Timeline.tsx +71 -0
- package/src/admin/AdminHub.tsx +11 -3
- package/src/admin/AuditLogAdmin.tsx +3 -1
- package/src/admin/GroupCreate.tsx +3 -1
- package/src/admin/GroupDetail.tsx +72 -67
- package/src/admin/GroupsAdmin.tsx +3 -1
- package/src/admin/ModuleAccessPanel.tsx +13 -12
- package/src/admin/RecordHistory.tsx +83 -0
- package/src/admin/UserCreate.tsx +3 -1
- package/src/admin/UserDetail.tsx +8 -1
- package/src/admin/UsersAdmin.tsx +3 -0
- package/src/admin/admin.test.tsx +208 -5
- package/src/bootstrap.test.tsx +31 -7
- package/src/bootstrap.tsx +30 -4
- package/src/charts/BarChart.tsx +74 -0
- package/src/charts/ProportionBar.tsx +118 -0
- package/src/charts/StatusHistory.tsx +75 -0
- package/src/charts/TrendChart.tsx +232 -0
- package/src/charts/charts.test.tsx +409 -0
- package/src/charts/scale.ts +103 -0
- package/src/dataview/DataView.test.tsx +255 -0
- package/src/dataview/DataView.tsx +35 -0
- package/src/dataview/DataViewCardList.tsx +21 -13
- package/src/dataview/DataViewTable.tsx +5 -6
- package/src/dataview/README.md +18 -0
- package/src/dataview/index.ts +1 -0
- package/src/dataview/internal.tsx +112 -5
- package/src/dataview/types.ts +39 -10
- package/src/errorMessages.test.tsx +17 -0
- package/src/errorMessages.tsx +18 -0
- package/src/format.ts +15 -0
- package/src/index.ts +24 -1
- package/src/layout.manifest.json +2 -9
- package/src/layout.manifest.test.ts +4 -2
- package/src/layout.test.tsx +74 -6
- package/src/layout.tsx +85 -25
- package/src/layoutContract.test.tsx +239 -1
- package/src/layoutContract.ts +131 -5
- package/src/layoutDeclaration.test.ts +31 -10
- package/src/layoutDeclaration.ts +9 -4
- package/src/locale.tsx +20 -3
- package/src/markers.test.ts +70 -2
- package/src/router.test.tsx +15 -3
- package/src/router.tsx +11 -2
- package/src/ssr.test.tsx +18 -0
- package/src/styles.test.ts +222 -190
- package/src/styles.ts +1268 -328
- package/src/theme.test.tsx +44 -18
- package/src/theme.themes.test.ts +22 -2
- package/src/theme.tsx +22 -14
- package/src/themes.ts +39 -4
- package/src/tokens.guard.test.ts +13 -15
- package/src/typography.tsx +5 -1
- package/src/ui/Alert.test.tsx +24 -1
- package/src/ui/Alert.tsx +10 -1
- package/src/ui/Card.tsx +5 -4
- package/src/ui/Tooltip.test.tsx +171 -2
- package/src/ui/Tooltip.tsx +144 -8
- package/src/ui/controlMessages.tsx +20 -7
- package/src/uiText.test.tsx +16 -0
- package/src/uiText.tsx +76 -7
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ also carries JSDoc, so your editor shows the same guidance inline. **Never deep-
|
|
|
55
55
|
| `LoginView` | The standard sign-in screen: username/password, plus optional SSO provider buttons via `ssoProviders` and a dev-only credential-fill button via `devCredentials` (gate it on `import.meta.env.DEV`). |
|
|
56
56
|
| `useSso`, `parseSsoCallback`, `fetchSsoAuthorizationUrl`, `completeSsoCallback` | The SSO login seam (ADR 0058): `useSso().begin(provider)` opens an OIDC flow; `TerpProvider` completes the `/auth/callback/{provider}` redirect landing into a normal session on boot. `renderTerpApp({ ssoProviders })` wires the buttons in one line. |
|
|
57
57
|
| `RequireAuth` | Renders children only with a session; pairs with the router so the app mounts only when signed in. |
|
|
58
|
-
| `ThemeProvider`, `ThemeToggle`, `useTheme` | Theming over the shipped palettes — `
|
|
58
|
+
| `ThemeProvider`, `ThemeToggle`, `useTheme` | Theming over the shipped palettes — `midday`, `twilight`, `evening`, `night`, `contrast` — plus `system` to follow the OS preference (its dark half is `night`). The earlier names `light`, `dark` and `midnight` are still accepted wherever a theme is named and resolve to midday, evening and night; the toggle writes the new names, so per-palette selectors in an app's own `theme.css` must use them. Applies `data-theme` on `<html>` (the token stylesheet carries every palette) and persists the choice. `defaultTheme` is how an app ships on a named theme — declare it in `layout-contract.json` so a tool can read and rewrite it, or pass the bootstrap option; both is refused. `renderTerpApp` mounts it for every app; the shell header uses an icon-only, token-themed `variant="inline"` menu. |
|
|
59
59
|
| `LocaleProvider`, `defineAppLocales`, `LanguageSwitcher`, `useLocale`, `LOCALE_EN`, `LOCALE_NL` | The language seam over `UiTextProvider`: `defineAppLocales(i18n, frameworkCatalogs)` validates and merges checked-in app messages with framework chrome, the active locale persists, and the shell offers a picker. Pass `sourceLocale` with `locales`; missing/empty target messages, undocumented source copies, invalid locale selection and a non-English locale without a complete framework-string catalog throw rather than silently falling back. A framework string that counts something (`dataViewResultsRange`, `dataViewSelectAllResults`, `accessUnexplainedRoutes`) is a `PluralText`: one form per plural category, chosen by the count under the active locale's `Intl.PluralRules`, and a catalog must supply exactly the categories its locale uses (`one` and `other` for Dutch; `one`, `few`, `many` and `other` for Polish). `<html lang>` follows the active locale from mount and across every switch. |
|
|
60
60
|
| `UserMenu`, `userInitials` | The signed-in user's menu, pinned by `buildAppRouter` to the bottom of the sidebar: an initials avatar trigger opening the identity block, **Settings** (the built-in profile page) and sign-out. Collapses to the avatar in the icon rail. |
|
|
61
61
|
| `ProfileView` | The built-in profile / settings page (`/profile`): the server-validated identity, theme + language preferences, and sign-out. |
|
|
@@ -72,7 +72,8 @@ also carries JSDoc, so your editor shows the same guidance inline. **Never deep-
|
|
|
72
72
|
## Page archetypes (the three-level screen pattern)
|
|
73
73
|
|
|
74
74
|
Every routed view **must** render one of the archetypes (`Page`, or `OverviewPage` /
|
|
75
|
-
`DetailPage` / `HubPage` / `FormPage` / `SettingsPage` / `SplitPage`, which
|
|
75
|
+
`DetailPage` / `HubPage` / `DashboardPage` / `FormPage` / `SettingsPage` / `SplitPage`, which
|
|
76
|
+
compose it) — `buildAppRouter` refuses an unframed view at
|
|
76
77
|
runtime, fail closed (ADR 0059), so every screen keeps the breadcrumb/title/error frame.
|
|
77
78
|
|
|
78
79
|
| Export | Use |
|
|
@@ -90,9 +91,10 @@ runtime, fail closed (ADR 0059), so every screen keeps the breadcrumb/title/erro
|
|
|
90
91
|
| `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`. |
|
|
91
92
|
| `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`. |
|
|
92
93
|
| `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`. |
|
|
93
|
-
| `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
|
|
94
|
+
| `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): the cluster sits beside the trail, a page with badges or a lead line spends a second row on them, and below the first cutover the cluster takes a row of its own; a page with none of that keeps the single row. A band of more than one row keeps the one-row band's inset once: each row is a control tall, with the inset above the first, between rows and below the last, so its lines sit as far from each other as from the border. 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. A page's own figures go in `summary`: a band directly under the title band, full-bleed inside a shell on the summary fill (`--color-bg-summary`, the brand's soft tint unless the theme says otherwise), holding a `StatGroup`, a headline `Stat`, a `StatusHistory`, a `Badge` or a line of `Text` — data, so it is not rendered while the page loads or fails (ADR 0169 §4). A page that is one item of an ordered series — a record among results, a column among a table's columns, a step among steps — takes `sequence`: the series' `label`, `previous` / `next` as `{ label, to }` and an optional `position`, rendered as a bar after the article (ADR 0168). The steps are router links with `rel` and a direction in their accessible name, an absent neighbour leaves its cell empty so the others never move, and inside a shell the bar sits at the bottom of the content column on a short page and pins to the bottom of the viewport on a long one, so "next" is in one place for the whole series. |
|
|
94
95
|
| `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`. |
|
|
95
96
|
| `OverviewPage` | A module's top-level listing screen (level 2); detail pages crumb back to it. |
|
|
97
|
+
| `DashboardPage` | "How is the whole doing" (ADR 0169 §4), where an overview answers "how is each one doing": the figures in its `summary` band, and a body of `Grid` sections — written with a template, which collapses on a phone — holding the figure and chart families side by side, the `DataView` they summarise, a `Timeline`, an `Alert` where something needs action. Under the `standard` contract the body admits `Grid`, `Stack`, `Card`, `DataView`, the figure family (`Stat`, `StatGroup`), the chart family (`TrendChart`, `BarChart`, `ProportionBar`, `StatusHistory`), `Timeline`, `Divider`, `Text`, `Alert`, `ConfirmDialog` and the framework states; the template is the guide's ask, not the contract's. |
|
|
96
98
|
| `DetailPage` | One record's screen (level 3); breadcrumb trail = ancestors + record title. |
|
|
97
99
|
| `FormPage` | A create-or-edit screen. `measure="narrow"` by default, so the whole frame — header, actions and all — caps at 32rem over a single column of controls. Its body slot takes the form container (`Stack as="form"`), plus `Grid` / `Card` / `Divider` / `Text`; a bare `Field` at the top level is refused, because a run of fields has no `<form>` and cannot be submitted. |
|
|
98
100
|
| `SettingsPage` | Preferences and account screens: `Card` sections, also `measure="narrow"`. No `DataView`, `DetailList` or `Tabs` — a settings screen whose body is a collection is an overview with the wrong chrome. `parents` is optional, unlike `FormPage`'s. |
|
|
@@ -104,7 +106,7 @@ runtime, fail closed (ADR 0059), so every screen keeps the breadcrumb/title/erro
|
|
|
104
106
|
| `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`. |
|
|
105
107
|
| `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"]`. |
|
|
106
108
|
| `ModuleNav` | Secondary horizontal tabs for intra-module sub-pages (real routes, not state). |
|
|
107
|
-
| `PageActions` | The page header's action cluster: `primary`, `secondary` nodes, `secondaryActions` descriptors and an `overflow` menu. The cluster follows the viewport — supporting
|
|
109
|
+
| `PageActions` | The page header's action cluster: `primary`, `secondary` nodes, `secondaryActions` descriptors and an `overflow` menu. The cluster follows the viewport AND the count — below the widest region a supporting action with an icon drops its label for it only when the slot holds more than one action, and on a phone the supporting actions fold into the overflow menu only when the slot holds more than two — while the primary action keeps its label at every width. It is the way a page's actions should be written: it wraps rather than running off the screen, and it collapses as room runs out, which a row of plain buttons cannot. Only `secondaryActions` can follow the viewport: a `secondary` node's label is inside the caller's tree and can only be shown or hidden. |
|
|
108
110
|
|
|
109
111
|
### Typed route paths and params (generated, ADR 0092)
|
|
110
112
|
|
|
@@ -163,8 +165,12 @@ the framework states (`EmptyState` / `ErrorState` / `LoadingState` / `Alert`) an
|
|
|
163
165
|
deliberate and pinned by tests rather than left to the table: `Grid` joins **detail**
|
|
164
166
|
bodies only (an overview body is a collection, and a grid of summary cards is a hub,
|
|
165
167
|
which has its own archetype), while `Heading` joins **neither** — a heading in a governed
|
|
166
|
-
body must own its section, and `Card` is how a section is owned. The plain `Page` stays
|
|
167
|
-
unconstrained (the sanctioned home for a bespoke screen).
|
|
168
|
+
body must own its section, and `Card` is how a section is owned. The plain `Page`'s body stays
|
|
169
|
+
unconstrained (the sanctioned home for a bespoke screen). Two rules belong to the frame rather
|
|
170
|
+
than to a body, so they hold on every page, the plain one included (ADR 0169 §4): a `summary`
|
|
171
|
+
band holds only `Stat` / `StatGroup` / `StatusHistory` / `Badge` / `Text`, and at most one figure on a page is its
|
|
172
|
+
`headline` — the lint counts the static JSX of a page element, taking the larger branch of a
|
|
173
|
+
conditional, and the runtime counts the rendered page. Only the slot's **direct** children are governed — an allowed
|
|
168
174
|
container's own subtree (a `Card` body, a `Stack` of rows) is the app's to compose.
|
|
169
175
|
Enforcement is two-layer and fail-closed: the lint rule checks static JSX
|
|
170
176
|
children; the archetypes verify the rendered DOM (sanctioned components stamp a
|
|
@@ -181,7 +187,7 @@ marker, counted by the escape-hatch budget.
|
|
|
181
187
|
|
|
182
188
|
| Export | Use |
|
|
183
189
|
|---|---|
|
|
184
|
-
| `DataView` + family | **The single sanctioned surface for data collections**: repository-driven table/card view with search, sorting, pagination, column management, selection + batch actions, row actions, expandable rows, persisted view preferences, and pointer/keyboard row activation for overview-to-detail navigation. See [`src/dataview/README.md`](src/dataview/README.md) for the full guide (client-side and server-side recipes). |
|
|
190
|
+
| `DataView` + family | **The single sanctioned surface for data collections**: repository-driven table/card view with search, sorting, pagination, column management, selection + batch actions, row actions, expandable rows, persisted view preferences, and pointer/keyboard row activation for overview-to-detail navigation. A collection that is one section of a page takes `title`, its heading with its count beside it once read; a column takes `status` for a dot before its word, `bar` for its numbers drawn as bars against the largest shown, or `history` for each row's recent runs as a `StatusHistory` (ADR 0169 §5, §6). See [`src/dataview/README.md`](src/dataview/README.md) for the full guide (client-side and server-side recipes). |
|
|
185
191
|
| `InMemoryDataViewRepository`, `HttpDataViewRepository` | Data repositories (client-side / server-side); `useServerDataView` keeps server query state in the URL. |
|
|
186
192
|
| `InMemoryViewStateRepository`, `LocalStorageViewStateRepository` | Preference persistence seam. |
|
|
187
193
|
| `useResource` | An async collection: rows + loading/error + reload + create-then-reload. |
|
|
@@ -222,12 +228,19 @@ marker, counted by the escape-hatch budget.
|
|
|
222
228
|
| `Avatar` | The initials tile: `from` (an email or a name) or explicit `initials`, and a closed `size` of `sm` (2rem, an account menu) or `md` (3.5rem, a profile header). `aria-hidden`, because the name it abbreviates is always rendered beside it. No `src`: `/me` carries no avatar URL, so an image slot would be a prop with nothing behind it. |
|
|
223
229
|
| `Badge` | Small status pill: `<Badge tone="success">Synced</Badge>` (or `label="Synced"`); `tone`: neutral / info / success / warning / danger. |
|
|
224
230
|
| `Meter` | One bounded value — a quota used, a score against its range — as a bar with the value printed beside it (ADR 0158). The bar **is** the native `<meter>` (`value`, `min` default 0, `max` default 1, and the optional `low` / `high` / `optimum` bands), styled from the sheet, so the browser draws the proportion and nothing renders an inline width. `label` is required and is the meter's **accessible name, not printed**: every place a quantity sits already has a visible caption — a `DetailList` term, a `Card` title, a `HubCard` title — so a meter goes inside one, and the standard layout contract refuses one loose in a body. `format` takes the `Intl.NumberFormatOptions` the `format` helpers take and defaults to a percentage, which is always the **share of the range** (`value={74} max={100}` prints `74%`, not Intl's `7,400%`); any other style prints the value itself, unclamped, so an overrun reads `120%` against a full bar. The printed copy is `aria-hidden` and handed to the element as `aria-valuetext`, so a screen reader hears it once — and so does a `HubCard` link whose stat is a meter. Bands are opt-in: with none the bar is one accent colour, and with any the fill takes success / warning / danger by region — reinforcing the printed value, never replacing words where the judgement matters. |
|
|
225
|
-
| `
|
|
231
|
+
| `Stat` | One figure, with what it needs to be read (ADR 0169): `label`, a `value` printed in the app's locale through the `format` helpers (a string prints as written; `null` prints the dash), and optionally a `delta` — `{ value, sentiment, format?, label? }`, a pill carrying its sign whose tone is the **declared** sentiment (`"positive"` / `"negative"` / `"neutral"`, the caller's fact: more rejections is up and bad) and whose sentiment is also read out as a word — a `trend` of labelled points drawn as a sparkline (SVG geometry, coloured from the sheet) and read out as text, its data alternative, a `target` drawn as a `Meter` against its range and bands, and a `caption`. On its own it is a tile on the surface rung, where data is read; in a `StatGroup` or a `HubCard`'s `stat` row the container is its frame. `headline` fills it with the brand colour: at most one per page, which both halves of the layout contract hold. Phrasing content throughout, so it is valid inside a `HubCard`'s link. |
|
|
232
|
+
| `StatGroup` | Several figures about one subject as one ruled row — unframed wherever it is placed, so four figures read as one statement rather than four tiles. Wraps by itself, two to a line on a phone, and a figure that starts a line carries no rule. The usual content of a page's `summary` band. |
|
|
233
|
+
| `TrendChart` | Values over time (ADR 0158, ADR 0169 §6): `mark` `"line"` (the default), `"area"` or `"columns"`, an optional `comparison` series drawn dashed behind it and named in a legend, on a value axis of three round ticks. A line's axis starts where its data does; an area's and columns' keep zero, because their length is the value. Under ADR 0158's contract: SVG geometry with colour from the sheet (no inline style), numbers through the `format` helpers, no dependency, and the data as a visually hidden table that assistive technology reads in place of the hidden picture. A tile on the surface. |
|
|
234
|
+
| `BarChart` | Categories compared by length, in the order given — rank them first. The chart is its own table: each category a row header, its value printed, its bar a cell drawn for the eye. `max` overrides the largest value as the scale. |
|
|
235
|
+
| `ProportionBar` | A whole split into its parts along one bar, parted by hairlines, with a legend that says every part — its name, its count and its share. Parts that are states take their `tone`; the rest take the chart colours in order. |
|
|
236
|
+
| `Timeline` | Events in order on a line that joins them (ADR 0169 §5): each a `label` in words, a `when` printed in the app's locale inside a `<time>` carrying its instant, an optional `detail`, and a `tone` for its marker where the event changed a state — the label is always the word. An ordered list named by `label`. The packaged user and group screens show a record's own history with it, read from the audit trail narrowed to that record. |
|
|
237
|
+
| `StatusHistory` | How the recent runs of something ended, one cell per run, oldest first: each run a `{ label, outcome }`, an outcome a `{ label, tone }` declared once and reused. The latest ending is printed and every run is read out. Phrasing content, so it sits in a page's `summary` band, a collection's cell (`history` on a `DataView` column) or a hub card's link. |
|
|
238
|
+
| `Tooltip` | Accessible focus/hover tooltip that describes its trigger with `aria-describedby`. The bubble is portalled to the body — or into the dialog its trigger sits in, since nothing outside a modal dialog paints above it — and placed from measurements — above the trigger, or below when there is no room — and kept inside the window, so a scroll container (a DataView cell) cannot clip it and a trigger at the window's edge cannot push it off screen. |
|
|
226
239
|
| `Popover`, `Menu`, `MenuItem` | Shared anchored overlay and dropdown-menu primitives: body-portaled, viewport-aware panels that escape scroll/table clipping, with outside-click/Escape close, focus return, selected-item semantics, and roving keyboard navigation. |
|
|
227
|
-
| `Alert` | Inline banner for persistent feedback (`tone`: neutral / info / success / warning / danger); warnings and danger announce as `alert`, others as `status`. |
|
|
240
|
+
| `Alert` | Inline banner for persistent feedback (`tone`: neutral / info / success / warning / danger); warnings and danger announce as `alert`, others as `status`. `actions` puts what the reader can do about it — one or two `Button`s — inside the alert, under its message, rather than in a row the caller builds beside it (ADR 0169 §5). |
|
|
228
241
|
| `Markdown` | Safe, dependency-free markdown renderer for headings, paragraphs, bold, italic, inline code, code blocks, lists, and safe links; raw HTML is rendered as text and never passed through. |
|
|
229
|
-
| `Field` | Label + control + hint/error wrapper for one form field. The error is announced (`role="alert"`) as well as described, because `aria-describedby` alone is silent for a rejection that arrives after focus has left the control. |
|
|
230
|
-
| `FieldRow` | Several `Field`s side by side, with their labels
|
|
242
|
+
| `Field` | Label + control + hint/error wrapper for one form field. Fields side by side in a `Grid` (or a `FieldRow`) share a label line and a control line, so a label that wraps or a hint under one control moves no other field's control. The error is announced (`role="alert"`) as well as described, because `aria-describedby` alone is silent for a rejection that arrives after focus has left the control. |
|
|
243
|
+
| `FieldRow` | Several `Field`s side by side, with their labels on one **shared line** and their bodies — each control with whatever its field says under it — on the next. (A `Grid` whose children are all fields now does this by itself; `FieldRow` is for a row that also holds an action.) A field is as tall as its label, its control *and* whatever it has to say, so neither flex alignment is right: `align="end"` lines up the messages, so a field that grows a hint lifts its own control above its neighbours' and a bare action button sinks to the depth of the longest error on the row; `align="start"` lines up the labels, which fixes the fields and leaves the button riding above the controls. A flex row can align one **edge** of a box and the thing that has to line up here is a band in the middle of it, so the row owns two rows and each field becomes a `subgrid` of them — the instrument `DetailListGroup` already uses, for the same reason. Anything that is not a field lands on the control line, which is a placement rather than a wrapper, so a remove button keeps its own element and its own name. `gap` moves the **column** gap only: the row gap is each field's internal label-to-control measure, shared by every field on the row. Below the viewport cutover it is one column at full width — three controls and an action do not fit a phone, and that is also where the alignment problem stops existing. |
|
|
231
244
|
| `QuietActions` | A value with an action attached, where the action is **quiet until someone reaches for it** — a copyable identifier, a row's remove, a list item's open. Five copyable digests on one card meant five copy buttons competing with the five values they applied to. The space is **reserved, not collapsed**: the action fades rather than appears, so nothing moves when a pointer arrives. Three things make it safe rather than merely quiet — the resting state sits behind `@media (hover: hover)`, so a touch screen with no hover to reveal anything gets a visible control instead of an invisible tappable one; it reveals on `:focus-within` as well as hover, because opacity does not remove an element from the tab order and a keyboard must never land on something it cannot see; and opacity is not `visibility`, so the action is announced, named and operable throughout. The actions are a slot, the same one `Card` publishes, rather than a convention about which children count. |
|
|
232
245
|
|
|
233
246
|
## Layout
|
|
@@ -239,16 +252,24 @@ token spacing scale, so spacing is themed centrally):
|
|
|
239
252
|
| Export | Use |
|
|
240
253
|
|---|---|
|
|
241
254
|
| `Stack` | The layout primitive: a flex container with a token gap. Vertical by default (forms, sections); `direction="row"` + `justify` for toolbars; `as="form"` etc. for semantics. `padding` insets on the same token scale; `direction` and `gap` also take a `{ narrow, wide }` pair, which changes over at the one viewport cutover the shell and the DataView already use. |
|
|
242
|
-
| `Grid` | The two-dimensional primitive, and the one that lifts a real ceiling — a two-column form could not be expressed at all before it. `columns` takes a fixed 1–4 or `"auto"` (the default), which reflows to whatever the **container** can hold with no breakpoint anywhere; `minColumn` is the track floor for `auto`; `gap` indexes the spacing scale; `align` is a closed four. Renders no inline style. No `span`, and therefore no twelve-column option — a
|
|
243
|
-
| `Card` | A token-styled frame (a border, a radius and
|
|
255
|
+
| `Grid` | The two-dimensional primitive, and the one that lifts a real ceiling — a two-column form could not be expressed at all before it. `columns` takes a fixed 1–4 or `"auto"` (the default), which reflows to whatever the **container** can hold with no breakpoint anywhere; `minColumn` is the track floor for `auto`; `gap` indexes the spacing scale; `align` is a closed four. `template` lays out a page section instead (ADR 0169 §2): `"2:1"`, `"1:2"` and `"3:1"` for a main track beside a narrower one, `"1:1"`, `"1:1:1"` and `"1:1:1:1"` for equal ones — and every template gives up its tracks at the one cutover (to one, and the four-track set to two), which a fixed count does not, so a template is how a section is laid out and `columns={4}` is not. The types refuse a template beside a count. Renders no inline style. No `span`, and therefore no twelve-column option — asymmetry is a template on the parent, so a row cannot go ragged whatever renders in it. |
|
|
256
|
+
| `Card` | A token-styled frame (a border, a radius, padding and the container fill, `--color-bg-subtle` — the rung between the page and the data read on it, ADR 0169 §3) grouping one block of a page — the sanctioned visual separation between sections. Optional header, shaped like the page band: `title` (semantic `<h3>`) with the `actions` slot beside it when they fit (they wrap under it, and wrap their own buttons, when they do not), then the muted `description` on a line of its own at full width — so a sentence of description no longer wraps in a narrow column beside a button. `variant="plain"` keeps the heading and drops the box, for a titled region inside something that is already a surface — a section whose body is a `DataView` gets a border inside a border otherwise. There is no separate `Section` or `Surface`: both are this element with declarations removed. |
|
|
244
257
|
| `Divider` | A rule between groups, as a semantic `<hr>` so the separation reaches the accessibility tree — `Separator` under its other name, shipped once. `orientation="vertical"` takes its height from its flex or grid line rather than inventing one, so it works between the items of a row `Stack` and is zero-height in a block parent. |
|
|
245
|
-
| `DetailList` | Token-styled label/value pairs as a semantic `<dl>` (record metadata, expanded-row summaries). A real grid
|
|
258
|
+
| `DetailList` | Token-styled label/value pairs as a semantic `<dl>` (record metadata, expanded-row summaries). A real grid. The default `layout="stacked"` puts each label above its value — the one layout with no label-to-value spacing to get wrong; `"aligned"` puts every label in a shared column so the values line up, `"inline"` runs `Label: value` on one line, `"grid"` is the ruled grid — each pair a cell, as many to a row as fit at 11rem, divided by hairline rules, for a record whose facts are many and short (ADR 0169 §5) — and `columns` takes two pairs per row. Tracks are floored at zero and long values wrap, so a 64-character digest no longer pushes the list past its container. Both non-inline layouts mute their label to the small, regular step — at the value's own size and weight a card of labelled values is a wall of bold text — and space their rows so a pair groups; `gap` moves that distance on the spacing scale, and it is the **row** gap, since the column gap is the label-to-value distance. One pair can leave the shared column with `full`, which spans it across every track with its label above its value — the escape that stops a single wide value (a paragraph, a payload) from forcing the list to split in two, since two lists measure two label columns. `columns` also takes `"auto"`, which follows the **container** rather than the viewport: a pair is at least 9rem of label and 13rem of value, each floor capped at a share of the track so one pair always fits a narrow panel instead of overflowing it. The closed one-or-two keep the reflow at the framework's viewport cutover, where `Grid` deliberately does not for a fixed count. |
|
|
246
259
|
| `DetailListGroup` | Several `DetailList`s that share **one** measured label column. A card that shows a record in sections renders a list per section — the sections have their own headings and their own order, and one `<dl>` cannot carry that — and each list then measures its own label column, so the values in each land on a different vertical line: four lists, four gutters, on one card. The group owns the track list and each aligned list inside becomes a `subgrid` of it, so every label in every list is measured against the same track. Explicit rather than something `Card` infers from its children: a card that wants two different label widths has to be able to say so, and a card has no business knowing about `<dl>` tracks. Children other than lists span the whole group (a `Heading` between two sections, a `Divider`), which is the other half of why it is a wrapper. It shares the measure for `layout="aligned"` at the default single column — a `columns={2}` list keeps its own four tracks rather than being quietly folded into two — above the viewport cutover, and it degrades to exactly today's output where `subgrid` is unsupported. |
|
|
247
260
|
| `Heading` | A section heading inside a page body — `h2`–`h4`, with `size` a **separate** choice from `level` so a visually small `h2` is expressible without picking the wrong element. No level 1: `Page` renders the single `h1` of every routed view. |
|
|
248
261
|
| `Text` | Body copy with themeable ink — `tone` (default / muted / subtle), `size`, and an enumerable `measure` that caps the line length in `ch`. What a bare `<p>` in a module cannot be, since a bare element carries no marker for a rule to reach. |
|
|
249
262
|
| `Code` | An identifier or a snippet in the mono family. `block` wraps it in a focusable `<pre>`, which is what preserves the whitespace and what makes a long line scrollable by keyboard. |
|
|
250
263
|
| `Link` | A link with themeable ink, routing in-app paths through the surrounding router and degrading to a plain anchor outside one. An external `newTab` gets `rel="noreferrer"`. The boundary lint refuses a raw in-app `<a href="/…">`; this is the thing to use instead. |
|
|
251
264
|
|
|
265
|
+
**Framed and unframed, alternated** (ADR 0169 §3). The frame belongs to the data a reader works
|
|
266
|
+
with: a `DataView`, a chart and a lone `Stat` sit on the surface, the collection brightest. A
|
|
267
|
+
boxed `Card` steps back onto the container fill, for a group of controls or one section of a
|
|
268
|
+
record. Much of a page needs no frame at all — a `StatGroup`, a `DetailList`, a `Timeline`, a
|
|
269
|
+
line of `Text`, a titled region as `Card variant="plain"`. A page that boxes every block in a
|
|
270
|
+
`Card` reads as one object repeated; which block a shape of data takes is in
|
|
271
|
+
`terp guide layouts`.
|
|
272
|
+
|
|
252
273
|
## The packaged admin area
|
|
253
274
|
|
|
254
275
|
Every Terp backend mounts the base-profile admin capabilities (users, groups +
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terpjs/react-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.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": {
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"test": "vitest run"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@tanstack/react-router": "^1.170.
|
|
18
|
-
"@terpjs/contract": "^0.
|
|
17
|
+
"@tanstack/react-router": "^1.170.40",
|
|
18
|
+
"@terpjs/contract": "^0.31.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"react": "^19.0.0",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"react": "^19.3.0",
|
|
32
32
|
"react-dom": "^19.3.0",
|
|
33
33
|
"typescript": "^5.9.3",
|
|
34
|
-
"vite": "^8.3.
|
|
35
|
-
"vitest": "^5.0.
|
|
34
|
+
"vite": "^8.3.1",
|
|
35
|
+
"vitest": "^5.0.2"
|
|
36
36
|
},
|
|
37
37
|
"license": "Apache-2.0",
|
|
38
38
|
"repository": {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
import type { BreadcrumbItem } from "./Breadcrumbs";
|
|
4
|
+
import { Page } from "./Page";
|
|
5
|
+
import type { PageProps } from "./Page";
|
|
6
|
+
import { LayoutSlotContext } from "./layoutContract";
|
|
7
|
+
|
|
8
|
+
export interface DashboardPageProps extends Omit<PageProps, "breadcrumbs"> {
|
|
9
|
+
/** Optional parent layers for a dashboard nested below a hub or an area. */
|
|
10
|
+
parents?: readonly (BreadcrumbItem & { to: string })[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The dashboard archetype (ADR 0169 §4): a page that answers "how is the whole doing", where an
|
|
15
|
+
* overview answers "how is each one doing".
|
|
16
|
+
*
|
|
17
|
+
* Its figures go in the `summary` band under the title; its body is composed from the shape of
|
|
18
|
+
* its data — templated `Grid` sections holding charts and figures side by side, the collection
|
|
19
|
+
* the figures summarise, an `Alert` where something needs action. With a layout contract active
|
|
20
|
+
* (ADR 0079) the body accepts exactly those: `Grid`, `Stack`, `Card`, `DataView`, the figure
|
|
21
|
+
* family (`Stat`, `StatGroup`), the chart family (`TrendChart`, `BarChart`, `ProportionBar`,
|
|
22
|
+
* `StatusHistory`), `Timeline`, `Divider`, `Text`, `Alert`, `ConfirmDialog` and the framework
|
|
23
|
+
* states — refused fail closed otherwise. A section is written with a `Grid` template, which
|
|
24
|
+
* collapses on a phone; the contract admits any `Grid`, and the guide is what asks for the
|
|
25
|
+
* template. ADR 0098 named the condition for this archetype as "a `Grid` decision", and the
|
|
26
|
+
* track templates were that decision.
|
|
27
|
+
*/
|
|
28
|
+
export function DashboardPage({ parents, ...page }: DashboardPageProps): ReactNode {
|
|
29
|
+
return (
|
|
30
|
+
<LayoutSlotContext.Provider value="DashboardPage">
|
|
31
|
+
<Page breadcrumbs={parents} {...page} />
|
|
32
|
+
</LayoutSlotContext.Provider>
|
|
33
|
+
);
|
|
34
|
+
}
|
package/src/Field.test.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
|
-
import { cleanup, render, screen } from "@testing-library/react";
|
|
2
|
+
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
|
3
3
|
import { afterEach, describe, expect, it } from "vitest";
|
|
4
4
|
|
|
5
5
|
import { Field, FieldRow } from "./Field";
|
|
@@ -252,3 +252,28 @@ describe("Select / Textarea primitives", () => {
|
|
|
252
252
|
expect(TERP_STYLES_CSS).toContain('[data-terp="field-row"][data-gap="4"]');
|
|
253
253
|
});
|
|
254
254
|
});
|
|
255
|
+
|
|
256
|
+
describe("Field — what it says is not part of its control", () => {
|
|
257
|
+
it("does not hand a click on its hint or its error to the control", () => {
|
|
258
|
+
// The messages sit inside the <label> so fields side by side share two lines, and a click
|
|
259
|
+
// anywhere in a label is forwarded to its control: clicking an error opened a Select and
|
|
260
|
+
// toggled a checkbox. The label text still forwards -- the fix is the messages, not the
|
|
261
|
+
// label.
|
|
262
|
+
// Asserted after EACH click: two forwarded clicks toggle a checkbox twice and leave it as it
|
|
263
|
+
// was, so one assertion after both could not see either of them (a first version did that,
|
|
264
|
+
// and the mutation below stayed green against it).
|
|
265
|
+
// Mutation: drop the envelope's click handler, and the box is checked after the hint click.
|
|
266
|
+
render(
|
|
267
|
+
<Field label="Accept the terms" hint="You can withdraw later." error="Required.">
|
|
268
|
+
<input type="checkbox" />
|
|
269
|
+
</Field>,
|
|
270
|
+
);
|
|
271
|
+
const box = screen.getByRole("checkbox");
|
|
272
|
+
fireEvent.click(screen.getByText("You can withdraw later."));
|
|
273
|
+
expect(box).not.toBeChecked();
|
|
274
|
+
fireEvent.click(screen.getByText("Required."));
|
|
275
|
+
expect(box).not.toBeChecked();
|
|
276
|
+
fireEvent.click(screen.getByText("Accept the terms"));
|
|
277
|
+
expect(box).toBeChecked();
|
|
278
|
+
});
|
|
279
|
+
});
|
package/src/Field.tsx
CHANGED
|
@@ -85,9 +85,17 @@ export function Field({ label, children, error, hint }: FieldProps) {
|
|
|
85
85
|
<span id={labelId} data-terp="field-label-text">
|
|
86
86
|
{resolve(label)}
|
|
87
87
|
</span>
|
|
88
|
-
{control
|
|
88
|
+
{/* The control and what the field says about it, as ONE box under the label. That is
|
|
89
|
+
what lets fields side by side share two lines -- every label on one, every control
|
|
90
|
+
on the next -- however long any label runs or whatever any field has to say: a
|
|
91
|
+
hint or an error grows its own body downward and moves no other field's control.
|
|
92
|
+
Inside the <label> with the control, which changes no name: the control is named
|
|
93
|
+
by aria-labelledby on the label TEXT above, not by the label's whole subtree. */}
|
|
94
|
+
<span data-terp="field-body">
|
|
95
|
+
{control}
|
|
96
|
+
{messages}
|
|
97
|
+
</span>
|
|
89
98
|
</label>
|
|
90
|
-
{messages}
|
|
91
99
|
</div>
|
|
92
100
|
);
|
|
93
101
|
}
|
|
@@ -106,8 +114,10 @@ export interface FieldRowProps extends Omit<HTMLAttributes<HTMLDivElement>, "sty
|
|
|
106
114
|
}
|
|
107
115
|
|
|
108
116
|
/**
|
|
109
|
-
* Several {@link Field}s side by side, with their labels
|
|
110
|
-
*
|
|
117
|
+
* Several {@link Field}s side by side, with their labels on one shared line and their
|
|
118
|
+
* bodies -- each control with whatever its field says under it -- on the next. A `Grid`
|
|
119
|
+
* whose children are all fields does the same by itself; this is for a row that also holds
|
|
120
|
+
* an action beside the fields.
|
|
111
121
|
*
|
|
112
122
|
* It exists because a row of fields had no correct alignment, and both wrong ones were
|
|
113
123
|
* reachable by an ordinary `Stack`. A field is as tall as its label, its control AND
|
|
@@ -122,7 +132,7 @@ export interface FieldRowProps extends Omit<HTMLAttributes<HTMLDivElement>, "sty
|
|
|
122
132
|
*
|
|
123
133
|
* Neither is a bug in `Stack`. A flex row can align one edge of a box, and the thing that
|
|
124
134
|
* has to line up here is a band in the MIDDLE of it, which needs the boxes to share tracks
|
|
125
|
-
* rather than edges. So the row owns
|
|
135
|
+
* rather than edges. So the row owns two rows and each field becomes a subgrid of them --
|
|
126
136
|
* the same instrument {@link DetailListGroup} uses to share one label column across several
|
|
127
137
|
* lists, for the same reason: the alternative is each box measuring itself.
|
|
128
138
|
*
|
package/src/HubPage.tsx
CHANGED
|
@@ -74,8 +74,13 @@ export interface HubCardProps {
|
|
|
74
74
|
/** Optional leading icon (any rendered node — react-core takes no icon dependency). */
|
|
75
75
|
icon?: ReactNode;
|
|
76
76
|
/**
|
|
77
|
-
* Optional live summary
|
|
78
|
-
*
|
|
77
|
+
* Optional live summary, which turns the hub into a lightweight dashboard rather than a
|
|
78
|
+
* duplicate of the sidebar.
|
|
79
|
+
*
|
|
80
|
+
* A figure is a `Stat` — `stat={<Stat label={open} value={142} />}` — so a number reads on a
|
|
81
|
+
* hub card as it does on every other page, in the app's locale and with its delta and its
|
|
82
|
+
* sparkline (ADR 0169 §5). The card is its frame, so it has none of its own here. A short
|
|
83
|
+
* line of text that is not a figure ("Needs review") is passed as it is.
|
|
79
84
|
*/
|
|
80
85
|
stat?: ReactNode;
|
|
81
86
|
/** Link renderer (default: a plain `<a href>`); pass the stack's `Link`, like `AppShell`. */
|
package/src/Page.test.tsx
CHANGED
|
@@ -3,8 +3,11 @@ import { cleanup, render, screen } from "@testing-library/react";
|
|
|
3
3
|
import { afterEach, describe, expect, it } from "vitest";
|
|
4
4
|
|
|
5
5
|
import { DetailPage } from "./DetailPage";
|
|
6
|
+
import { NavLinkContext } from "./navLink";
|
|
6
7
|
import { OverviewPage } from "./OverviewPage";
|
|
7
8
|
import { Page } from "./Page";
|
|
9
|
+
import { Stat, StatGroup } from "./Stat";
|
|
10
|
+
import { UiTextProvider } from "./uiText";
|
|
8
11
|
import { ApiError } from "./unwrap";
|
|
9
12
|
import { Badge } from "./ui/Badge";
|
|
10
13
|
import { Button } from "./ui/Button";
|
|
@@ -259,6 +262,139 @@ describe("Page", () => {
|
|
|
259
262
|
});
|
|
260
263
|
});
|
|
261
264
|
|
|
265
|
+
describe("Page sequence", () => {
|
|
266
|
+
const MIDDLE = {
|
|
267
|
+
label: "Orders",
|
|
268
|
+
previous: { label: "Order 1016", to: "/orders/1016" },
|
|
269
|
+
next: { label: "Order 1018", to: "/orders/1018" },
|
|
270
|
+
position: { current: 17, total: 48 },
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
it("renders no bar when the page is not part of a sequence", () => {
|
|
274
|
+
const { container } = render(<Page title="Tasks">body</Page>);
|
|
275
|
+
expect(container.querySelector('[data-terp="page-sequence"]')).toBeNull();
|
|
276
|
+
expect(screen.getAllByRole("navigation")).toHaveLength(1);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("names the series and says which way each link goes", () => {
|
|
280
|
+
render(
|
|
281
|
+
<Page title="Order 1017" sequence={MIDDLE}>
|
|
282
|
+
body
|
|
283
|
+
</Page>,
|
|
284
|
+
);
|
|
285
|
+
// Its own landmark, named for the series, beside the page's breadcrumb landmark — two
|
|
286
|
+
// navigations a screen reader can tell apart by name.
|
|
287
|
+
expect(screen.getByRole("navigation", { name: "Orders" })).toHaveAttribute(
|
|
288
|
+
"data-terp",
|
|
289
|
+
"page-sequence",
|
|
290
|
+
);
|
|
291
|
+
// The visible label is the neighbour's name; the accessible name says the direction and
|
|
292
|
+
// still contains that name, so a voice user can say what they see.
|
|
293
|
+
const previous = screen.getByRole("link", { name: "Previous: Order 1016" });
|
|
294
|
+
expect(previous).toHaveAttribute("href", "/orders/1016");
|
|
295
|
+
expect(previous).toHaveAttribute("rel", "prev");
|
|
296
|
+
expect(previous).toHaveTextContent("Order 1016");
|
|
297
|
+
const next = screen.getByRole("link", { name: "Next: Order 1018" });
|
|
298
|
+
expect(next).toHaveAttribute("href", "/orders/1018");
|
|
299
|
+
expect(next).toHaveAttribute("rel", "next");
|
|
300
|
+
expect(screen.getByText("17 of 48")).toHaveAttribute("data-terp", "page-sequence-position");
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it("renders the bar after the article, never inside it", () => {
|
|
304
|
+
// Inside, the layout contract's slot check would read it as a body child (see the
|
|
305
|
+
// governed-page case in layoutContract.test.tsx).
|
|
306
|
+
const { container } = render(
|
|
307
|
+
<Page title="Order 1017" sequence={MIDDLE}>
|
|
308
|
+
body
|
|
309
|
+
</Page>,
|
|
310
|
+
);
|
|
311
|
+
const bar = container.querySelector('[data-terp="page-sequence"]')!;
|
|
312
|
+
expect(bar.closest('[data-terp="page"]')).toBeNull();
|
|
313
|
+
expect(bar.previousElementSibling).toHaveAttribute("data-terp", "page");
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it("keeps an absent neighbour's cell, so the others never move", () => {
|
|
317
|
+
const { container } = render(
|
|
318
|
+
<Page title="Order 1001" sequence={{ label: "Orders", next: MIDDLE.next }}>
|
|
319
|
+
body
|
|
320
|
+
</Page>,
|
|
321
|
+
);
|
|
322
|
+
const bar = container.querySelector('[data-terp="page-sequence"]')!;
|
|
323
|
+
expect([...bar.children].map((cell) => cell.getAttribute("data-terp"))).toEqual([
|
|
324
|
+
"page-sequence-previous",
|
|
325
|
+
"page-sequence-position",
|
|
326
|
+
"page-sequence-next",
|
|
327
|
+
]);
|
|
328
|
+
expect(bar.querySelector('[data-terp="page-sequence-previous"]')).toBeEmptyDOMElement();
|
|
329
|
+
// No position given is no position shown — an unknown total is never guessed at.
|
|
330
|
+
expect(bar.querySelector('[data-terp="page-sequence-position"]')).toBeEmptyDOMElement();
|
|
331
|
+
expect(screen.getAllByRole("link")).toHaveLength(1);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it("steps through the ambient router, with the direction on the anchor", () => {
|
|
335
|
+
const renderer = ({
|
|
336
|
+
to,
|
|
337
|
+
children,
|
|
338
|
+
attributes,
|
|
339
|
+
}: {
|
|
340
|
+
to: string;
|
|
341
|
+
children: React.ReactNode;
|
|
342
|
+
attributes?: Record<string, unknown>;
|
|
343
|
+
}) => (
|
|
344
|
+
<a href={`#routed${to}`} data-testid="routed" {...attributes}>
|
|
345
|
+
{children}
|
|
346
|
+
</a>
|
|
347
|
+
);
|
|
348
|
+
render(
|
|
349
|
+
<NavLinkContext.Provider value={renderer}>
|
|
350
|
+
<Page title="Order 1017" sequence={{ label: "Orders", next: MIDDLE.next }}>
|
|
351
|
+
body
|
|
352
|
+
</Page>
|
|
353
|
+
</NavLinkContext.Provider>,
|
|
354
|
+
);
|
|
355
|
+
const anchor = screen.getByRole("link", { name: "Next: Order 1018" });
|
|
356
|
+
expect(anchor).toHaveAttribute("href", "#routed/orders/1018");
|
|
357
|
+
expect(anchor).toHaveAttribute("rel", "next");
|
|
358
|
+
// The marker is on the cell the bar owns, not on the router's anchor: a renderer that
|
|
359
|
+
// forwards no attributes must not leave the bar unstyled.
|
|
360
|
+
expect(anchor.parentElement).toHaveAttribute("data-terp", "page-sequence-next");
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it("stays while the body loads or fails, like the band", () => {
|
|
364
|
+
const { container, rerender } = render(
|
|
365
|
+
<Page title="Order 1017" sequence={MIDDLE} isLoading>
|
|
366
|
+
body
|
|
367
|
+
</Page>,
|
|
368
|
+
);
|
|
369
|
+
expect(container.querySelector('[data-terp="page-sequence"]')).not.toBeNull();
|
|
370
|
+
rerender(
|
|
371
|
+
<Page title="Order 1017" sequence={MIDDLE} error="gone">
|
|
372
|
+
body
|
|
373
|
+
</Page>,
|
|
374
|
+
);
|
|
375
|
+
expect(screen.getByRole("link", { name: "Next: Order 1018" })).toBeInTheDocument();
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it("words the position and the directions through the strings seam", () => {
|
|
379
|
+
render(
|
|
380
|
+
<UiTextProvider
|
|
381
|
+
strings={{
|
|
382
|
+
pageSequencePrevious: "Vorige: {label}",
|
|
383
|
+
pageSequenceNext: "Volgende: {label}",
|
|
384
|
+
pageSequencePosition: "{current} van {total}",
|
|
385
|
+
}}
|
|
386
|
+
>
|
|
387
|
+
<Page title="Order 1017" sequence={MIDDLE}>
|
|
388
|
+
body
|
|
389
|
+
</Page>
|
|
390
|
+
</UiTextProvider>,
|
|
391
|
+
);
|
|
392
|
+
expect(screen.getByRole("link", { name: "Vorige: Order 1016" })).toBeInTheDocument();
|
|
393
|
+
expect(screen.getByRole("link", { name: "Volgende: Order 1018" })).toBeInTheDocument();
|
|
394
|
+
expect(screen.getByText("17 van 48")).toBeInTheDocument();
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
|
|
262
398
|
describe("OverviewPage", () => {
|
|
263
399
|
it("puts its title where a detail page puts its own: the trail's leaf", () => {
|
|
264
400
|
render(<OverviewPage title="Tasks">list</OverviewPage>);
|
|
@@ -297,3 +433,59 @@ describe("DetailPage", () => {
|
|
|
297
433
|
expect(screen.getByText("detail")).toBeInTheDocument();
|
|
298
434
|
});
|
|
299
435
|
});
|
|
436
|
+
|
|
437
|
+
describe("Page's summary band", () => {
|
|
438
|
+
it("renders the page's figures in a second header, directly after the title band", () => {
|
|
439
|
+
// A <header> because the body slot check drops headers by tag: the band is the frame's,
|
|
440
|
+
// and judging it as body would fail every governed page that has one.
|
|
441
|
+
const { container } = render(
|
|
442
|
+
<Page
|
|
443
|
+
title="Orders"
|
|
444
|
+
summary={
|
|
445
|
+
<StatGroup>
|
|
446
|
+
<Stat label="Open" value={12} />
|
|
447
|
+
</StatGroup>
|
|
448
|
+
}
|
|
449
|
+
>
|
|
450
|
+
<p>body</p>
|
|
451
|
+
</Page>,
|
|
452
|
+
);
|
|
453
|
+
const article = container.querySelector('[data-terp="page"]')!;
|
|
454
|
+
const [band, summary, body] = [...article.children];
|
|
455
|
+
expect(band).toHaveAttribute("data-terp", "page-header");
|
|
456
|
+
expect(summary!.tagName).toBe("HEADER");
|
|
457
|
+
expect(summary).toHaveAttribute("data-terp", "page-summary");
|
|
458
|
+
expect(summary!.querySelector('[data-terp="stat-group"]')).not.toBeNull();
|
|
459
|
+
expect(body!.textContent).toBe("body");
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
it("renders no band for a summary that renders nothing", () => {
|
|
463
|
+
// `summary={figures && <StatGroup/>}` hands the frame false before the figures arrive.
|
|
464
|
+
// Mutation: test `summary !== undefined` alone, and an empty padded band appears.
|
|
465
|
+
for (const summary of [undefined, null, false, ""] as const) {
|
|
466
|
+
const { container, unmount } = render(
|
|
467
|
+
<Page title="Orders" summary={summary}>
|
|
468
|
+
<p>body</p>
|
|
469
|
+
</Page>,
|
|
470
|
+
);
|
|
471
|
+
expect(container.querySelector('[data-terp="page-summary"]')).toBeNull();
|
|
472
|
+
unmount();
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
it("follows the body: no band while the page loads or shows its error", () => {
|
|
477
|
+
// The figures are data. The title band stays for orientation; the summary does not
|
|
478
|
+
// claim a place for figures that are not there.
|
|
479
|
+
const figures = <Stat label="Open" value={12} />;
|
|
480
|
+
for (const state of [{ isLoading: true }, { error: new Error("gone") }]) {
|
|
481
|
+
const { container, unmount } = render(
|
|
482
|
+
<Page title="Orders" summary={figures} {...state}>
|
|
483
|
+
<p>body</p>
|
|
484
|
+
</Page>,
|
|
485
|
+
);
|
|
486
|
+
expect(container.querySelector('[data-terp="page-header"]')).not.toBeNull();
|
|
487
|
+
expect(container.querySelector('[data-terp="page-summary"]')).toBeNull();
|
|
488
|
+
unmount();
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
});
|