File tree Expand file tree Collapse file tree 3 files changed +63
-34
lines changed Expand file tree Collapse file tree 3 files changed +63
-34
lines changed Original file line number Diff line number Diff line change @@ -768,7 +768,7 @@ button:has(~ .product-selector[style*="none"]) > .product-selector-button-icon {
768
768
padding : 0 ;
769
769
list-style : none;
770
770
font-weight : 400 ;
771
- font-size : 1 rem ;
771
+ font-size : 0.875 rem ;
772
772
}
773
773
774
774
.sidebar__container button {
@@ -788,15 +788,36 @@ button:has(~ .product-selector[style*="none"]) > .product-selector-button-icon {
788
788
}
789
789
790
790
.sidebar__toggle {
791
+ display : flex;
792
+ align-items : center;
793
+ gap : 0.25rem ;
791
794
cursor : pointer;
792
795
background : none;
793
796
border : none;
794
797
width : 100% ;
795
798
text-align : left;
796
- padding : 0.25rem 0.75 rem ;
799
+ padding : 0.25rem 0.5 rem ;
797
800
border-radius : 5px ;
798
801
}
799
802
803
+ .sidebar__chevron {
804
+ display : flex;
805
+ align-items : center;
806
+ }
807
+
808
+ .sidebar__chevron svg {
809
+ margin-right : -0.325rem ;
810
+ stroke-width : 1.5 ;
811
+ }
812
+
813
+ .sidebar__chevron--open {
814
+ transform : rotate (90deg );
815
+ }
816
+
817
+ .sidebar__toggle : has (.sidebar__chevron ) {
818
+ padding-left : .4rem ;
819
+ }
820
+
800
821
.sidebar__link {
801
822
display : block;
802
823
padding : 0.25rem 0.75rem ;
@@ -810,6 +831,7 @@ button:has(~ .product-selector[style*="none"]) > .product-selector-button-icon {
810
831
color : oklch (var (--color-brand ) / 1 );
811
832
background-color : oklch (var (--color-brand ) / 0.1 );
812
833
font-weight : 600 ;
834
+ width : fit-content;
813
835
}
814
836
815
837
.sidebar__toc {
Original file line number Diff line number Diff line change 1
- document . addEventListener ( 'DOMContentLoaded' , ( ) => {
2
- const toggles = document . querySelectorAll ( '.sidebar__toggle' ) ;
1
+ document . addEventListener ( 'click' , ( e ) => {
2
+ const toggle = e . target . closest ( '.sidebar__toggle' ) ;
3
+ if ( toggle ) {
4
+ const chevron = toggle . querySelector ( '.sidebar__chevron' ) ;
5
+ const expanded = toggle . getAttribute ( 'aria-expanded' ) === 'true' ;
6
+ const panel = document . getElementById ( toggle . getAttribute ( 'aria-controls' ) ) ;
3
7
4
- toggles . forEach ( ( toggle ) => {
5
- const parent = toggle . closest ( 'li.sidebar__section' ) ;
6
- const children = parent . querySelector ( '.sidebar__children' ) ;
8
+ // Toggle the expanded state
9
+ toggle . setAttribute ( 'aria-expanded' , String ( ! expanded ) ) ;
7
10
8
- toggle . addEventListener ( 'click' , ( ) => {
9
- const isExpanded = toggle . getAttribute ( 'aria-expanded' ) === 'true' ;
10
- toggle . setAttribute ( 'aria-expanded' , ! isExpanded ) ;
11
- children . hidden = isExpanded ;
12
- } ) ;
13
- } ) ;
11
+ // Toggle visibility of the content
12
+ if ( panel ) {
13
+ panel . hidden = expanded ;
14
+ }
15
+
16
+ // Toggle chevron direction class
17
+ if ( chevron ) {
18
+ chevron . classList . toggle ( 'sidebar__chevron--open' , ! expanded ) ;
19
+ }
20
+ }
14
21
} ) ;
Original file line number Diff line number Diff line change 9
9
{{- $isAncestor := .IsAncestor $currentPage -}}
10
10
{{- $shouldExpand := or $onPage $isAncestor -}}
11
11
{{- $sectionID := printf "section-%s" (urlize .Permalink) -}}
12
-
13
12
{{ if eq .Kind "section" }}
14
- < li class ="sidebar__section ">
15
- < button
16
- class ="sidebar__toggle "
17
- aria-expanded ="{{ $shouldExpand }} "
18
- aria-controls ="{{ $sectionID }} "
19
- >
20
- {{ .Title }}
21
- </ button >
22
-
23
- < div
24
- id =" {{ $sectionID }} "
25
- class =" sidebar__children "
26
- {{ if not $shouldExpand }}hidden{{ end }}
27
- >
28
- {{ partial "sidebar-list.html" (dict
29
- "firstSection" . "currentUrl" $currentUrl "currentPage" $currentPage)
30
- }}
31
- </ div >
32
- </ li >
33
-
13
+ < li class ="sidebar__section ">
14
+ < button
15
+ class ="sidebar__toggle "
16
+ aria-expanded ="{{ $shouldExpand }} "
17
+ aria-controls ="{{ $sectionID }} "
18
+ >
19
+ < span class =" sidebar__chevron {{ if $shouldExpand }}sidebar__chevron--open{{ end }} " >
20
+ {{ partial "lucide" (dict "context" . "icon" "chevron-right") }}
21
+ </ span >
22
+ < span class =" sidebar__toggle-text " > {{ .Title }} </ span >
23
+ </ button >
24
+ < div
25
+ id =" {{ $sectionID }} "
26
+ class =" sidebar__children "
27
+ {{ if not $shouldExpand }}hidden {{ end }}
28
+ >
29
+ {{ partial "sidebar-list.html" (dict
30
+ "firstSection" . "currentUrl" $currentUrl "currentPage" $currentPage) }}
31
+ </ div >
32
+ </ li >
34
33
{{ else if eq .Kind "page" }}
35
34
< li class ="sidebar__page ">
36
35
< a
46
45
{{ end }}
47
46
{{ end }}
48
47
</ li >
48
+
49
49
{{ end }}
50
50
{{ end }}
51
51
</ ul >
You can’t perform that action at this time.
0 commit comments