|
16 | 16 | let is_open = false;
|
17 | 17 | let search = '';
|
18 | 18 |
|
| 19 | + let expanded_part = current.part.slug; |
| 20 | + let expanded_chapter = current.chapter.slug; |
| 21 | +
|
19 | 22 | const duration = browser && matchMedia('(prefers-reduced-motion: reduce)').matches ? 0 : 200;
|
20 | 23 |
|
21 | 24 | $: regex = new RegExp(`\\b${search.length >= 2 ? search : ''}`, 'i');
|
|
88 | 91 | {#each filtered as part (part.slug)}
|
89 | 92 | <li
|
90 | 93 | class="part"
|
| 94 | + class:expanded={part.slug === expanded_part} |
| 95 | + aria-current={part.slug === current.part.slug ? 'step' : undefined} |
91 | 96 | transition:slide|local={{ duration }}
|
92 |
| - class:expanded={part.slug === current.part.slug} |
93 | 97 | >
|
94 |
| - <a sveltekit:prefetch href="/tutorial/{part.first}" data-label={part.label}> |
| 98 | + <button |
| 99 | + on:click={() => { |
| 100 | + if (expanded_part !== part.slug) { |
| 101 | + expanded_part = part.slug; |
| 102 | + expanded_chapter = part.chapters[0].slug; |
| 103 | + } |
| 104 | + }} |
| 105 | + > |
95 | 106 | Part {part.label}: {part.title}
|
96 |
| - </a> |
| 107 | + </button> |
97 | 108 |
|
98 |
| - {#if search.length >= 2 || part.slug === current.part.slug} |
| 109 | + {#if search.length >= 2 || part.slug === expanded_part} |
99 | 110 | <ul class="chapter" transition:slide|local={{ duration }}>
|
100 | 111 | {#each part.chapters as chapter (chapter.slug)}
|
101 |
| - <li class="chapter" class:expanded={chapter.slug === current.chapter.slug}> |
| 112 | + <li |
| 113 | + class="chapter" |
| 114 | + class:expanded={chapter.slug === expanded_chapter} |
| 115 | + aria-current={chapter.slug === current.chapter.slug ? 'step' : undefined} |
| 116 | + > |
102 | 117 | <img src={arrow} alt="Arrow icon" />
|
103 |
| - <a sveltekit:prefetch href="/tutorial/{chapter.first}" data-label={chapter.label} |
104 |
| - >{chapter.title}</a |
105 |
| - > |
| 118 | + <button on:click={() => (expanded_chapter = chapter.slug)}> |
| 119 | + {chapter.title} |
| 120 | + </button> |
106 | 121 |
|
107 |
| - {#if search.length >= 2 || chapter.slug === current.chapter.slug} |
| 122 | + {#if search.length >= 2 || chapter.slug === expanded_chapter} |
108 | 123 | <ul transition:slide|local={{ duration }}>
|
109 | 124 | {#each chapter.sections as section (section.slug)}
|
110 | 125 | <li
|
|
267 | 282 | position: relative;
|
268 | 283 | }
|
269 | 284 |
|
270 |
| - li[aria-current='page'] a { |
| 285 | + li[aria-current='page'] a, |
| 286 | + li[aria-current='step']:not(.expanded) > button { |
271 | 287 | color: var(--prime);
|
272 | 288 | }
|
273 | 289 |
|
274 | 290 | li img {
|
275 | 291 | position: absolute;
|
276 | 292 | left: -2rem;
|
277 |
| - top: 0.3rem; |
| 293 | + top: 0.1rem; |
278 | 294 | width: 2rem;
|
279 | 295 | height: 2rem;
|
280 | 296 | transition: transform 0.2s;
|
281 | 297 | }
|
282 | 298 |
|
283 |
| - li.expanded > a { |
| 299 | + li.expanded > button { |
284 | 300 | font-weight: bold;
|
285 | 301 | }
|
286 | 302 |
|
|
298 | 314 | --color: var(--second);
|
299 | 315 | }
|
300 | 316 |
|
301 |
| - a { |
| 317 | + a, |
| 318 | + button { |
302 | 319 | color: var(--second);
|
303 | 320 | padding: 0 0 0 0.5rem;
|
304 | 321 | margin: 0 0.5rem 0 0;
|
|
0 commit comments