Skip to content

Commit 670c10d

Browse files
committed
Sidebar: Show and hide toc
1 parent 2590dc3 commit 670c10d

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

assets/css/v2/style.css

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,12 +885,14 @@ button:has(~ .product-selector[style*="none"]) > .product-selector-button-icon {
885885
}
886886
}
887887

888-
.sidebar__link--current {
888+
.sidebar__link--current,
889+
.sidebar__toggle.sidebar__link--current {
889890
color: oklch(var(--color-brand) / 1);
890891
background-color: oklch(var(--color-brand) / 0.1);
891892
font-weight: 600;
892-
display: block; /* Make it stretch horizontally clearly */
893-
width: auto; /* reset width clearly */
893+
display: flex;
894+
justify-self: stretch;
895+
width: auto;
894896
box-sizing: border-box;
895897
}
896898

@@ -901,6 +903,10 @@ button:has(~ .product-selector[style*="none"]) > .product-selector-button-icon {
901903
border-left: 1px solid var(--color-divider);
902904
color: oklch(0 0 0 / 0.75);
903905

906+
&[hidden] {
907+
display: none;
908+
}
909+
904910
a {
905911
color: oklch(0 0 0 / 0.75);
906912
text-decoration: none;

assets/js/sidebar-v2.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ document.addEventListener('click', (e) => {
55
const expanded = toggle.getAttribute('aria-expanded') === 'true';
66
const panel = document.getElementById(toggle.getAttribute('aria-controls'));
77

8-
// Toggle the expanded state
98
toggle.setAttribute('aria-expanded', String(!expanded));
109

11-
// Toggle visibility of the content
1210
if (panel) {
1311
panel.hidden = expanded;
1412
}
1513

16-
// Toggle chevron direction class
1714
if (chevron) {
1815
chevron.classList.toggle('sidebar__chevron--open', !expanded);
1916
}

layouts/partials/sidebar-list.html

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,32 @@
3333
</div>
3434
</li>
3535

36-
{{ else if eq .Kind "page" }}
36+
{{ else if eq .Kind "page" }}
3737
<li class="sidebar__page">
38-
<a
39-
href="{{ .Permalink }}"
40-
class="sidebar__link {{ if $onPage }}sidebar__link--current{{ end }}"
41-
{{ if $onPage }}aria-current="page"{{ end }}
42-
>
43-
{{ .Title }}
44-
</a>
45-
46-
{{ if $onPage }}
47-
{{ with .TableOfContents }}
48-
<div class="sidebar__toc" id="TableOfContents">{{ . }}</div>
49-
{{ end }}
38+
{{- $pageHasTOC := (and $onPage .TableOfContents) -}}
39+
{{- $tocID := printf "toc-%s" (urlize .Permalink) -}}
40+
{{- if $pageHasTOC }}
41+
<button
42+
class="sidebar__toggle sidebar__link sidebar__link--current"
43+
aria-expanded="true"
44+
aria-controls="{{ $tocID }}"
45+
>
46+
<span>{{ .Title }}</span>
47+
<span class="sidebar__chevron sidebar__chevron--open">
48+
{{ partial "lucide" (dict "context" . "icon" "chevron-right") }}
49+
</span>
50+
</button>
51+
<div id="{{ $tocID }}" class="sidebar__toc">
52+
{{ .TableOfContents }}
53+
</div>
54+
{{ else }}
55+
<a
56+
href="{{ .Permalink }}"
57+
class="sidebar__link {{ if $onPage }}sidebar__link--current{{ end }}"
58+
{{ if $onPage }}aria-current="page"{{ end }}
59+
>
60+
{{ .Title }}
61+
</a>
5062
{{ end }}
5163
</li>
5264
{{ end }}

0 commit comments

Comments
 (0)