@terpjs/react-core 0.31.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/ModuleNav.test.tsx +29 -1
- package/src/ModuleNav.tsx +5 -1
- package/src/Stat.test.tsx +35 -0
- package/src/Stat.tsx +3 -1
- package/src/admin/AdminHub.tsx +233 -86
- package/src/admin/RecordHistory.tsx +5 -0
- package/src/admin/admin.test.tsx +181 -14
- package/src/currentInView.ts +28 -0
- package/src/dataview/DataView.test.tsx +48 -1
- package/src/dataview/DataView.tsx +18 -3
- package/src/dataview/DataViewToolbar.tsx +4 -1
- package/src/locale.tsx +8 -0
- package/src/styles.test.ts +66 -0
- package/src/styles.ts +92 -14
- package/src/ui/Tabs.test.tsx +44 -0
- package/src/ui/Tabs.tsx +5 -2
- package/src/uiText.tsx +30 -1
- package/src/viewerTimeZone.ts +15 -0
package/src/styles.ts
CHANGED
|
@@ -357,17 +357,29 @@ html {
|
|
|
357
357
|
/* Badges ------------------------------------------------------------------- */
|
|
358
358
|
/* The border matches the soft fill exactly, so it reads as one flat pill while
|
|
359
359
|
still occupying a border box — which is what keeps a Badge the same height
|
|
360
|
-
next to a bordered control.
|
|
360
|
+
next to a bordered control.
|
|
361
|
+
|
|
362
|
+
A label longer than its container wraps inside it. It did not: nowrap with no width cap let a
|
|
363
|
+
phrase in a narrow column run out of it, cover the next one and widen a phone's page. The
|
|
364
|
+
radius is what keeps one line a pill. 0.75rem is more than half a one-line badge's height,
|
|
365
|
+
so the corners clamp to a full round, exactly as 9999px did, and less than half of two lines',
|
|
366
|
+
so a wrapped badge is a rounded box rather than a lozenge.
|
|
367
|
+
|
|
368
|
+
It wraps between words, and inside a word only once a word alone is wider than the
|
|
369
|
+
container. break-word on an inline block, not anywhere on an inline flex: anywhere also
|
|
370
|
+
shrinks the badge's narrowest width to one glyph, so an auto-layout table squeezed the
|
|
371
|
+
badge column first and split "Cancelled" mid-word over three lines. A badge holds text
|
|
372
|
+
only, so the inline block draws one line exactly as the inline flex did. */
|
|
361
373
|
[data-terp="badge"] {
|
|
362
|
-
display: inline-
|
|
363
|
-
|
|
374
|
+
display: inline-block;
|
|
375
|
+
max-inline-size: 100%;
|
|
364
376
|
border: 1px solid;
|
|
365
|
-
border-radius: var(--radius-
|
|
377
|
+
border-radius: var(--radius-lg);
|
|
366
378
|
padding: 2px var(--space-2);
|
|
367
379
|
font-size: var(--font-size-xs);
|
|
368
380
|
font-weight: var(--font-weight-semibold);
|
|
369
381
|
line-height: 1.4;
|
|
370
|
-
|
|
382
|
+
overflow-wrap: break-word;
|
|
371
383
|
}
|
|
372
384
|
[data-terp="badge"][data-tone="neutral"] {
|
|
373
385
|
color: var(--color-fg-muted);
|
|
@@ -1520,17 +1532,33 @@ textarea[data-terp="input"] {
|
|
|
1520
1532
|
}
|
|
1521
1533
|
|
|
1522
1534
|
/* Tabs --------------------------------------------------------------------- */
|
|
1523
|
-
/* The
|
|
1524
|
-
|
|
1535
|
+
/* The strip is one line that scrolls sideways where it does not fit. It wrapped, and a wrapped
|
|
1536
|
+
strip put the second line's tabs under the first line's selected edge and the rule under the
|
|
1537
|
+
second line, so on a phone it read as two strips with one tab marked between them. The
|
|
1538
|
+
current tab is scrolled into the strip's view as it changes (useCurrentInView).
|
|
1539
|
+
|
|
1540
|
+
The rule is a 1px background on the content box's last row rather than a bottom border. A
|
|
1541
|
+
scroll container clips at its padding edge, and the selected tab's 2px edge reached a pixel
|
|
1542
|
+
into the border to cover it; drawn inside, the rule sits under that edge and nothing is cut.
|
|
1543
|
+
The padding is room for the focus ring, which the container would clip as well, and the
|
|
1544
|
+
negative margin gives the layout that room back, so the strip sits where it did. */
|
|
1525
1545
|
[data-terp="tabs"] {
|
|
1526
1546
|
display: grid;
|
|
1527
1547
|
gap: var(--space-3);
|
|
1528
1548
|
}
|
|
1529
1549
|
[data-terp="tab-list"] {
|
|
1530
1550
|
display: flex;
|
|
1531
|
-
flex-wrap:
|
|
1551
|
+
flex-wrap: nowrap;
|
|
1532
1552
|
gap: var(--space-1);
|
|
1533
|
-
|
|
1553
|
+
margin: calc(-1 * var(--space-1));
|
|
1554
|
+
padding: var(--space-1);
|
|
1555
|
+
overflow-x: auto;
|
|
1556
|
+
scrollbar-width: none;
|
|
1557
|
+
background: linear-gradient(var(--color-neutral-200), var(--color-neutral-200)) no-repeat
|
|
1558
|
+
var(--space-1) calc(100% - var(--space-1)) / calc(100% - 2 * var(--space-1)) 1px;
|
|
1559
|
+
}
|
|
1560
|
+
[data-terp="tab-list"]::-webkit-scrollbar {
|
|
1561
|
+
display: none;
|
|
1534
1562
|
}
|
|
1535
1563
|
[data-terp="tab"] {
|
|
1536
1564
|
font-family: var(--font-family-sans);
|
|
@@ -1543,7 +1571,8 @@ textarea[data-terp="input"] {
|
|
|
1543
1571
|
color: var(--color-fg-muted);
|
|
1544
1572
|
background: transparent;
|
|
1545
1573
|
cursor: pointer;
|
|
1546
|
-
|
|
1574
|
+
flex: none;
|
|
1575
|
+
white-space: nowrap;
|
|
1547
1576
|
border-top-left-radius: var(--radius-sm);
|
|
1548
1577
|
border-top-right-radius: var(--radius-sm);
|
|
1549
1578
|
transition:
|
|
@@ -1563,17 +1592,28 @@ textarea[data-terp="input"] {
|
|
|
1563
1592
|
|
|
1564
1593
|
The edges are logical (border-block-end) to match tab and appshell-footer rather
|
|
1565
1594
|
than the physical borderBottom the component declared. Identical in every writing
|
|
1566
|
-
mode this framework ships, and the sheet already had one convention.
|
|
1595
|
+
mode this framework ships, and the sheet already had one convention.
|
|
1596
|
+
|
|
1597
|
+
One line that scrolls sideways where it does not fit, as the tab strip is and for its
|
|
1598
|
+
reason: wrapped, the strip's rule sat under the second line and the first line's active
|
|
1599
|
+
edge floated above it. The rule stays the nav's own border, outside the scrolling list, so
|
|
1600
|
+
nothing clips it; the list's padding is the focus ring's room and its negative margin gives
|
|
1601
|
+
the layout that room back. */
|
|
1567
1602
|
[data-terp="module-nav"] {
|
|
1568
1603
|
border-block-end: 1px solid var(--color-neutral-200);
|
|
1569
1604
|
}
|
|
1570
1605
|
[data-terp="module-nav-list"] {
|
|
1571
1606
|
list-style: none;
|
|
1572
|
-
margin:
|
|
1573
|
-
padding:
|
|
1607
|
+
margin: calc(-1 * var(--space-1));
|
|
1608
|
+
padding: var(--space-1);
|
|
1574
1609
|
display: flex;
|
|
1575
|
-
flex-wrap:
|
|
1610
|
+
flex-wrap: nowrap;
|
|
1576
1611
|
gap: var(--space-3);
|
|
1612
|
+
overflow-x: auto;
|
|
1613
|
+
scrollbar-width: none;
|
|
1614
|
+
}
|
|
1615
|
+
[data-terp="module-nav-list"]::-webkit-scrollbar {
|
|
1616
|
+
display: none;
|
|
1577
1617
|
}
|
|
1578
1618
|
[data-terp="module-nav-link"] {
|
|
1579
1619
|
display: inline-flex;
|
|
@@ -1581,6 +1621,7 @@ textarea[data-terp="input"] {
|
|
|
1581
1621
|
padding: var(--space-2) 0;
|
|
1582
1622
|
color: var(--color-fg-muted);
|
|
1583
1623
|
text-decoration: none;
|
|
1624
|
+
white-space: nowrap;
|
|
1584
1625
|
border-block-end: 2px solid transparent;
|
|
1585
1626
|
}
|
|
1586
1627
|
|
|
@@ -3080,6 +3121,23 @@ html:has([data-terp="page-sequence"]) {
|
|
|
3080
3121
|
[data-terp="hubcard-stat"][data-empty="true"] {
|
|
3081
3122
|
visibility: hidden;
|
|
3082
3123
|
}
|
|
3124
|
+
/* A list none of whose cards carries a figure keeps no figure row. The placeholder is there so
|
|
3125
|
+
a bare card stays flush with a full one beside it; with no full one there is nothing to stay
|
|
3126
|
+
flush with, and the row and the 10rem floor it helped pad out were blank space at the foot
|
|
3127
|
+
of every card — the admin hub's areas under its figures, an app's landing before its first
|
|
3128
|
+
figure. The cards in a row still share a height: the grid stretches them, and the
|
|
3129
|
+
description's track takes the slack. */
|
|
3130
|
+
:is(ul, ol):not(:has([data-terp="hubcard-stat"]:not([data-empty="true"])))
|
|
3131
|
+
> [data-terp="hubcard"]
|
|
3132
|
+
[data-terp="hubcard-body"] {
|
|
3133
|
+
grid-template-rows: auto 1fr;
|
|
3134
|
+
min-height: 0;
|
|
3135
|
+
}
|
|
3136
|
+
:is(ul, ol):not(:has([data-terp="hubcard-stat"]:not([data-empty="true"])))
|
|
3137
|
+
> [data-terp="hubcard"]
|
|
3138
|
+
[data-terp="hubcard-stat"] {
|
|
3139
|
+
display: none;
|
|
3140
|
+
}
|
|
3083
3141
|
|
|
3084
3142
|
/* DataView: the composition root ------------------------------------------- */
|
|
3085
3143
|
/* One display for both return paths, so it belongs on the bare marker rather than
|
|
@@ -5032,6 +5090,13 @@ button[data-terp="input"][data-placeholder="true"] {
|
|
|
5032
5090
|
font-variant-numeric: tabular-nums;
|
|
5033
5091
|
overflow-wrap: anywhere;
|
|
5034
5092
|
}
|
|
5093
|
+
/* A figure with nothing to show prints a dash, and the dash is an absence rather than a number:
|
|
5094
|
+
in the value's full ink and weight it read as a broken bar. A headline keeps its own ink, the
|
|
5095
|
+
one its fill was measured against. */
|
|
5096
|
+
[data-terp="stat"]:not([data-headline]) [data-terp="stat-value"][data-empty] {
|
|
5097
|
+
color: var(--color-fg-subtle);
|
|
5098
|
+
font-weight: var(--font-weight-normal);
|
|
5099
|
+
}
|
|
5035
5100
|
[data-terp="stat-delta"] {
|
|
5036
5101
|
display: flex;
|
|
5037
5102
|
flex-wrap: wrap;
|
|
@@ -5186,6 +5251,19 @@ button[data-terp="input"][data-placeholder="true"] {
|
|
|
5186
5251
|
[data-terp="stat-group"] > [data-terp="stat"][data-headline] + [data-terp="stat"] {
|
|
5187
5252
|
box-shadow: none;
|
|
5188
5253
|
}
|
|
5254
|
+
/* On a narrow screen the rows of figures, and the band they sit in, close up: a band of five
|
|
5255
|
+
figures is three rows deep there, and with a full gap between them and the band's full padding
|
|
5256
|
+
around them it put the page's own content half a phone's height down. The floor above stays,
|
|
5257
|
+
two to a line: three were tried, and a figure such as "4 m 12 s" then broke over two lines
|
|
5258
|
+
and its label over two more, which made the group taller rather than shorter. */
|
|
5259
|
+
@media ${NARROW_VIEWPORT} {
|
|
5260
|
+
[data-terp="stat-group"] {
|
|
5261
|
+
row-gap: var(--space-2);
|
|
5262
|
+
}
|
|
5263
|
+
[data-terp="page-summary"] {
|
|
5264
|
+
padding-block: var(--space-3);
|
|
5265
|
+
}
|
|
5266
|
+
}
|
|
5189
5267
|
/* A lone figure in a boxed card: the card is its frame, so the figure takes no tile of its own
|
|
5190
5268
|
-- a tile inside a box is a frame inside a frame. A group's cells keep theirs, and the
|
|
5191
5269
|
headline keeps its fill wherever it is. A plain card has no frame to lend, so a figure in one
|
package/src/ui/Tabs.test.tsx
CHANGED
|
@@ -55,3 +55,47 @@ describe("Tabs with a single tab", () => {
|
|
|
55
55
|
expect(screen.getByRole("tab", { name: "Only" })).toBeDisabled();
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
|
+
|
|
59
|
+
describe("Tabs on a strip too narrow for them", () => {
|
|
60
|
+
// jsdom lays nothing out, so the boxes are given: the strip is 100 to 300, and whichever tab
|
|
61
|
+
// is selected sits where each test puts it.
|
|
62
|
+
function boxes(selected: [number, number]) {
|
|
63
|
+
return vi
|
|
64
|
+
.spyOn(HTMLElement.prototype, "getBoundingClientRect")
|
|
65
|
+
.mockImplementation(function (this: HTMLElement) {
|
|
66
|
+
const at = (left: number, right: number) =>
|
|
67
|
+
({ left, right, top: 0, bottom: 20, width: right - left, height: 20, x: left, y: 0 }) as DOMRect;
|
|
68
|
+
if (this.dataset.terp === "tab-list") return at(100, 300);
|
|
69
|
+
if (this.getAttribute("aria-selected") === "true") return at(...selected);
|
|
70
|
+
return at(0, 0);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
it("scrolls the strip forward to a selected tab past its end, and follows the selection", () => {
|
|
75
|
+
const spy = boxes([320, 360]);
|
|
76
|
+
try {
|
|
77
|
+
render(<Tabs label="Sections" tabs={tabs} defaultValue="audit" />);
|
|
78
|
+
const list = screen.getByRole("tablist");
|
|
79
|
+
// Mutation: no scroll, which leaves the selected tab out of sight on a phone.
|
|
80
|
+
expect(list.scrollLeft).toBe(60);
|
|
81
|
+
fireEvent.click(screen.getByRole("tab", { name: "Overview" }));
|
|
82
|
+
// Mutation: scrolling on mount only, not as the selection moves.
|
|
83
|
+
expect(list.scrollLeft).toBe(120);
|
|
84
|
+
} finally {
|
|
85
|
+
spy.mockRestore();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("scrolls it back to a selected tab before its start", () => {
|
|
90
|
+
// jsdom keeps a negative scroll position where a browser clamps it, which is what makes the
|
|
91
|
+
// backward step visible here.
|
|
92
|
+
const spy = boxes([60, 90]);
|
|
93
|
+
try {
|
|
94
|
+
render(<Tabs label="Sections" tabs={tabs} defaultValue="audit" />);
|
|
95
|
+
// Mutation: scrolling only forwards, which leaves a tab before the strip's start hidden.
|
|
96
|
+
expect(screen.getByRole("tablist").scrollLeft).toBe(-40);
|
|
97
|
+
} finally {
|
|
98
|
+
spy.mockRestore();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
package/src/ui/Tabs.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { useId, useMemo, useState } from "react";
|
|
1
|
+
import { useId, useMemo, useRef, useState } from "react";
|
|
2
2
|
import type { KeyboardEvent, ReactNode } from "react";
|
|
3
3
|
|
|
4
|
+
import { useCurrentInView } from "../currentInView";
|
|
4
5
|
import { injectTerpStyles } from "../styles";
|
|
5
6
|
import { useUiText } from "../uiText";
|
|
6
7
|
import type { UiText } from "../uiText";
|
|
@@ -37,6 +38,8 @@ export function Tabs({ tabs, value, defaultValue, onChange, label }: TabsProps)
|
|
|
37
38
|
// Nothing reports that — axe sees a well-formed reference to nothing. The same refusal to
|
|
38
39
|
// interpolate caller strings into ids is written out at AppShell's nav-group labels.
|
|
39
40
|
const selectedIndex = tabs.findIndex((tab) => tab.value === selectedTab?.value);
|
|
41
|
+
const list = useRef<HTMLDivElement>(null);
|
|
42
|
+
useCurrentInView(list, selectedTab?.value, '[aria-selected="true"]');
|
|
40
43
|
|
|
41
44
|
// One usable tab is not a choice, so it gets no chrome. A tablist over a single tab costs
|
|
42
45
|
// a row of the screen to offer nothing, and it is worse than decorative to a screen
|
|
@@ -92,7 +95,7 @@ export function Tabs({ tabs, value, defaultValue, onChange, label }: TabsProps)
|
|
|
92
95
|
|
|
93
96
|
return (
|
|
94
97
|
<div data-terp="tabs">
|
|
95
|
-
<div role="tablist" data-terp="tab-list" aria-label={label === undefined ? undefined : resolve(label)} onKeyDown={onKeyDown}>
|
|
98
|
+
<div ref={list} role="tablist" data-terp="tab-list" aria-label={label === undefined ? undefined : resolve(label)} onKeyDown={onKeyDown}>
|
|
96
99
|
{tabs.map((tab, index) => {
|
|
97
100
|
const selected = tab.value === selectedTab?.value;
|
|
98
101
|
return (
|
package/src/uiText.tsx
CHANGED
|
@@ -193,8 +193,29 @@ export interface TerpStrings {
|
|
|
193
193
|
statUnfavourable: string;
|
|
194
194
|
/** A figure's sparkline as text; `{points}` is the listed points, each a label and a value. */
|
|
195
195
|
statTrend: string;
|
|
196
|
-
/**
|
|
196
|
+
/**
|
|
197
|
+
* Named the total on the admin hub's users and groups cards until the hub became a dashboard,
|
|
198
|
+
* whose figures name what they count. Not read by the framework since; kept because a
|
|
199
|
+
* catalog that leaves out a framework string, or carries one the framework does not know, is
|
|
200
|
+
* refused, so an app's catalog written for 0.31.0 still loads.
|
|
201
|
+
*/
|
|
197
202
|
adminHubTotal: string;
|
|
203
|
+
/** The admin hub's headline figure: the accounts that can sign in. */
|
|
204
|
+
adminHubActiveAccounts: string;
|
|
205
|
+
/** Under that figure; `{count}` is the number of deactivated accounts. */
|
|
206
|
+
adminHubDeactivated: string;
|
|
207
|
+
/** The admin hub's figure for the audit trail's last days; `{count}` is how many. */
|
|
208
|
+
adminHubChangesWeek: string;
|
|
209
|
+
/** What that figure's change is measured against. */
|
|
210
|
+
adminHubVsWeekBefore: string;
|
|
211
|
+
/** The admin hub's chart of the trail per day. */
|
|
212
|
+
adminHubChangesPerDay: string;
|
|
213
|
+
/** That chart's series; `{count}` is how many days it draws. */
|
|
214
|
+
adminHubLastDays: string;
|
|
215
|
+
/** That chart's comparison, drawn dashed; `{count}` is how many days it covers. */
|
|
216
|
+
adminHubDaysBefore: string;
|
|
217
|
+
/** The admin hub's share of each kind of change; `{count}` is how many days it covers. */
|
|
218
|
+
adminHubChangesByKind: string;
|
|
198
219
|
/** A status history read out; `{label}` is what ran and `{runs}` the listed runs, each a label and its ending. */
|
|
199
220
|
statusHistoryRuns: string;
|
|
200
221
|
/** A record's own history, from the audit trail, on its admin screen: the section's title. */
|
|
@@ -552,6 +573,14 @@ export const DEFAULT_STRINGS: TerpStrings = {
|
|
|
552
573
|
statUnfavourable: "unfavourable",
|
|
553
574
|
statTrend: "Over time: {points}",
|
|
554
575
|
adminHubTotal: "Total",
|
|
576
|
+
adminHubActiveAccounts: "Active accounts",
|
|
577
|
+
adminHubDeactivated: "{count} deactivated",
|
|
578
|
+
adminHubChangesWeek: "Changes, last {count} days",
|
|
579
|
+
adminHubVsWeekBefore: "vs the week before",
|
|
580
|
+
adminHubChangesPerDay: "Changes per day",
|
|
581
|
+
adminHubLastDays: "Last {count} days",
|
|
582
|
+
adminHubDaysBefore: "The {count} days before",
|
|
583
|
+
adminHubChangesByKind: "Changes by kind, last {count} days",
|
|
555
584
|
statusHistoryRuns: "{label}, oldest first: {runs}",
|
|
556
585
|
recordHistory: "History",
|
|
557
586
|
auditActionCreated: "Created",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The viewer's own time zone, as an IANA name, or `UTC` where the host cannot say.
|
|
3
|
+
*
|
|
4
|
+
* The one question about the host the app has no answer of its own for. Dates are formatted in
|
|
5
|
+
* the app's locale everywhere, but a calendar day is the viewer's: the admin hub counts the
|
|
6
|
+
* audit trail in the days of whoever is looking at it (ADR 0171). Its own module so the
|
|
7
|
+
* locale gate's allowance covers this one read and nothing that might format beside it.
|
|
8
|
+
*/
|
|
9
|
+
export function viewerTimeZone(): string {
|
|
10
|
+
try {
|
|
11
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
|
|
12
|
+
} catch {
|
|
13
|
+
return "UTC";
|
|
14
|
+
}
|
|
15
|
+
}
|