Skip to content

Commit 53303d3

Browse files
committed
Collapse sections
1 parent cdf5006 commit 53303d3

3 files changed

Lines changed: 142 additions & 1 deletion

File tree

_config.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,24 @@ site.helper("walkthrough", (track: string) => {
524524
return ` <li><a href="${escapeHtml(page.src.path)}">${escapeHtml(title)}</a>${sections}\n </li>`;
525525
});
526526

527-
return `<ol class="walkthrough-list" aria-label="${label}">\n${items.join("\n")}\n</ol>`;
527+
const visibleItems = items.slice(0, 10);
528+
const remainingItems = items.slice(10);
529+
if (!remainingItems.length) {
530+
return `<ol class="walkthrough-list" aria-label="${label}">\n${visibleItems.join("\n")}\n</ol>`;
531+
}
532+
533+
return `<div class="walkthrough-group" data-walkthrough-collapsed>
534+
<ol class="walkthrough-list" aria-label="${label}">\n${visibleItems.join("\n")}\n </ol>
535+
<button class="walkthrough-more" type="button" aria-expanded="false">
536+
<span class="walkthrough-more-collapsed">Show More</span>
537+
<span class="walkthrough-more-expanded">Show Less</span>
538+
</button>
539+
<div class="walkthrough-remainder">
540+
<div class="walkthrough-remainder-inner">
541+
<ol class="walkthrough-list walkthrough-list-continuation" start="11" aria-label="${label}, continued">\n${remainingItems.join("\n")}\n </ol>
542+
</div>
543+
</div>
544+
</div>`;
528545
}, { type: "filter" });
529546

530547
site.data("layout", "layout.tsx");

src/_includes/style/walkthrough.scss

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,51 @@ ol.walkthrough-list {
5252
}
5353
}
5454

55+
.walkthrough-group {
56+
position: relative;
57+
58+
> .walkthrough-list {
59+
margin-bottom: 0;
60+
}
61+
}
62+
63+
.walkthrough-more {
64+
display: none;
65+
}
66+
67+
.walkthrough-more-expanded {
68+
display: none;
69+
}
70+
71+
.walkthrough-remainder {
72+
display: grid;
73+
grid-template-rows: 0fr;
74+
opacity: 0;
75+
transform: translateY(-0.5rem);
76+
transition:
77+
grid-template-rows 560ms cubic-bezier(0.16, 1, 0.3, 1),
78+
opacity 240ms ease,
79+
transform 480ms cubic-bezier(0.16, 1, 0.3, 1);
80+
81+
> .walkthrough-remainder-inner {
82+
min-height: 0;
83+
overflow: hidden;
84+
margin-left: -1.5rem;
85+
padding-left: 1.5rem;
86+
87+
> .walkthrough-list {
88+
margin-top: 0;
89+
margin-bottom: 0;
90+
}
91+
}
92+
}
93+
94+
.walkthrough-list-continuation > li {
95+
opacity: 0;
96+
transform: translateY(-0.3rem);
97+
transition: opacity 220ms ease, transform 400ms cubic-bezier(0.16, 1, 0.3, 1);
98+
}
99+
55100
.index-subsections > ul {
56101
display: grid;
57102
gap: 0.15rem;
@@ -166,12 +211,78 @@ ol.walkthrough-list {
166211
}
167212

168213
@media (hover: hover) and (pointer: fine) {
214+
.walkthrough-group:hover,
215+
.walkthrough-group:focus-within {
216+
> .walkthrough-remainder {
217+
grid-template-rows: 1fr;
218+
opacity: 1;
219+
transform: none;
220+
221+
> .walkthrough-remainder-inner > .walkthrough-list {
222+
margin-bottom: 1rem;
223+
}
224+
}
225+
226+
.walkthrough-list-continuation > li {
227+
opacity: 1;
228+
transform: none;
229+
}
230+
}
231+
169232
.index-subsection-toggle {
170233
display: none;
171234
}
172235
}
173236

237+
@media (hover: none), (pointer: coarse) {
238+
.walkthrough-more {
239+
display: inline-flex;
240+
align-items: center;
241+
min-height: 2rem;
242+
margin: 0.2rem 0 0.2rem 1.15rem;
243+
padding: 0.2rem 0.45rem;
244+
border: 0;
245+
border-radius: 0;
246+
background: var(--dbt);
247+
color: var(--kr);
248+
cursor: pointer;
249+
font: inherit;
250+
font-size: 0.75rem;
251+
touch-action: manipulation;
252+
}
253+
254+
.walkthrough-group.is-expanded > .walkthrough-more {
255+
> .walkthrough-more-collapsed {
256+
display: none;
257+
}
258+
259+
> .walkthrough-more-expanded {
260+
display: inline;
261+
}
262+
}
263+
264+
.walkthrough-group.is-expanded > .walkthrough-remainder {
265+
grid-template-rows: 1fr;
266+
opacity: 1;
267+
transform: none;
268+
269+
> .walkthrough-remainder-inner > .walkthrough-list {
270+
margin-bottom: 1rem;
271+
}
272+
}
273+
274+
.walkthrough-group.is-expanded .walkthrough-list-continuation > li {
275+
opacity: 1;
276+
transform: none;
277+
}
278+
}
279+
174280
@media (prefers-reduced-motion: reduce) {
281+
.walkthrough-remainder,
282+
.walkthrough-list-continuation > li {
283+
transition-duration: 0.01ms !important;
284+
}
285+
175286
.index-subsections > ul > li {
176287
transition-delay: 0ms !important;
177288
}

src/static/script.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,18 @@ function initIndexSubsections() {
331331
hoverQuery.addEventListener("change", syncInputMode);
332332
}
333333

334+
function initWalkthroughGroups() {
335+
for (const group of document.querySelectorAll("[data-walkthrough-collapsed]")) {
336+
const button = group.querySelector(":scope > .walkthrough-more");
337+
if (!(button instanceof HTMLButtonElement)) continue;
338+
339+
button.addEventListener("click", () => {
340+
const expanded = group.classList.toggle("is-expanded");
341+
button.setAttribute("aria-expanded", String(expanded));
342+
});
343+
}
344+
}
345+
334346
function initToc() {
335347
const toc = document.querySelector(".toc");
336348
const mobileToggle = toc?.querySelector(".toc-mobile-toggle");
@@ -718,6 +730,7 @@ function initToc() {
718730
if (!activateHashEntry()) updateActive();
719731
}
720732

733+
initWalkthroughGroups();
721734
initIndexSubsections();
722735
initReferenceFilter();
723736
initToc();

0 commit comments

Comments
 (0)