@@ -84,16 +84,18 @@ function SidebarGroup(props: { group: Pages[number] } & { depth: number }) {
84
84
// A recursive function to determine if this group
85
85
// has an active child link. If so, it is open.
86
86
function hasActiveChild ( pages : Pages ) : boolean {
87
+ let isActive = false ;
87
88
for ( const page of pages ) {
88
89
if ( "group" in page ) {
89
90
if ( hasActiveChild ( page . pages ) ) {
90
- return true ;
91
+ isActive = true ;
91
92
}
92
93
} else if ( page . href ) {
93
- return getHrefIsActive ( ctx , router . asPath , page . href ) ;
94
+ isActive = getHrefIsActive ( ctx , router . asPath , page . href ) ;
94
95
}
95
96
}
96
- return false ;
97
+
98
+ return isActive ;
97
99
}
98
100
99
101
// Determine if this group has an active child link.
@@ -122,6 +124,7 @@ function SidebarGroup(props: { group: Pages[number] } & { depth: number }) {
122
124
depth = { props . depth }
123
125
href = { props . group . href }
124
126
icon = { props . group . icon }
127
+ isOpen = { open }
125
128
collapse = {
126
129
open ? < ChevronUpIcon size = { 14 } /> : < ChevronDownIcon size = { 14 } />
127
130
}
@@ -142,26 +145,32 @@ function SidebarGroup(props: { group: Pages[number] } & { depth: number }) {
142
145
function SidebarAnchor ( props : {
143
146
title : string ;
144
147
depth : number ;
148
+ isOpen ?: boolean ;
145
149
href ?: string ;
146
150
icon ?: string ;
147
151
collapse ?: ReactElement ;
148
152
onClick ?: ( ) => void ;
149
153
} ) {
150
154
const { href, isActive } = useHrefMeta ( props . href ?? "" ) ;
151
- const className = cn ( "relative group flex items-center pr-5 gap-2 py-2 pl-3" ) ;
155
+ const className = cn ( "py-2 inline-flex gap-2 grow" ) ;
156
+ const style = {
157
+ paddingLeft : `${ ( props . depth + 1 ) * 12 } px` ,
158
+ } ;
152
159
153
160
const element = props . href ? (
154
161
< Link
155
162
href = { href }
156
- onClick = { props . collapse ? props . onClick : undefined }
163
+ onClick = { props . collapse && ! props . isOpen ? props . onClick : undefined }
157
164
className = { cn ( className , {
158
165
"nav-link-active" : isActive ,
159
166
} ) }
167
+ style = { style }
160
168
/>
161
169
) : (
162
170
< div
163
171
role = "button"
164
172
className = { className }
173
+ style = { style }
165
174
onKeyDown = { props . onClick }
166
175
onClick = { props . onClick }
167
176
/>
@@ -176,23 +185,27 @@ function SidebarAnchor(props: {
176
185
< span key = "title" className = "flex-1 text-ellipsis overflow-hidden" >
177
186
{ props . title }
178
187
</ span > ,
179
- props . collapse ? (
180
- < div key = "toggle" onKeyDown = { props . onClick } onClick = { props . onClick } >
181
- { props . collapse }
182
- </ div >
183
- ) : null ,
184
188
] ) ;
185
189
186
190
return (
187
- < div className = "opacity-75 has-[.nav-link-active]:opacity-100 hover:opacity-100 mb-px relative rounded-md hover:bg-black/5 dark:hover:bg-white/5 has-[.nav-link-active]:bg-primary-light/10 dark:has-[.nav-link-active]:bg-primary-light/10 dark:hover:has-[.nav-link-active]:bg-primary-light/10 transition-all" >
188
- < div
189
- className = "has-[.nav-link-active]:font-bold has-[.nav-link-active]:text-primary-light dark:has-[.nav-link-active]:text-primary-light"
190
- style = { {
191
- paddingLeft : `${ props . depth * 12 } px` ,
192
- } }
193
- >
194
- { anchor }
195
- </ div >
191
+ < div
192
+ className = { cn (
193
+ "flex opacity-75 hover:opacity-100 mb-px relative rounded-md hover:bg-black/5 dark:hover:bg-white/5 transition-all has-[.nav-link-active]:font-bold" ,
194
+ "has-[.nav-link-active]:opacity-100 has-[.nav-link-active]:bg-primary-light/10 dark:has-[.nav-link-active]:bg-primary-light/10 dark:hover:has-[.nav-link-active]:bg-primary-light/10 has-[.nav-link-active]:text-primary-light dark:has-[.nav-link-active]:text-primary-light"
195
+ ) }
196
+ >
197
+ { anchor }
198
+ { props . collapse ? (
199
+ < button
200
+ key = "toggle"
201
+ type = "button"
202
+ onKeyDown = { props . onClick }
203
+ onClick = { props . onClick }
204
+ className = "px-3"
205
+ >
206
+ { props . collapse }
207
+ </ button >
208
+ ) : null }
196
209
</ div >
197
210
) ;
198
211
}
0 commit comments