rift-ds 1.32.0 → 1.34.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 +4 -4
- package/behaviors/chat-card.css +11 -6
- package/behaviors/clipboard.d.ts +7 -0
- package/behaviors/clipboard.js +35 -0
- package/behaviors/headingSlug.d.ts +8 -0
- package/behaviors/headingSlug.js +4 -0
- package/behaviors/shell.css +64 -0
- package/behaviors/syncedChoice.d.ts +2 -0
- package/behaviors/syncedChoice.js +48 -0
- package/behaviors/useLayer.d.ts +15 -2
- package/behaviors/useLayer.js +3 -2
- package/bin/templates/blocks/app/guide/PageFeedback.tsx +55 -0
- package/bin/templates/blocks/app/guide/page.module.css +94 -0
- package/bin/templates/blocks/app/guide/page.tsx +168 -0
- package/bin/templates/blocks/components/blocks/AppShell.module.css +3 -1
- package/bin/templates/blocks/components/blocks/AppShell.tsx +8 -0
- package/bin/templates/blocks/components/blocks/DocsShell.module.css +18 -0
- package/bin/templates/blocks/components/blocks/DocsShell.tsx +179 -0
- package/bin/templates/blocks/registry.json +13 -0
- package/chat/AssistantTurn.d.ts +2 -0
- package/chat/AssistantTurn.js +18 -7
- package/chat/ChatProvider.js +14 -0
- package/chat/ChatWidget.css +10 -0
- package/chat/ChatWidget.d.ts +7 -3
- package/chat/ChatWidget.js +6 -3
- package/chat/agentState.d.ts +2 -1
- package/chat/agentState.js +4 -1
- package/chat/awaiting.d.ts +19 -0
- package/chat/awaiting.js +21 -0
- package/chat/context.d.ts +4 -0
- package/chat/index.d.ts +1 -0
- package/chat/index.js +3 -1
- package/chat/server.d.ts +8 -3
- package/chat/server.js +1 -1
- package/code/highlight.d.ts +4 -0
- package/code/highlight.js +34 -0
- package/code/index.d.ts +16 -0
- package/code/index.js +23 -0
- package/components/ActionCard/ActionCard.css +3 -3
- package/components/AgentStatus/AgentStatus.css +114 -22
- package/components/AgentStatus/AgentStatus.d.ts +10 -7
- package/components/AgentStatus/AgentStatus.js +10 -0
- package/components/AiButton/AiButton.d.ts +3 -3
- package/components/AnchorNav/AnchorNav.d.ts +29 -3
- package/components/AnchorNav/AnchorNav.js +69 -5
- package/components/AppLayout/AppLayout.css +8 -4
- package/components/AppLayout/AppLayout.d.ts +13 -3
- package/components/AppLayout/AppLayout.js +2 -0
- package/components/ArtifactPanel/ArtifactPanel.css +46 -0
- package/components/ArtifactPanel/ArtifactPanel.d.ts +14 -4
- package/components/ArtifactPanel/ArtifactPanel.js +8 -5
- package/components/BackToTop/BackToTop.css +28 -0
- package/components/BackToTop/BackToTop.d.ts +28 -0
- package/components/BackToTop/BackToTop.js +47 -0
- package/components/BentoTile/BentoTile.css +3 -0
- package/components/CodeBlock/CodeBlock.css +63 -24
- package/components/CodeBlock/CodeBlock.d.ts +62 -6
- package/components/CodeBlock/CodeBlock.js +90 -48
- package/components/Composer/Composer.css +14 -9
- package/components/Composer/Composer.d.ts +10 -8
- package/components/Composer/Composer.js +2 -1
- package/components/CopyButton/CopyButton.d.ts +42 -0
- package/components/CopyButton/CopyButton.js +72 -0
- package/components/DescriptionList/DescriptionListCopy.d.ts +2 -2
- package/components/DescriptionList/DescriptionListCopy.js +7 -35
- package/components/Figure/Figure.css +26 -0
- package/components/Figure/Figure.d.ts +10 -1
- package/components/Figure/Figure.js +15 -3
- package/components/Heading/Heading.css +43 -0
- package/components/Heading/Heading.d.ts +14 -3
- package/components/Heading/Heading.js +22 -4
- package/components/HoverCard/HoverCard.js +1 -0
- package/components/Link/Link.css +38 -0
- package/components/Link/Link.d.ts +3 -3
- package/components/Link/Link.js +1 -1
- package/components/Menubar/Menubar.css +82 -0
- package/components/Menubar/Menubar.d.ts +40 -0
- package/components/Menubar/Menubar.js +97 -0
- package/components/MessageCard/MessageCard.css +1 -1
- package/components/NavList/NavList.css +197 -0
- package/components/NavList/NavList.d.ts +54 -6
- package/components/NavList/NavList.js +136 -8
- package/components/Pagination/Pagination.css +80 -0
- package/components/Pagination/Pagination.d.ts +29 -3
- package/components/Pagination/Pagination.js +49 -5
- package/components/Rating/Rating.css +26 -0
- package/components/Rating/Rating.d.ts +18 -5
- package/components/Rating/Rating.js +16 -7
- package/components/SectionTitle/SectionTitle.css +36 -0
- package/components/SectionTitle/SectionTitle.d.ts +10 -1
- package/components/SectionTitle/SectionTitle.js +7 -2
- package/components/ShaderScene/ShaderScene.d.ts +2 -1
- package/components/ShaderScene/ShaderScene.js +20 -2
- package/components/SiteFooter/SiteFooter.css +157 -0
- package/components/SiteFooter/SiteFooter.d.ts +53 -0
- package/components/SiteFooter/SiteFooter.js +61 -0
- package/components/SiteHeader/SiteHeader.css +106 -4
- package/components/SiteHeader/SiteHeader.d.ts +25 -2
- package/components/SiteHeader/SiteHeader.js +46 -8
- package/components/SiteLayout/SiteLayout.css +361 -0
- package/components/SiteLayout/SiteLayout.d.ts +103 -0
- package/components/SiteLayout/SiteLayout.js +68 -0
- package/components/SourceTrail/SourceTrail.css +1 -1
- package/components/Table/Table.css +14 -0
- package/components/Table/Table.d.ts +2 -0
- package/components/Table/Table.js +1 -1
- package/components/ToolCall/ToolCall.css +2 -2
- package/components/Tooltip/Tooltip.js +1 -0
- package/components/UsageCard/UsageCard.css +4 -3
- package/components/keyboard-patterns.json.d.ts +57 -0
- package/components/keyboard-patterns.json.js +1 -1
- package/components/registry.json +89 -19
- package/components/registry.json.d.ts +89 -19
- package/components/registry.json.js +1 -1
- package/index.d.ts +5 -0
- package/index.js +14 -1
- package/package.json +14 -2
- package/tokens/breakpoints.js +3 -3
- package/tokens/registry.json +5 -0
- package/tokens/registry.json.d.ts +5 -0
- package/tokens/registry.json.js +1 -1
- package/tokens/tokens-dark.css +12 -0
- package/tokens/tokens-light.css +12 -0
- package/tokens/values.json.js +1 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useRef } from "react";
|
|
4
|
+
import { DropdownMenu } from "../DropdownMenu/DropdownMenu.js";
|
|
5
|
+
import { logicalArrowKey } from "../../behaviors/direction.js";
|
|
6
|
+
import "./Menubar.css";
|
|
7
|
+
function Menubar({
|
|
8
|
+
menus,
|
|
9
|
+
label = "Menu bar",
|
|
10
|
+
size = "default",
|
|
11
|
+
keyLabels,
|
|
12
|
+
className = "",
|
|
13
|
+
ref,
|
|
14
|
+
...rest
|
|
15
|
+
}) {
|
|
16
|
+
const [openIndex, setOpenIndex] = useState(null);
|
|
17
|
+
const [focusIndex, setFocusIndex] = useState(0);
|
|
18
|
+
const triggers = useRef([]);
|
|
19
|
+
const baseClass = "ds-menubar";
|
|
20
|
+
const classes = [baseClass, size === "compact" ? `${baseClass}--compact` : "", className].filter(Boolean).join(" ");
|
|
21
|
+
const enabled = menus.map((menu, i) => menu.disabled ? -1 : i).filter((i) => i >= 0);
|
|
22
|
+
const move = (to) => {
|
|
23
|
+
setFocusIndex(to);
|
|
24
|
+
triggers.current[to]?.focus();
|
|
25
|
+
if (openIndex !== null) setOpenIndex(to);
|
|
26
|
+
};
|
|
27
|
+
const step = (from, by) => {
|
|
28
|
+
const at = enabled.indexOf(from);
|
|
29
|
+
return enabled[(at + by + enabled.length) % enabled.length];
|
|
30
|
+
};
|
|
31
|
+
const handleKeyDown = (index) => (event) => {
|
|
32
|
+
switch (logicalArrowKey(event.key, event.currentTarget)) {
|
|
33
|
+
case "ArrowRight":
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
move(step(index, 1));
|
|
36
|
+
break;
|
|
37
|
+
case "ArrowLeft":
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
move(step(index, -1));
|
|
40
|
+
break;
|
|
41
|
+
case "Home":
|
|
42
|
+
if (openIndex === null) {
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
move(enabled[0]);
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
case "End":
|
|
48
|
+
if (openIndex === null) {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
move(enabled[enabled.length - 1]);
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
return /* @__PURE__ */ jsx("div", { "aria-label": label, ...rest, ref, className: classes, role: "menubar", children: menus.map((menu, index) => /* @__PURE__ */ jsx(
|
|
56
|
+
DropdownMenu,
|
|
57
|
+
{
|
|
58
|
+
className: `${baseClass}__menu`,
|
|
59
|
+
items: menu.items,
|
|
60
|
+
size,
|
|
61
|
+
keyLabels,
|
|
62
|
+
open: openIndex === index,
|
|
63
|
+
onOpenChange: (open) => {
|
|
64
|
+
if (menu.disabled) return;
|
|
65
|
+
setOpenIndex((current) => open ? index : current === index ? null : current);
|
|
66
|
+
if (open) setFocusIndex(index);
|
|
67
|
+
},
|
|
68
|
+
trigger: /* @__PURE__ */ jsx(
|
|
69
|
+
"button",
|
|
70
|
+
{
|
|
71
|
+
ref: (node) => {
|
|
72
|
+
triggers.current[index] = node;
|
|
73
|
+
},
|
|
74
|
+
type: "button",
|
|
75
|
+
role: "menuitem",
|
|
76
|
+
className: `${baseClass}__trigger`,
|
|
77
|
+
tabIndex: index === focusIndex ? 0 : -1,
|
|
78
|
+
"aria-disabled": menu.disabled || void 0,
|
|
79
|
+
onKeyDown: handleKeyDown(index),
|
|
80
|
+
onFocus: () => setFocusIndex(index),
|
|
81
|
+
onMouseEnter: () => {
|
|
82
|
+
if (openIndex !== null && openIndex !== index && !menu.disabled) {
|
|
83
|
+
setOpenIndex(index);
|
|
84
|
+
setFocusIndex(index);
|
|
85
|
+
triggers.current[index]?.focus();
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
children: menu.label
|
|
89
|
+
}
|
|
90
|
+
)
|
|
91
|
+
},
|
|
92
|
+
menu.id ?? menu.label
|
|
93
|
+
)) });
|
|
94
|
+
}
|
|
95
|
+
export {
|
|
96
|
+
Menubar
|
|
97
|
+
};
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
padding: var(--padding-400) var(--ds-chat-card-inset) var(--padding-200);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
/* Without media the body opens the card, at the chat cards'
|
|
89
|
+
/* Without media the body opens the card, at the chat cards' edge. */
|
|
90
90
|
.ds-message-card__body:first-child {
|
|
91
91
|
padding-top: var(--ds-chat-card-edge);
|
|
92
92
|
}
|
|
@@ -8,6 +8,14 @@
|
|
|
8
8
|
============================================ */
|
|
9
9
|
|
|
10
10
|
.ds-nav-list {
|
|
11
|
+
/* How far a row's text sits in from the row's own edge (the rows are
|
|
12
|
+
compact tertiary Buttons, the headings share their inset). A host that
|
|
13
|
+
lines the list's text up with something above it, a header's brand,
|
|
14
|
+
hangs the list out by this much, so the fills sit in the gutter and the
|
|
15
|
+
words sit on the line (SiteLayout's sidebar does). Compact rows inset
|
|
16
|
+
their text --padding-300; default rows (a default Button) --padding-500,
|
|
17
|
+
set below. */
|
|
18
|
+
--ds-nav-list-text-inset: var(--padding-300);
|
|
11
19
|
display: flex;
|
|
12
20
|
flex-direction: column;
|
|
13
21
|
gap: var(--gap-050);
|
|
@@ -153,3 +161,192 @@
|
|
|
153
161
|
.ds-nav-list__item > .ds-nav-list__sublist {
|
|
154
162
|
margin-top: var(--gap-050);
|
|
155
163
|
}
|
|
164
|
+
|
|
165
|
+
/* ============================================
|
|
166
|
+
COMPACT
|
|
167
|
+
Every row on the 32px compact control height, for a
|
|
168
|
+
long sidebar: the 40px reservation and toggle step down
|
|
169
|
+
to match, so a hundred rows read as one quiet column.
|
|
170
|
+
============================================ */
|
|
171
|
+
|
|
172
|
+
/* Default size: the top-level rows are default Buttons, so their text sits
|
|
173
|
+
--padding-500 in; the hang and the section headings follow it, so the
|
|
174
|
+
headings sit on the rows' leading line at either size. */
|
|
175
|
+
.ds-nav-list:not(.ds-nav-list--compact) {
|
|
176
|
+
--ds-nav-list-text-inset: var(--padding-500);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.ds-nav-list:not(.ds-nav-list--compact) .ds-nav-list__heading {
|
|
180
|
+
padding-inline-start: var(--padding-500);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.ds-nav-list--compact .ds-nav-list__item {
|
|
184
|
+
min-height: var(--control-height-compact);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.ds-nav-list--compact .ds-nav-list__toggle {
|
|
188
|
+
width: var(--control-height-compact);
|
|
189
|
+
height: var(--control-height-compact);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.ds-nav-list--compact .ds-nav-list__sublist {
|
|
193
|
+
padding-inline-start: var(--padding-400);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.ds-nav-list__badge {
|
|
197
|
+
margin-inline-start: auto;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/* ============================================
|
|
201
|
+
SECTIONS
|
|
202
|
+
A heading over its rows: the rails' group heading
|
|
203
|
+
(caption face, tertiary text, mixed case), seated on
|
|
204
|
+
the rows' leading line. A collapsible heading is a
|
|
205
|
+
full-width quiet button with the chevron at its end.
|
|
206
|
+
============================================ */
|
|
207
|
+
|
|
208
|
+
.ds-nav-list__section {
|
|
209
|
+
display: flex;
|
|
210
|
+
flex-direction: column;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.ds-nav-list__section + .ds-nav-list__section,
|
|
214
|
+
.ds-nav-list__item + .ds-nav-list__section {
|
|
215
|
+
margin-block-start: var(--gap-500);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.ds-nav-list__heading {
|
|
219
|
+
display: flex;
|
|
220
|
+
align-items: center;
|
|
221
|
+
gap: var(--gap-200);
|
|
222
|
+
box-sizing: border-box;
|
|
223
|
+
min-height: var(--control-height-compact);
|
|
224
|
+
padding-inline: var(--padding-300);
|
|
225
|
+
font-family: var(--font-paragraph-sm-family);
|
|
226
|
+
font-size: var(--font-paragraph-sm-size);
|
|
227
|
+
line-height: var(--font-paragraph-sm-line-height);
|
|
228
|
+
color: var(--color-text-tertiary);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.ds-nav-list--compact .ds-nav-list__heading {
|
|
232
|
+
padding-inline: var(--padding-300);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.ds-nav-list__heading--toggle {
|
|
236
|
+
width: 100%;
|
|
237
|
+
margin: 0;
|
|
238
|
+
padding-inline-end: var(--padding-200);
|
|
239
|
+
border: none;
|
|
240
|
+
border-radius: var(--radius-pill);
|
|
241
|
+
background: none;
|
|
242
|
+
text-align: start;
|
|
243
|
+
cursor: pointer;
|
|
244
|
+
transition: background-color var(--motion-duration-base) var(--motion-ease-standard), color var(--motion-duration-base) var(--motion-ease-standard);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.ds-nav-list__heading--toggle:hover {
|
|
248
|
+
background-color: var(--color-action-passive-bg-hover);
|
|
249
|
+
color: var(--color-text-secondary);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.ds-nav-list__heading--toggle:focus-visible {
|
|
253
|
+
outline: 2px solid var(--color-action-primary-bg);
|
|
254
|
+
outline-offset: -2px;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
.ds-nav-list__heading-text {
|
|
258
|
+
flex: 1 1 auto;
|
|
259
|
+
min-width: 0;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
.ds-nav-list__heading--toggle[aria-expanded='true'] .ds-nav-list__chevron {
|
|
263
|
+
transform: rotate(180deg);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.ds-nav-list__section-list {
|
|
267
|
+
display: flex;
|
|
268
|
+
flex-direction: column;
|
|
269
|
+
gap: var(--gap-050);
|
|
270
|
+
overflow: hidden;
|
|
271
|
+
min-height: 0;
|
|
272
|
+
margin: 0;
|
|
273
|
+
padding: 0;
|
|
274
|
+
list-style: none;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/* ============================================
|
|
278
|
+
SCROLLABLE
|
|
279
|
+
The list as its own scroll area: it takes its parent's
|
|
280
|
+
height, keeps its scroll to itself at both ends, and
|
|
281
|
+
keeps a still gutter so rows do not shift when the
|
|
282
|
+
scrollbar comes and goes.
|
|
283
|
+
============================================ */
|
|
284
|
+
|
|
285
|
+
.ds-nav-list--scrollable {
|
|
286
|
+
/* How far the content fades in or out at an end with more to scroll. */
|
|
287
|
+
--ds-nav-list-fade: var(--gap-1000);
|
|
288
|
+
--ds-nav-list-fade-start: 0px;
|
|
289
|
+
--ds-nav-list-fade-end: 0px;
|
|
290
|
+
flex-wrap: nowrap;
|
|
291
|
+
height: 100%;
|
|
292
|
+
min-height: 0;
|
|
293
|
+
overflow-y: auto;
|
|
294
|
+
overscroll-behavior: contain;
|
|
295
|
+
/* Room at both ends for the fade, a hook so a host can line the first
|
|
296
|
+
row up with something beside it (SiteLayout's sidebar pulls the list up
|
|
297
|
+
by it, so the first row starts level with the page's first line). */
|
|
298
|
+
--ds-nav-list-block-inset: var(--padding-200);
|
|
299
|
+
padding-block: var(--ds-nav-list-block-inset);
|
|
300
|
+
/* The scrollbar stays out of sight until the list scrolls. */
|
|
301
|
+
scrollbar-width: none;
|
|
302
|
+
/* The ends fade only when there is more past them, so a list at its top
|
|
303
|
+
shows its first row crisp. ds-allow(color): mask alpha keywords
|
|
304
|
+
(black/transparent), not palette colours */
|
|
305
|
+
-webkit-mask-image: linear-gradient(
|
|
306
|
+
to bottom,
|
|
307
|
+
transparent,
|
|
308
|
+
black var(--ds-nav-list-fade-start),
|
|
309
|
+
black calc(100% - var(--ds-nav-list-fade-end)),
|
|
310
|
+
transparent
|
|
311
|
+
);
|
|
312
|
+
mask-image: linear-gradient(
|
|
313
|
+
to bottom,
|
|
314
|
+
transparent,
|
|
315
|
+
black var(--ds-nav-list-fade-start),
|
|
316
|
+
black calc(100% - var(--ds-nav-list-fade-end)),
|
|
317
|
+
transparent
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/* A fixed-height column scrolls its rows rather than squeezing them: a
|
|
322
|
+
flex child would otherwise shrink to fit and the rows would overlap. */
|
|
323
|
+
.ds-nav-list--scrollable > * {
|
|
324
|
+
flex-shrink: 0;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
.ds-nav-list--scrollable[data-fade-start] {
|
|
328
|
+
--ds-nav-list-fade-start: var(--ds-nav-list-fade);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.ds-nav-list--scrollable[data-fade-end] {
|
|
332
|
+
--ds-nav-list-fade-end: var(--ds-nav-list-fade);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
.ds-nav-list--scrollable::-webkit-scrollbar {
|
|
336
|
+
width: 0;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/* While it scrolls: a thin thumb on no track, gone again once it settles. */
|
|
340
|
+
.ds-nav-list--scrollable[data-scrolling] {
|
|
341
|
+
scrollbar-width: thin;
|
|
342
|
+
scrollbar-color: var(--color-bg-container-border) transparent;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
.ds-nav-list--scrollable[data-scrolling]::-webkit-scrollbar {
|
|
346
|
+
width: var(--padding-150);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
.ds-nav-list--scrollable[data-scrolling]::-webkit-scrollbar-thumb {
|
|
350
|
+
border-radius: var(--radius-pill);
|
|
351
|
+
background: var(--color-bg-container-border);
|
|
352
|
+
}
|
|
@@ -12,6 +12,7 @@ export interface NavListItem {
|
|
|
12
12
|
/**
|
|
13
13
|
* When false, an item with children renders no toggle and its children stay
|
|
14
14
|
* visible — a permanent group rather than a collapsible section.
|
|
15
|
+
* @default true
|
|
15
16
|
*/
|
|
16
17
|
collapsible?: boolean;
|
|
17
18
|
/**
|
|
@@ -20,26 +21,73 @@ export interface NavListItem {
|
|
|
20
21
|
* stay current on their child routes.
|
|
21
22
|
*/
|
|
22
23
|
current?: boolean;
|
|
24
|
+
/** A short tag after the label, such as "New" or "Beta", drawn as a neutral Badge. */
|
|
25
|
+
badge?: string;
|
|
23
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* A titled section of rows: a heading over its items, the way a long
|
|
29
|
+
* documentation sidebar groups its pages. Sections sit only at the top
|
|
30
|
+
* level; their items nest like any others.
|
|
31
|
+
*/
|
|
32
|
+
export interface NavListSection {
|
|
33
|
+
/** Marks the entry as a section rather than a row. */
|
|
34
|
+
type: 'section';
|
|
35
|
+
/** The section's heading. */
|
|
36
|
+
label: string;
|
|
37
|
+
/** The section's rows. */
|
|
38
|
+
items: NavListItem[];
|
|
39
|
+
/**
|
|
40
|
+
* Stable identity for its expansion state. Defaults to the label. In
|
|
41
|
+
* `expandedIds`, `defaultExpandedIds` and `onExpandedChange` a section
|
|
42
|
+
* appears as `section:<id>`, so its id never collides with a row's.
|
|
43
|
+
*/
|
|
44
|
+
id?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Let the reader fold the section under its heading. Unlike a row with
|
|
47
|
+
* `items`, which folds unless told not to, a section is a plain label
|
|
48
|
+
* unless told to fold.
|
|
49
|
+
* @default false
|
|
50
|
+
*/
|
|
51
|
+
collapsible?: boolean;
|
|
52
|
+
}
|
|
53
|
+
/** A top-level entry: a row, or a section of rows. */
|
|
54
|
+
export type NavListEntry = NavListItem | NavListSection;
|
|
24
55
|
/** Props owned by NavList itself — everything else falls through to the list element. */
|
|
25
56
|
type NavListOwnProps = {
|
|
26
|
-
/** Navigation tree to render. */
|
|
27
|
-
items:
|
|
57
|
+
/** Navigation tree to render: rows, and at the top level, sections of rows. */
|
|
58
|
+
items: NavListEntry[];
|
|
59
|
+
/**
|
|
60
|
+
* Row density. `default` is the drawer's 40px top row; `compact` sets
|
|
61
|
+
* every row on the 32px compact control height, for a long sidebar of
|
|
62
|
+
* pages (a documentation site's hundred entries).
|
|
63
|
+
*/
|
|
64
|
+
size?: 'default' | 'compact';
|
|
65
|
+
/**
|
|
66
|
+
* Make the list its own scroll area: it fills the height its parent
|
|
67
|
+
* gives it, scrolls inside without carrying the page along at its ends,
|
|
68
|
+
* and brings the current row into view when it first renders. Put it in
|
|
69
|
+
* a column with a fixed or sticky height.
|
|
70
|
+
*/
|
|
71
|
+
scrollable?: boolean;
|
|
28
72
|
/** href of the current page — the exactly matching row gets `aria-current="page"` and the active treatment. */
|
|
29
73
|
currentHref?: string;
|
|
30
74
|
/** Controlled list of expanded item ids. */
|
|
31
75
|
expandedIds?: string[];
|
|
32
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Initially expanded item ids (uncontrolled). The branch and the
|
|
78
|
+
* collapsible section that hold the current page start open as well, so a
|
|
79
|
+
* reader landing deep in a long tree sees where they are.
|
|
80
|
+
*/
|
|
33
81
|
defaultExpandedIds?: string[];
|
|
34
82
|
/** Fires with the full new list of expanded ids whenever a toggle is pressed, in both controlled and uncontrolled modes. */
|
|
35
83
|
onExpandedChange?: (expandedIds: string[]) => void;
|
|
36
|
-
/** Allow several
|
|
84
|
+
/** Allow several branches expanded at once. Default false: expanding one collapses its siblings, never the section or the rows it sits in. */
|
|
37
85
|
multiple?: boolean;
|
|
38
86
|
/** Fires when any link is clicked, alongside native navigation — e.g. to close the drawer that contains the list. */
|
|
39
87
|
onNavigate?: (item: NavListItem, event: React.MouseEvent<HTMLElement>) => void;
|
|
40
|
-
/** Accessible name of a collapsed section's
|
|
88
|
+
/** Accessible name of a collapsed row's or section's toggle, given its label. Defaults to "Expand <label>". */
|
|
41
89
|
expandLabel?: (label: string) => string;
|
|
42
|
-
/** Accessible name of an expanded section's
|
|
90
|
+
/** Accessible name of an expanded row's or section's toggle, given its label. Defaults to "Collapse <label>". */
|
|
43
91
|
collapseLabel?: (label: string) => string;
|
|
44
92
|
/**
|
|
45
93
|
* The component its links render with, such as Next.js's `Link`, so they
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import React, { useId, useState } from "react";
|
|
3
|
+
import React, { useId, useState, useRef, useEffect } from "react";
|
|
4
4
|
import { Button } from "../Button/Button.js";
|
|
5
|
+
import { Badge } from "../Badge/Badge.js";
|
|
6
|
+
import { MOTION_SCROLL_SETTLE_MS } from "../../tokens/motion.js";
|
|
5
7
|
import "./NavList.css";
|
|
6
8
|
import "../../fonts/material-symbols.css";
|
|
9
|
+
const isSection = (entry) => entry.type === "section";
|
|
7
10
|
const MAX_DEPTH = 3;
|
|
8
11
|
const NavList = React.forwardRef(
|
|
9
12
|
({
|
|
10
13
|
items,
|
|
14
|
+
size = "default",
|
|
15
|
+
scrollable = false,
|
|
11
16
|
currentHref,
|
|
12
17
|
expandedIds,
|
|
13
18
|
defaultExpandedIds,
|
|
@@ -22,13 +27,90 @@ const NavList = React.forwardRef(
|
|
|
22
27
|
}, ref) => {
|
|
23
28
|
const baseClass = "ds-nav-list";
|
|
24
29
|
const uid = useId();
|
|
25
|
-
const [internalExpanded, setInternalExpanded] = useState(
|
|
26
|
-
defaultExpandedIds ?? []
|
|
27
|
-
);
|
|
28
|
-
const expanded = expandedIds ?? internalExpanded;
|
|
29
30
|
const itemId = (item) => item.id ?? item.href;
|
|
31
|
+
const sectionId = (section) => `section:${section.id ?? section.label}`;
|
|
32
|
+
const [internalExpanded, setInternalExpanded] = useState(() => {
|
|
33
|
+
const open = new Set(defaultExpandedIds ?? []);
|
|
34
|
+
const holdsCurrent = (item) => (item.current ?? (currentHref !== void 0 && item.href === currentHref)) || Boolean(item.items?.some(holdsCurrent));
|
|
35
|
+
const walk = (list) => {
|
|
36
|
+
for (const item of list) {
|
|
37
|
+
if (item.items?.some(holdsCurrent)) open.add(itemId(item));
|
|
38
|
+
if (item.items) walk(item.items);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
for (const entry of items) {
|
|
42
|
+
if (isSection(entry)) {
|
|
43
|
+
if (entry.collapsible && entry.items.some(holdsCurrent)) open.add(sectionId(entry));
|
|
44
|
+
walk(entry.items);
|
|
45
|
+
} else {
|
|
46
|
+
walk([entry]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return [...open];
|
|
50
|
+
});
|
|
51
|
+
const expanded = expandedIds ?? internalExpanded;
|
|
52
|
+
const rootRef = useRef(null);
|
|
53
|
+
const setRootRef = (node) => {
|
|
54
|
+
rootRef.current = node;
|
|
55
|
+
if (typeof ref === "function") ref(node);
|
|
56
|
+
else if (ref) ref.current = node;
|
|
57
|
+
};
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
const root = rootRef.current;
|
|
60
|
+
if (!scrollable || !root) return;
|
|
61
|
+
let settle;
|
|
62
|
+
const edges = () => {
|
|
63
|
+
const max = root.scrollHeight - root.clientHeight;
|
|
64
|
+
root.toggleAttribute("data-fade-start", root.scrollTop > 1);
|
|
65
|
+
root.toggleAttribute("data-fade-end", root.scrollTop < max - 1);
|
|
66
|
+
};
|
|
67
|
+
const onScroll = () => {
|
|
68
|
+
edges();
|
|
69
|
+
root.setAttribute("data-scrolling", "");
|
|
70
|
+
clearTimeout(settle);
|
|
71
|
+
settle = setTimeout(() => root.removeAttribute("data-scrolling"), MOTION_SCROLL_SETTLE_MS);
|
|
72
|
+
};
|
|
73
|
+
edges();
|
|
74
|
+
root.addEventListener("scroll", onScroll, { passive: true });
|
|
75
|
+
const resize = new ResizeObserver(edges);
|
|
76
|
+
resize.observe(root);
|
|
77
|
+
return () => {
|
|
78
|
+
clearTimeout(settle);
|
|
79
|
+
root.removeEventListener("scroll", onScroll);
|
|
80
|
+
resize.disconnect();
|
|
81
|
+
};
|
|
82
|
+
}, [scrollable]);
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
const root = rootRef.current;
|
|
85
|
+
if (!scrollable || !root) return;
|
|
86
|
+
const row = root.querySelector('[aria-current="page"]');
|
|
87
|
+
if (!row) return;
|
|
88
|
+
const top = row.getBoundingClientRect().top - root.getBoundingClientRect().top;
|
|
89
|
+
if (top < 0 || top > root.clientHeight - row.offsetHeight) {
|
|
90
|
+
root.scrollTop += top - root.clientHeight / 3;
|
|
91
|
+
}
|
|
92
|
+
}, []);
|
|
93
|
+
const ancestorsOf = /* @__PURE__ */ new Map();
|
|
94
|
+
const mapAncestors = (list, chain) => {
|
|
95
|
+
for (const item of list) {
|
|
96
|
+
if (!item.items) continue;
|
|
97
|
+
ancestorsOf.set(itemId(item), chain);
|
|
98
|
+
mapAncestors(item.items, [...chain, itemId(item)]);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
for (const entry of items) {
|
|
102
|
+
if (isSection(entry)) {
|
|
103
|
+
ancestorsOf.set(sectionId(entry), []);
|
|
104
|
+
mapAncestors(entry.items, [sectionId(entry)]);
|
|
105
|
+
} else {
|
|
106
|
+
mapAncestors([entry], []);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
30
109
|
const toggle = (id) => {
|
|
31
|
-
const
|
|
110
|
+
const parentOf = (entry) => (ancestorsOf.get(entry) ?? []).join("\0");
|
|
111
|
+
const isSection2 = (entry) => entry.startsWith("section:");
|
|
112
|
+
const sibling = (entry) => parentOf(entry) === parentOf(id) && isSection2(entry) === isSection2(id);
|
|
113
|
+
const next = expanded.includes(id) ? expanded.filter((entry) => entry !== id) : multiple ? [...expanded, id] : [...expanded.filter((entry) => !sibling(entry)), id];
|
|
32
114
|
if (expandedIds === void 0) setInternalExpanded(next);
|
|
33
115
|
onExpandedChange?.(next);
|
|
34
116
|
};
|
|
@@ -43,8 +125,9 @@ const NavList = React.forwardRef(
|
|
|
43
125
|
Button,
|
|
44
126
|
{
|
|
45
127
|
variant: "tertiary",
|
|
46
|
-
size: level === 1 ? "default" : "compact",
|
|
128
|
+
size: level === 1 && size === "default" ? "default" : "compact",
|
|
47
129
|
label: item.label,
|
|
130
|
+
iconRight: item.badge ? /* @__PURE__ */ jsx(Badge, { className: `${baseClass}__badge`, label: item.badge, variant: "neutral" }) : void 0,
|
|
48
131
|
href: item.href,
|
|
49
132
|
linkComponent,
|
|
50
133
|
ariaCurrent: isCurrent,
|
|
@@ -95,7 +178,52 @@ const NavList = React.forwardRef(
|
|
|
95
178
|
)
|
|
96
179
|
] }, id);
|
|
97
180
|
});
|
|
98
|
-
|
|
181
|
+
const renderSection = (section) => {
|
|
182
|
+
const id = sectionId(section);
|
|
183
|
+
const panelId = `${uid}-${id}`;
|
|
184
|
+
const isOpen = !section.collapsible || expanded.includes(id);
|
|
185
|
+
return /* @__PURE__ */ jsxs("li", { className: `${baseClass}__section`, children: [
|
|
186
|
+
section.collapsible ? /* @__PURE__ */ jsxs(
|
|
187
|
+
"button",
|
|
188
|
+
{
|
|
189
|
+
type: "button",
|
|
190
|
+
className: `${baseClass}__heading ${baseClass}__heading--toggle`,
|
|
191
|
+
"aria-expanded": isOpen,
|
|
192
|
+
"aria-controls": panelId,
|
|
193
|
+
"aria-label": isOpen ? collapseLabel(section.label) : expandLabel(section.label),
|
|
194
|
+
onClick: () => toggle(id),
|
|
195
|
+
children: [
|
|
196
|
+
/* @__PURE__ */ jsx("span", { className: `${baseClass}__heading-text`, children: section.label }),
|
|
197
|
+
/* @__PURE__ */ jsx("span", { className: `${baseClass}__chevron material-symbols-rounded`, "aria-hidden": "true", children: "expand_more" })
|
|
198
|
+
]
|
|
199
|
+
}
|
|
200
|
+
) : /* @__PURE__ */ jsx("span", { className: `${baseClass}__heading`, id: `${panelId}-heading`, children: section.label }),
|
|
201
|
+
/* @__PURE__ */ jsx(
|
|
202
|
+
"div",
|
|
203
|
+
{
|
|
204
|
+
id: panelId,
|
|
205
|
+
className: `${baseClass}__panel ${isOpen ? `${baseClass}__panel--open` : ""}`,
|
|
206
|
+
inert: !isOpen,
|
|
207
|
+
children: /* @__PURE__ */ jsx(
|
|
208
|
+
"ul",
|
|
209
|
+
{
|
|
210
|
+
className: `${baseClass}__section-list`,
|
|
211
|
+
"aria-labelledby": section.collapsible ? void 0 : `${panelId}-heading`,
|
|
212
|
+
"aria-label": section.collapsible ? section.label : void 0,
|
|
213
|
+
children: renderItems(1, section.items)
|
|
214
|
+
}
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
)
|
|
218
|
+
] }, id);
|
|
219
|
+
};
|
|
220
|
+
const classes = [
|
|
221
|
+
baseClass,
|
|
222
|
+
size === "compact" ? `${baseClass}--compact` : "",
|
|
223
|
+
scrollable ? `${baseClass}--scrollable` : "",
|
|
224
|
+
className
|
|
225
|
+
].filter(Boolean).join(" ");
|
|
226
|
+
return /* @__PURE__ */ jsx("ul", { ...rest, ref: setRootRef, className: classes, children: items.map((entry) => isSection(entry) ? renderSection(entry) : renderItems(1, [entry])) });
|
|
99
227
|
}
|
|
100
228
|
);
|
|
101
229
|
NavList.displayName = "NavList";
|
|
@@ -126,3 +126,83 @@
|
|
|
126
126
|
color: var(--color-text-secondary);
|
|
127
127
|
white-space: nowrap;
|
|
128
128
|
}
|
|
129
|
+
|
|
130
|
+
/* ============================================
|
|
131
|
+
ADJACENT (variant="adjacent")
|
|
132
|
+
The page before and after this one in a sequence, as two
|
|
133
|
+
cards on the container family's surface: an eyebrow with
|
|
134
|
+
its chevron over the page's title. Previous holds the start
|
|
135
|
+
edge and next the end, each half the row, so a missing side
|
|
136
|
+
leaves its half empty rather than stretching the other.
|
|
137
|
+
============================================ */
|
|
138
|
+
|
|
139
|
+
.ds-pagination--adjacent {
|
|
140
|
+
display: grid;
|
|
141
|
+
grid-template-columns: 1fr 1fr;
|
|
142
|
+
gap: var(--gap-400);
|
|
143
|
+
width: 100%;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.ds-pagination__adjacent {
|
|
147
|
+
display: flex;
|
|
148
|
+
flex-direction: column;
|
|
149
|
+
gap: var(--gap-100);
|
|
150
|
+
min-width: 0;
|
|
151
|
+
padding: var(--padding-400) var(--padding-500);
|
|
152
|
+
border: var(--border-025) solid var(--color-bg-container-border);
|
|
153
|
+
border-radius: var(--radius-300);
|
|
154
|
+
background-color: var(--color-bg-container-primary);
|
|
155
|
+
color: var(--color-text-primary);
|
|
156
|
+
text-decoration: none;
|
|
157
|
+
transition: background-color var(--motion-duration-base) var(--motion-ease-standard), border-color var(--motion-duration-base) var(--motion-ease-standard);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.ds-pagination__adjacent:hover {
|
|
161
|
+
background-color: var(--color-bg-container-secondary);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.ds-pagination__adjacent:focus-visible {
|
|
165
|
+
outline: 2px solid var(--color-action-primary-bg);
|
|
166
|
+
outline-offset: 2px;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.ds-pagination__adjacent--next {
|
|
170
|
+
grid-column: 2;
|
|
171
|
+
align-items: flex-end;
|
|
172
|
+
text-align: end;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.ds-pagination__adjacent-eyebrow {
|
|
176
|
+
display: inline-flex;
|
|
177
|
+
align-items: center;
|
|
178
|
+
gap: var(--gap-050);
|
|
179
|
+
font-family: var(--font-caption-family);
|
|
180
|
+
font-size: var(--font-caption-size);
|
|
181
|
+
line-height: var(--font-caption-line-height);
|
|
182
|
+
color: var(--color-text-tertiary);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.ds-pagination__adjacent-eyebrow .ds-pagination__icon {
|
|
186
|
+
--icon-size: var(--icon-size-500);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.ds-pagination__adjacent-title {
|
|
190
|
+
max-width: 100%;
|
|
191
|
+
overflow: hidden;
|
|
192
|
+
text-overflow: ellipsis;
|
|
193
|
+
white-space: nowrap;
|
|
194
|
+
font-family: var(--font-title-body-family);
|
|
195
|
+
font-size: var(--font-title-body-size);
|
|
196
|
+
font-weight: var(--font-title-body-weight);
|
|
197
|
+
line-height: var(--font-title-body-line-height);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
@media (max-width: 480px) {
|
|
201
|
+
.ds-pagination--adjacent {
|
|
202
|
+
grid-template-columns: 1fr;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.ds-pagination__adjacent--next {
|
|
206
|
+
grid-column: 1;
|
|
207
|
+
}
|
|
208
|
+
}
|