|
1 | 1 | <script lang="ts"> |
| 2 | + import { Navigation, NavigationItem } from "@stackoverflow/stacks-svelte"; |
| 3 | +
|
2 | 4 | type Props = { |
3 | 5 | toc: DocsTocItem[]; |
4 | 6 | activeId: string | null; |
5 | 7 | headingId?: string; |
| 8 | + label?: string; |
6 | 9 | onSelect: (id: string) => void; |
7 | 10 | showHeading?: boolean; |
8 | 11 | }; |
|
11 | 14 | toc, |
12 | 15 | activeId, |
13 | 16 | headingId, |
| 17 | + label = "Contents", |
14 | 18 | onSelect, |
15 | 19 | showHeading = true, |
16 | 20 | }: Props = $props(); |
| 21 | +
|
17 | 22 | </script> |
18 | 23 |
|
19 | 24 | {#if showHeading && headingId} |
|
22 | 27 | </h2> |
23 | 28 | {/if} |
24 | 29 |
|
25 | | -<ul class="s-navigation s-navigation__vertical"> |
| 30 | +<Navigation {label} orientation="vertical" listClass="contents-list"> |
26 | 31 | {#each toc as item, index (item.id)} |
27 | | - <li> |
28 | | - <a |
29 | | - href="#{item.id}" |
30 | | - onclick={() => onSelect(item.id)} |
31 | | - class="s-navigation--item fs-caption bar0 fw-bold fc-black ai-start" |
32 | | - class:bg-black-100={activeId === item.id} |
33 | | - class:is-active={activeId === item.id} |
34 | | - > |
35 | | - <span class="fl-shrink0 w24 d-flex ai-center fc-theme-primary"> |
36 | | - {(index + 1).toString().padStart(2, "0")} |
37 | | - </span> |
38 | | - <span class="truncate">{item.value}</span> |
39 | | - </a> |
40 | | - |
41 | | - {#if item.children && item.children.length > 0} |
42 | | - <ul class="s-navigation s-navigation__vertical"> |
| 32 | + <NavigationItem |
| 33 | + href="#{item.id}" |
| 34 | + text={item.value} |
| 35 | + selected={activeId === item.id} |
| 36 | + onclick={() => onSelect(item.id)} |
| 37 | + class={`contents-primary-item fs-caption bar0 fw-bold fc-black ai-start ${activeId === item.id ? "bg-black-100" : ""}`} |
| 38 | + /> |
| 39 | + |
| 40 | + {#if item.children && item.children.length > 0} |
| 41 | + <li> |
| 42 | + <Navigation |
| 43 | + label={`${item.value} sections`} |
| 44 | + orientation="vertical" |
| 45 | + > |
43 | 46 | {#each item.children as child (child.id)} |
44 | | - <li> |
45 | | - <a |
46 | | - href="#{child.id}" |
47 | | - onclick={() => onSelect(child.id)} |
48 | | - class="s-navigation--item fs-caption bar0" |
49 | | - class:bg-black-100={activeId === child.id} |
50 | | - class:is-active={activeId === child.id} |
51 | | - > |
52 | | - {child.value} |
53 | | - </a> |
54 | | - </li> |
| 47 | + <NavigationItem |
| 48 | + href="#{child.id}" |
| 49 | + text={child.value} |
| 50 | + selected={activeId === child.id} |
| 51 | + onclick={() => onSelect(child.id)} |
| 52 | + class={`fs-caption bar0 ${activeId === child.id ? "bg-black-100" : ""}`} |
| 53 | + /> |
55 | 54 | {/each} |
56 | | - </ul> |
57 | | - {/if} |
58 | | - </li> |
| 55 | + </Navigation> |
| 56 | + </li> |
| 57 | + {/if} |
59 | 58 | {/each} |
60 | | -</ul> |
| 59 | +</Navigation> |
| 60 | + |
| 61 | +<style> |
| 62 | + :global(.contents-list) { |
| 63 | + counter-reset: contents-section; |
| 64 | + } |
| 65 | +
|
| 66 | + :global(.contents-primary-item .s-navigation--item-text) { |
| 67 | + flex-direction: row; |
| 68 | + } |
| 69 | +
|
| 70 | + :global(.contents-primary-item .s-navigation--item-text::before) { |
| 71 | + color: var(--theme-primary); |
| 72 | + content: counter(contents-section, decimal-leading-zero); |
| 73 | + counter-increment: contents-section; |
| 74 | + flex-shrink: 0; |
| 75 | + font-weight: var(--fw-bold); |
| 76 | + height: auto; |
| 77 | + margin-right: var(--su8); |
| 78 | + visibility: visible; |
| 79 | + width: var(--su24); |
| 80 | + } |
| 81 | +</style> |
0 commit comments