@keystone-sites/marketing-design-system 1.0.13 → 1.0.15
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/AGENTS.md +11 -1
- package/index.css +3 -0
- package/package.json +7 -1
- package/primitives/buttons.css +13 -1
- package/primitives/buttons.tsx +46 -0
- package/primitives/disclosure.css +9 -2
- package/primitives/disclosure.tsx +55 -2
- package/primitives/keystone-score.css +156 -0
- package/primitives/keystone-score.tsx +204 -0
- package/primitives/prose.css +32 -0
- package/primitives/prose.tsx +28 -4
- package/primitives/ramps.css +2 -9
- package/primitives/report-nav.css +322 -0
- package/primitives/report-nav.tsx +224 -0
- package/primitives/report.css +567 -0
- package/primitives/report.tsx +337 -0
- package/primitives/status.css +97 -11
- package/primitives/status.tsx +98 -3
- package/primitives/surface.css +10 -0
- package/primitives/surface.tsx +7 -2
- package/primitives/text.css +13 -0
- package/sections/landing-quote.tsx +1 -1
- package/sections/nav.css +6 -6
- package/tokens/motion.css +14 -0
package/primitives/prose.tsx
CHANGED
|
@@ -135,25 +135,49 @@ export function Figure({
|
|
|
135
135
|
);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
/** Names a group of surfaces inside a page body.
|
|
138
|
+
/** Names a group of surfaces inside a page body. `lg` is the Grader
|
|
139
|
+
* report's section head (ks-Grader grader/section-head): a thin serif
|
|
140
|
+
* that runs 28 → 36 with the grid, over a lede at 16 → 18. */
|
|
139
141
|
export function SecTitle({
|
|
140
142
|
as: Tag = "h2",
|
|
143
|
+
size,
|
|
144
|
+
id,
|
|
141
145
|
className,
|
|
142
146
|
children,
|
|
143
147
|
}: {
|
|
144
148
|
as?: ElementType;
|
|
149
|
+
size?: "lg";
|
|
150
|
+
/** Lets the section it heads name itself by it (`aria-labelledby`). */
|
|
151
|
+
id?: string;
|
|
145
152
|
className?: string;
|
|
146
153
|
children: ReactNode;
|
|
147
154
|
}) {
|
|
155
|
+
const step =
|
|
156
|
+
size === "lg"
|
|
157
|
+
? "type ts-display-serif-xs-plus-extralight"
|
|
158
|
+
: "type type-fixed ts-display-serif-xs-regular";
|
|
148
159
|
return (
|
|
149
|
-
<Tag className={cx("
|
|
160
|
+
<Tag className={cx(step, "sec-title", className)} data-size={size} id={id}>
|
|
150
161
|
{children}
|
|
151
162
|
</Tag>
|
|
152
163
|
);
|
|
153
164
|
}
|
|
154
165
|
|
|
155
|
-
export function SecSub({
|
|
156
|
-
|
|
166
|
+
export function SecSub({
|
|
167
|
+
size,
|
|
168
|
+
className,
|
|
169
|
+
children,
|
|
170
|
+
}: {
|
|
171
|
+
size?: "lg";
|
|
172
|
+
className?: string;
|
|
173
|
+
children: ReactNode;
|
|
174
|
+
}) {
|
|
175
|
+
const step = size === "lg" ? "type ts-text-md-light" : "type type-fixed ts-text-sm-light";
|
|
176
|
+
return (
|
|
177
|
+
<p className={cx(step, "sec-sub", className)} data-size={size}>
|
|
178
|
+
{children}
|
|
179
|
+
</p>
|
|
180
|
+
);
|
|
157
181
|
}
|
|
158
182
|
|
|
159
183
|
/** Short lines marked with a teal dot. */
|
package/primitives/ramps.css
CHANGED
|
@@ -62,20 +62,13 @@
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
/* quote: 2xs-plus-extralight 20/24 → sm-plus-extralight 36/42;
|
|
66
|
-
opening
|
|
65
|
+
/* quote: 2xs-plus-extralight 20/24 → sm-plus-extralight 36/42; pair it
|
|
66
|
+
with `type-hang` so the opening mark hangs into the margin. */
|
|
67
67
|
.ramp-quote {
|
|
68
68
|
color: var(--color-text-100);
|
|
69
|
-
text-indent: -0.434em;
|
|
70
69
|
--fs-rd2: var(--ts-display-serif-sm-plus-extralight-fs);
|
|
71
70
|
--lh-rd2: var(--ts-display-serif-sm-plus-extralight-lh);
|
|
72
71
|
}
|
|
73
|
-
@supports (hanging-punctuation: first) {
|
|
74
|
-
.ramp-quote {
|
|
75
|
-
text-indent: 0;
|
|
76
|
-
hanging-punctuation: first;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
72
|
@container (--rt) {
|
|
80
73
|
.ramp-quote {
|
|
81
74
|
--font: var(--ts-display-serif-sm-plus-extralight-font);
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/* The report nav (ks-Grader grader-nav 64:8505): the page switcher in
|
|
2
|
+
the nav bar once a report is unlocked. From the first desktop anchor
|
|
3
|
+
the pages are chips in the bar, the current one on white. Below it
|
|
4
|
+
the current page's name and a menu button open a card under the bar:
|
|
5
|
+
the pages as rows with their score rings, the current one muted, and
|
|
6
|
+
the account at the foot. The card hangs from the bar it is mounted
|
|
7
|
+
in — the host is the positioned ancestor — spanning it inside
|
|
8
|
+
`--rnav-card-inset` on the phone and standing under the controls at
|
|
9
|
+
its own width from the tablet anchor. */
|
|
10
|
+
|
|
11
|
+
/* Designed constants for this file. */
|
|
12
|
+
:root {
|
|
13
|
+
--rnav-control-h: 40px;
|
|
14
|
+
--rnav-row-h: 64px;
|
|
15
|
+
--rnav-foot-h: 80px;
|
|
16
|
+
--rnav-card-w: 350px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* ---- the chips (rd1 and up) ---- */
|
|
20
|
+
|
|
21
|
+
/* The chips hold their copy; whatever shares the bar with them (the
|
|
22
|
+
host's account control) is what gives way. */
|
|
23
|
+
.rnav-chips {
|
|
24
|
+
display: none;
|
|
25
|
+
flex: none;
|
|
26
|
+
gap: var(--space-sm);
|
|
27
|
+
margin: var(--space-none);
|
|
28
|
+
padding: var(--space-none);
|
|
29
|
+
list-style: none;
|
|
30
|
+
}
|
|
31
|
+
.rnav-chips-item {
|
|
32
|
+
flex: none;
|
|
33
|
+
display: flex;
|
|
34
|
+
}
|
|
35
|
+
.rnav-chip {
|
|
36
|
+
display: inline-flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
box-sizing: border-box;
|
|
39
|
+
height: var(--rnav-control-h);
|
|
40
|
+
padding-inline: var(--space-lg);
|
|
41
|
+
border-radius: var(--radius-xs);
|
|
42
|
+
background: var(--color-bg-200);
|
|
43
|
+
color: var(--color-text-300);
|
|
44
|
+
text-decoration: none;
|
|
45
|
+
white-space: nowrap;
|
|
46
|
+
transition:
|
|
47
|
+
background-color var(--motion-hover-duration) var(--motion-hover-ease),
|
|
48
|
+
color var(--motion-hover-duration) var(--motion-hover-ease);
|
|
49
|
+
}
|
|
50
|
+
.rnav-chip[aria-current="page"] {
|
|
51
|
+
background: var(--color-bg-000);
|
|
52
|
+
}
|
|
53
|
+
@media (hover: hover) {
|
|
54
|
+
.rnav-chip:not([aria-current="page"]):hover {
|
|
55
|
+
background: var(--color-bg-300);
|
|
56
|
+
color: var(--color-text-100);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
.rnav-chip:focus-visible {
|
|
60
|
+
outline: none;
|
|
61
|
+
box-shadow: 0 0 0 var(--ring-w) var(--color-border-200);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* ---- the menu (below rd1) ---- */
|
|
65
|
+
|
|
66
|
+
/* The controls stand at the bar's end, whatever precedes them. */
|
|
67
|
+
.rnav-menu {
|
|
68
|
+
display: flex;
|
|
69
|
+
align-items: center;
|
|
70
|
+
gap: var(--space-md);
|
|
71
|
+
margin-inline-start: auto;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* The current page: its name and the chevron, which turns while the
|
|
75
|
+
card is open. */
|
|
76
|
+
.rnav-current {
|
|
77
|
+
appearance: none;
|
|
78
|
+
display: inline-flex;
|
|
79
|
+
align-items: center;
|
|
80
|
+
gap: var(--fitem-gap);
|
|
81
|
+
box-sizing: border-box;
|
|
82
|
+
height: var(--rnav-control-h);
|
|
83
|
+
margin: var(--space-none);
|
|
84
|
+
padding-inline: var(--space-lg);
|
|
85
|
+
border: 0;
|
|
86
|
+
border-radius: var(--radius-xs);
|
|
87
|
+
background: var(--color-bg-200);
|
|
88
|
+
color: var(--color-text-300);
|
|
89
|
+
white-space: nowrap;
|
|
90
|
+
cursor: pointer;
|
|
91
|
+
transition:
|
|
92
|
+
background-color var(--motion-hover-duration) var(--motion-hover-ease),
|
|
93
|
+
color var(--motion-hover-duration) var(--motion-hover-ease);
|
|
94
|
+
}
|
|
95
|
+
.rnav-current-tick {
|
|
96
|
+
flex: none;
|
|
97
|
+
color: var(--color-border-400);
|
|
98
|
+
transition: rotate var(--motion-drawer-duration) var(--motion-drawer-ease);
|
|
99
|
+
}
|
|
100
|
+
.rnav-menu[data-open] .rnav-current-tick {
|
|
101
|
+
rotate: 180deg;
|
|
102
|
+
transition: rotate var(--motion-drawer-duration) var(--motion-drawer-ease-open);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/* The menu button (grader/nav-toggle 214:22707): the glyph swaps for
|
|
106
|
+
the close while the card is open and the ground deepens a step. */
|
|
107
|
+
.rnav-toggle {
|
|
108
|
+
appearance: none;
|
|
109
|
+
display: grid;
|
|
110
|
+
place-items: center;
|
|
111
|
+
flex: none;
|
|
112
|
+
width: var(--rnav-control-h);
|
|
113
|
+
height: var(--rnav-control-h);
|
|
114
|
+
margin: var(--space-none);
|
|
115
|
+
padding: var(--space-none);
|
|
116
|
+
border: 0;
|
|
117
|
+
border-radius: var(--radius-xs);
|
|
118
|
+
background: var(--color-bg-200);
|
|
119
|
+
color: var(--color-text-400);
|
|
120
|
+
cursor: pointer;
|
|
121
|
+
touch-action: manipulation;
|
|
122
|
+
transition: background-color var(--motion-glyph-swap-dur) var(--motion-drawer-ease-open);
|
|
123
|
+
}
|
|
124
|
+
.rnav-menu[data-open] .rnav-toggle {
|
|
125
|
+
background: var(--color-bg-300);
|
|
126
|
+
}
|
|
127
|
+
.rnav-glyphs {
|
|
128
|
+
display: grid;
|
|
129
|
+
place-items: center;
|
|
130
|
+
}
|
|
131
|
+
.rnav-glyphs svg {
|
|
132
|
+
grid-area: 1 / 1;
|
|
133
|
+
transition:
|
|
134
|
+
opacity var(--motion-glyph-swap-dur) var(--motion-drawer-ease-open),
|
|
135
|
+
filter var(--motion-glyph-swap-dur) var(--motion-drawer-ease-open),
|
|
136
|
+
scale var(--motion-glyph-swap-dur) var(--motion-drawer-ease-open);
|
|
137
|
+
}
|
|
138
|
+
.rnav-glyph-x,
|
|
139
|
+
.rnav-menu[data-open] .rnav-glyph-menu {
|
|
140
|
+
opacity: 0;
|
|
141
|
+
filter: blur(var(--motion-glyph-swap-blur));
|
|
142
|
+
scale: var(--motion-glyph-swap-scale);
|
|
143
|
+
}
|
|
144
|
+
.rnav-menu[data-open] .rnav-glyph-x {
|
|
145
|
+
opacity: 1;
|
|
146
|
+
filter: blur(0);
|
|
147
|
+
scale: 1;
|
|
148
|
+
}
|
|
149
|
+
@media (hover: hover) {
|
|
150
|
+
.rnav-current:hover {
|
|
151
|
+
background: var(--color-bg-300);
|
|
152
|
+
color: var(--color-text-100);
|
|
153
|
+
}
|
|
154
|
+
.rnav-toggle:hover {
|
|
155
|
+
background: var(--color-bg-300);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
.rnav-current:focus-visible,
|
|
159
|
+
.rnav-toggle:focus-visible {
|
|
160
|
+
outline: none;
|
|
161
|
+
box-shadow: 0 0 0 var(--ring-w) var(--color-border-200);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/* The card: hung from the host bar's foot, revealed by the fade-rise.
|
|
165
|
+
Shut, it is out of the tree for pointer and keyboard alike. Its lift
|
|
166
|
+
(214:27321, 214:28012) is three soft layers of border/500's ink, a
|
|
167
|
+
step deeper from the tablet anchor; the ink resolves here, not on
|
|
168
|
+
:root, so a themed host supplies its own. */
|
|
169
|
+
.rnav-card {
|
|
170
|
+
--rnav-ink-4: color-mix(in srgb, var(--color-border-500) 4%, transparent);
|
|
171
|
+
--rnav-ink-3: color-mix(in srgb, var(--color-border-500) 3%, transparent);
|
|
172
|
+
--rnav-ink-8: color-mix(in srgb, var(--color-border-500) 8%, transparent);
|
|
173
|
+
--rnav-shadow:
|
|
174
|
+
0 2px 2px 0 var(--rnav-ink-4), 0 4px 6px 0 var(--rnav-ink-3), 0 12px 16px 0 var(--rnav-ink-8);
|
|
175
|
+
--rnav-shadow-rt:
|
|
176
|
+
0 3px 3px 0 var(--rnav-ink-4), 0 8px 8px 0 var(--rnav-ink-3), 0 20px 24px 0 var(--rnav-ink-8);
|
|
177
|
+
position: absolute;
|
|
178
|
+
top: 100%;
|
|
179
|
+
inset-inline: var(--rnav-card-inset, 0);
|
|
180
|
+
z-index: 1;
|
|
181
|
+
box-sizing: border-box;
|
|
182
|
+
border-radius: var(--radius-xs);
|
|
183
|
+
background: var(--color-bg-200);
|
|
184
|
+
box-shadow: var(--rnav-shadow);
|
|
185
|
+
outline: none;
|
|
186
|
+
opacity: 0;
|
|
187
|
+
translate: 0 calc(-1 * var(--motion-reveal-rise));
|
|
188
|
+
visibility: hidden;
|
|
189
|
+
pointer-events: none;
|
|
190
|
+
transition:
|
|
191
|
+
opacity var(--motion-reveal-fade) ease,
|
|
192
|
+
translate var(--motion-reveal-slide) var(--motion-drawer-ease),
|
|
193
|
+
visibility 0s linear var(--motion-reveal-slide);
|
|
194
|
+
}
|
|
195
|
+
.rnav-menu[data-open] .rnav-card {
|
|
196
|
+
opacity: 1;
|
|
197
|
+
translate: 0 0;
|
|
198
|
+
visibility: visible;
|
|
199
|
+
pointer-events: auto;
|
|
200
|
+
transition:
|
|
201
|
+
opacity var(--motion-reveal-fade) ease,
|
|
202
|
+
translate var(--motion-reveal-slide) var(--motion-drawer-ease-open);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/* The pages: a row each, hairlines between, the score ring at the end. */
|
|
206
|
+
.rnav-pages {
|
|
207
|
+
margin: var(--space-none);
|
|
208
|
+
padding: var(--space-none);
|
|
209
|
+
list-style: none;
|
|
210
|
+
}
|
|
211
|
+
.rnav-row + .rnav-row,
|
|
212
|
+
.rnav-foot {
|
|
213
|
+
border-top: 1px solid var(--color-border-100);
|
|
214
|
+
}
|
|
215
|
+
.rnav-page {
|
|
216
|
+
display: flex;
|
|
217
|
+
align-items: center;
|
|
218
|
+
justify-content: space-between;
|
|
219
|
+
gap: var(--space-lg);
|
|
220
|
+
box-sizing: border-box;
|
|
221
|
+
min-height: var(--rnav-row-h);
|
|
222
|
+
padding-inline: var(--space-xl);
|
|
223
|
+
color: var(--color-text-300);
|
|
224
|
+
text-decoration: none;
|
|
225
|
+
transition: color var(--motion-hover-duration) var(--motion-hover-ease);
|
|
226
|
+
}
|
|
227
|
+
.rnav-page[aria-current="page"] {
|
|
228
|
+
color: var(--color-text-400);
|
|
229
|
+
}
|
|
230
|
+
.rnav-page-label {
|
|
231
|
+
min-width: 0;
|
|
232
|
+
}
|
|
233
|
+
@media (hover: hover) {
|
|
234
|
+
.rnav-page:not([aria-current="page"]):hover {
|
|
235
|
+
color: var(--color-text-100);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
.rnav-page:focus-visible {
|
|
239
|
+
outline: none;
|
|
240
|
+
box-shadow: inset 0 0 0 var(--ring-w) var(--color-border-200);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/* The foot: who is signed in, and the way out. */
|
|
244
|
+
.rnav-foot {
|
|
245
|
+
display: flex;
|
|
246
|
+
align-items: center;
|
|
247
|
+
justify-content: space-between;
|
|
248
|
+
gap: var(--space-lg);
|
|
249
|
+
box-sizing: border-box;
|
|
250
|
+
min-height: var(--rnav-foot-h);
|
|
251
|
+
padding: var(--space-lg) var(--space-xl);
|
|
252
|
+
}
|
|
253
|
+
.rnav-who {
|
|
254
|
+
display: flex;
|
|
255
|
+
flex-direction: column;
|
|
256
|
+
gap: var(--space-2xs);
|
|
257
|
+
min-width: 0;
|
|
258
|
+
}
|
|
259
|
+
.rnav-who-label {
|
|
260
|
+
color: var(--color-text-400);
|
|
261
|
+
}
|
|
262
|
+
.rnav-who-name {
|
|
263
|
+
overflow: hidden;
|
|
264
|
+
color: var(--color-text-300);
|
|
265
|
+
text-overflow: ellipsis;
|
|
266
|
+
white-space: nowrap;
|
|
267
|
+
}
|
|
268
|
+
/* 214:27848 draws this one control with a 2px corner against the 4px
|
|
269
|
+
on every other control in the bar; it takes the bar's. */
|
|
270
|
+
.rnav-signout {
|
|
271
|
+
appearance: none;
|
|
272
|
+
display: inline-flex;
|
|
273
|
+
align-items: center;
|
|
274
|
+
flex: none;
|
|
275
|
+
box-sizing: border-box;
|
|
276
|
+
height: var(--rnav-control-h);
|
|
277
|
+
margin: var(--space-none);
|
|
278
|
+
padding-inline: var(--space-xl);
|
|
279
|
+
border: 0;
|
|
280
|
+
border-radius: var(--radius-xs);
|
|
281
|
+
background: var(--color-bg-300);
|
|
282
|
+
color: var(--color-text-300);
|
|
283
|
+
white-space: nowrap;
|
|
284
|
+
cursor: pointer;
|
|
285
|
+
transition:
|
|
286
|
+
background-color var(--motion-hover-duration) var(--motion-hover-ease),
|
|
287
|
+
color var(--motion-hover-duration) var(--motion-hover-ease);
|
|
288
|
+
}
|
|
289
|
+
@media (hover: hover) {
|
|
290
|
+
.rnav-signout:hover {
|
|
291
|
+
background: var(--color-bg-400);
|
|
292
|
+
color: var(--color-text-100);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
.rnav-signout:disabled {
|
|
296
|
+
color: var(--color-text-600);
|
|
297
|
+
cursor: progress;
|
|
298
|
+
}
|
|
299
|
+
.rnav-signout:focus-visible {
|
|
300
|
+
outline: none;
|
|
301
|
+
box-shadow: 0 0 0 var(--ring-w) var(--color-border-200);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/* From the tablet anchor the card stands under the controls at its own
|
|
305
|
+
width, flush with the bar's end. */
|
|
306
|
+
@container (--rt) {
|
|
307
|
+
.rnav-card {
|
|
308
|
+
inset-inline: auto var(--rnav-card-inset, 0);
|
|
309
|
+
width: var(--rnav-card-w);
|
|
310
|
+
box-shadow: var(--rnav-shadow-rt);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/* From the first desktop anchor the chips take the menu's place. */
|
|
315
|
+
@container (--rd1) {
|
|
316
|
+
.rnav-chips {
|
|
317
|
+
display: flex;
|
|
318
|
+
}
|
|
319
|
+
.rnav-menu {
|
|
320
|
+
display: none;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/** The report's page switcher (ks-Grader grader-nav, 64:8505), standing
|
|
4
|
+
* in the nav bar once a report is unlocked. From the first desktop
|
|
5
|
+
* anchor the pages are chips in the bar (`ReportNavChips`): names only,
|
|
6
|
+
* the current one on white. Below it the bar holds the current page's
|
|
7
|
+
* name with a chevron and a menu button (`ReportNavMenu`); either opens
|
|
8
|
+
* a card under the bar with the pages as rows, each with its score as a
|
|
9
|
+
* small ring — an unscored page an empty ring with a dash, never a
|
|
10
|
+
* number — the current one muted, ending in who is signed in and the
|
|
11
|
+
* way out. The card hangs from the bar it is mounted in: the host is
|
|
12
|
+
* the positioned ancestor, and sets `--rnav-card-inset` to its gutter
|
|
13
|
+
* so the card spans the phone inside the margins. Picking a page, the
|
|
14
|
+
* close button, a tap outside, Escape or focus leaving put the card
|
|
15
|
+
* away; focus goes into the card on open and back to the opener on
|
|
16
|
+
* close. Styles in report-nav.css (`rnav-`). */
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
useEffect,
|
|
20
|
+
useId,
|
|
21
|
+
useRef,
|
|
22
|
+
type FocusEvent,
|
|
23
|
+
type KeyboardEvent,
|
|
24
|
+
type MouseEvent,
|
|
25
|
+
} from "react";
|
|
26
|
+
import { IconNavMenu, IconNavTrigger } from "../icons";
|
|
27
|
+
import { usePopover } from "../lib/use-popover";
|
|
28
|
+
import { ScoreRing, type Grade } from "./status";
|
|
29
|
+
|
|
30
|
+
export interface ReportNavPage<Id extends string> {
|
|
31
|
+
id: Id;
|
|
32
|
+
label: string;
|
|
33
|
+
href: string;
|
|
34
|
+
/** The page's score on 100; null where it could not be scored. */
|
|
35
|
+
score: number | null;
|
|
36
|
+
grade: Grade;
|
|
37
|
+
/** Attributes the host adds to the link (tracking). */
|
|
38
|
+
attrs?: Record<string, string>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ReportNavCopy {
|
|
42
|
+
/** Accessible name of the list of pages. */
|
|
43
|
+
pages: string;
|
|
44
|
+
/** The menu button's name while the card is shut, and while open. */
|
|
45
|
+
menu: string;
|
|
46
|
+
close: string;
|
|
47
|
+
/** The ring's name beside a page's label: scored, and not. */
|
|
48
|
+
score: string;
|
|
49
|
+
unscored: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface ReportNavAccount {
|
|
53
|
+
/** The line over the name: "Signed in as". */
|
|
54
|
+
label: string;
|
|
55
|
+
who: string;
|
|
56
|
+
signOut: string;
|
|
57
|
+
onSignOut: () => void;
|
|
58
|
+
/** The sign-out is under way; the control waits. */
|
|
59
|
+
busy?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The pages as chips in the bar, from the first desktop anchor. */
|
|
63
|
+
export function ReportNavChips<Id extends string>({
|
|
64
|
+
pages,
|
|
65
|
+
current,
|
|
66
|
+
label,
|
|
67
|
+
}: {
|
|
68
|
+
pages: readonly ReportNavPage<Id>[];
|
|
69
|
+
current: Id;
|
|
70
|
+
/** Accessible name of the list. */
|
|
71
|
+
label: string;
|
|
72
|
+
}) {
|
|
73
|
+
return (
|
|
74
|
+
<ul className="rnav-chips" aria-label={label}>
|
|
75
|
+
{pages.map((page) => (
|
|
76
|
+
<li key={page.id} className="rnav-chips-item">
|
|
77
|
+
<a
|
|
78
|
+
className="type type-fixed ts-text-md-medium rnav-chip"
|
|
79
|
+
href={page.href}
|
|
80
|
+
aria-current={page.id === current ? "page" : undefined}
|
|
81
|
+
{...page.attrs}
|
|
82
|
+
>
|
|
83
|
+
{page.label}
|
|
84
|
+
</a>
|
|
85
|
+
</li>
|
|
86
|
+
))}
|
|
87
|
+
</ul>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The current page and the menu button, below the first desktop
|
|
92
|
+
* anchor, and the card they open. `account` is the signed-in reader's
|
|
93
|
+
* foot — who, and the way out; a reader with no session has no foot. */
|
|
94
|
+
export function ReportNavMenu<Id extends string>({
|
|
95
|
+
pages,
|
|
96
|
+
current,
|
|
97
|
+
copy,
|
|
98
|
+
account,
|
|
99
|
+
}: {
|
|
100
|
+
pages: readonly ReportNavPage<Id>[];
|
|
101
|
+
current: Id;
|
|
102
|
+
copy: ReportNavCopy;
|
|
103
|
+
account?: ReportNavAccount;
|
|
104
|
+
}) {
|
|
105
|
+
const { open, setOpen, rootRef } = usePopover<HTMLDivElement>();
|
|
106
|
+
const cardRef = useRef<HTMLDivElement>(null);
|
|
107
|
+
/* The control that opened the card takes focus back when it closes. */
|
|
108
|
+
const openerRef = useRef<HTMLButtonElement | null>(null);
|
|
109
|
+
const cardId = useId();
|
|
110
|
+
const page = pages.find((p) => p.id === current);
|
|
111
|
+
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
if (open) cardRef.current?.focus({ preventScroll: true });
|
|
114
|
+
}, [open]);
|
|
115
|
+
|
|
116
|
+
const close = () => {
|
|
117
|
+
setOpen(false);
|
|
118
|
+
openerRef.current?.focus({ preventScroll: true });
|
|
119
|
+
};
|
|
120
|
+
const toggle = (event: MouseEvent<HTMLButtonElement>) => {
|
|
121
|
+
if (open) {
|
|
122
|
+
close();
|
|
123
|
+
} else {
|
|
124
|
+
openerRef.current = event.currentTarget;
|
|
125
|
+
setOpen(true);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
129
|
+
if (event.key === "Escape" && open) close();
|
|
130
|
+
};
|
|
131
|
+
const onBlur = (event: FocusEvent<HTMLDivElement>) => {
|
|
132
|
+
const next = event.relatedTarget;
|
|
133
|
+
if (open && (!(next instanceof Node) || !event.currentTarget.contains(next))) setOpen(false);
|
|
134
|
+
};
|
|
135
|
+
/* A page picked: the link navigates; the card does not wait for it. */
|
|
136
|
+
const onCardClick = (event: MouseEvent<HTMLDivElement>) => {
|
|
137
|
+
if (event.target instanceof Element && event.target.closest("a")) setOpen(false);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<div
|
|
142
|
+
ref={rootRef}
|
|
143
|
+
className="rnav-menu"
|
|
144
|
+
data-open={open || undefined}
|
|
145
|
+
onKeyDown={onKeyDown}
|
|
146
|
+
onBlur={onBlur}
|
|
147
|
+
>
|
|
148
|
+
<button
|
|
149
|
+
type="button"
|
|
150
|
+
className="type type-fixed ts-text-md-medium rnav-current"
|
|
151
|
+
aria-expanded={open}
|
|
152
|
+
aria-controls={cardId}
|
|
153
|
+
onClick={toggle}
|
|
154
|
+
>
|
|
155
|
+
{page?.label}
|
|
156
|
+
<IconNavTrigger className="rnav-current-tick" variant="chevron" />
|
|
157
|
+
</button>
|
|
158
|
+
<button
|
|
159
|
+
type="button"
|
|
160
|
+
className="rnav-toggle"
|
|
161
|
+
aria-expanded={open}
|
|
162
|
+
aria-controls={cardId}
|
|
163
|
+
aria-label={open ? copy.close : copy.menu}
|
|
164
|
+
onClick={toggle}
|
|
165
|
+
>
|
|
166
|
+
<span className="rnav-glyphs" aria-hidden="true">
|
|
167
|
+
<IconNavMenu className="rnav-glyph-menu" />
|
|
168
|
+
<IconNavMenu className="rnav-glyph-x" open />
|
|
169
|
+
</span>
|
|
170
|
+
</button>
|
|
171
|
+
<div
|
|
172
|
+
id={cardId}
|
|
173
|
+
ref={cardRef}
|
|
174
|
+
className="rnav-card"
|
|
175
|
+
tabIndex={-1}
|
|
176
|
+
inert={!open || undefined}
|
|
177
|
+
onClick={onCardClick}
|
|
178
|
+
>
|
|
179
|
+
<ul className="rnav-pages" aria-label={copy.pages}>
|
|
180
|
+
{pages.map((p) => (
|
|
181
|
+
<li key={p.id} className="rnav-row">
|
|
182
|
+
<a
|
|
183
|
+
className="type type-fixed ts-text-md-medium rnav-page"
|
|
184
|
+
href={p.href}
|
|
185
|
+
aria-current={p.id === current ? "page" : undefined}
|
|
186
|
+
{...p.attrs}
|
|
187
|
+
>
|
|
188
|
+
<span className="rnav-page-label">{p.label}</span>
|
|
189
|
+
<ScoreRing
|
|
190
|
+
value={p.score}
|
|
191
|
+
grade={p.grade}
|
|
192
|
+
size="sm"
|
|
193
|
+
label={p.score == null ? copy.unscored : copy.score}
|
|
194
|
+
>
|
|
195
|
+
—
|
|
196
|
+
</ScoreRing>
|
|
197
|
+
</a>
|
|
198
|
+
</li>
|
|
199
|
+
))}
|
|
200
|
+
</ul>
|
|
201
|
+
{account && (
|
|
202
|
+
<div className="rnav-foot">
|
|
203
|
+
<span className="rnav-who">
|
|
204
|
+
<span className="type type-fixed ts-text-xs-regular rnav-who-label">
|
|
205
|
+
{account.label}
|
|
206
|
+
</span>
|
|
207
|
+
<span className="type type-fixed ts-text-sm-regular rnav-who-name">
|
|
208
|
+
{account.who}
|
|
209
|
+
</span>
|
|
210
|
+
</span>
|
|
211
|
+
<button
|
|
212
|
+
type="button"
|
|
213
|
+
className="type type-fixed ts-text-sm-medium rnav-signout"
|
|
214
|
+
disabled={account.busy}
|
|
215
|
+
onClick={account.onSignOut}
|
|
216
|
+
>
|
|
217
|
+
{account.signOut}
|
|
218
|
+
</button>
|
|
219
|
+
</div>
|
|
220
|
+
)}
|
|
221
|
+
</div>
|
|
222
|
+
</div>
|
|
223
|
+
);
|
|
224
|
+
}
|