@@ -12,10 +12,9 @@ import {
12
12
useMatches ,
13
13
useNavigate ,
14
14
useParams ,
15
- useRouterState ,
16
15
} from '@tanstack/react-router'
17
16
import type { AnyOrama , SearchParamsFullText , AnyDocument } from '@orama/orama'
18
- import { SearchBox , SearchButton } from '@orama/searchbox'
17
+ import { SearchBox } from '@orama/searchbox'
19
18
import { Carbon } from '~/components/Carbon'
20
19
import { Select } from '~/components/Select'
21
20
import { useLocalStorage } from '~/utils/useLocalStorage'
@@ -25,7 +24,7 @@ import type { SelectOption } from '~/components/Select'
25
24
import type { ConfigSchema , MenuItem } from '~/utils/config'
26
25
import { create } from 'zustand'
27
26
import { searchBoxParams , searchButtonParams } from '~/components/Orama'
28
- import { Framework , getFrameworkOptions , getLibrary } from '~/libraries'
27
+ import { Framework , getFrameworkOptions } from '~/libraries'
29
28
import { DocsCalloutQueryGG } from '~/components/DocsCalloutQueryGG'
30
29
import { DocsCalloutBytes } from '~/components/DocsCalloutBytes'
31
30
import { ClientOnlySearchButton } from './ClientOnlySearchButton'
@@ -179,7 +178,7 @@ const useMenuConfig = ({
179
178
config : ConfigSchema
180
179
repo : string
181
180
frameworks : Framework [ ]
182
- } ) => {
181
+ } ) : MenuItem [ ] => {
183
182
const currentFramework = useCurrentFramework ( frameworks )
184
183
185
184
const localMenu : MenuItem = {
@@ -211,7 +210,7 @@ const useMenuConfig = ({
211
210
return [
212
211
localMenu ,
213
212
// Merge the two menus together based on their group labels
214
- ...config . sections . map ( ( section ) => {
213
+ ...config . sections . map ( ( section ) : MenuItem | undefined => {
215
214
const frameworkDocs = section . frameworks ?. find (
216
215
( f ) => f . label === currentFramework . framework
217
216
)
@@ -232,9 +231,11 @@ const useMenuConfig = ({
232
231
return {
233
232
label : section . label ,
234
233
children,
234
+ collapsible : section . collapsible ?? false ,
235
+ defaultCollapsed : section . defaultCollapsed ?? false ,
235
236
}
236
237
} ) ,
237
- ] . filter ( Boolean )
238
+ ] . filter ( ( item ) => item !== undefined )
238
239
}
239
240
240
241
const useFrameworkConfig = ( { frameworks } : { frameworks : Framework [ ] } ) => {
@@ -317,8 +318,7 @@ export function DocsLayout({
317
318
children,
318
319
} : DocsLayoutProps ) {
319
320
const { libraryId } = useParams ( {
320
- strict : false ,
321
- experimental_returnIntersection : true ,
321
+ from : '/$libraryId/$version/docs' ,
322
322
} )
323
323
const frameworkConfig = useFrameworkConfig ( { frameworks } )
324
324
const versionConfig = useVersionConfig ( { versions } )
@@ -350,16 +350,29 @@ export function DocsLayout({
350
350
const [ showBytes , setShowBytes ] = useLocalStorage ( 'showBytes' , true )
351
351
352
352
const menuItems = menuConfig . map ( ( group , i ) => {
353
+ const WrapperComp = group . collapsible ? 'details' : 'div'
354
+ const LabelComp = group . collapsible ? 'summary' : 'div'
355
+
356
+ const isCollapsed = group . defaultCollapsed ?? false
357
+
358
+ const detailsProps = group . collapsible ? { open : ! isCollapsed } : { }
359
+
353
360
return (
354
- < div key = { i } >
355
- < div className = "text-[.8em] uppercase font-black" > { group ?. label } </ div >
361
+ < WrapperComp
362
+ key = { `group-${ i } ` }
363
+ className = "[&>summary]:before:mr-[0.4rem] [&>summary]:marker:text-[0.8em] [&>summary]:marker:-ml-[0.3rem] [&>summary]:marker:leading-4 [&>div.ts-sidebar-label]:ml-[1rem] relative select-none"
364
+ { ...detailsProps }
365
+ >
366
+ < LabelComp className = "text-[.8em] uppercase font-black leading-4 ts-sidebar-label" >
367
+ { group ?. label }
368
+ </ LabelComp >
356
369
< div className = "h-2" />
357
- < div className = "ml-2 text-[.85em]" >
370
+ < ul className = "ml-2 text-[.85em] list-none " >
358
371
{ group ?. children ?. map ( ( child , i ) => {
359
372
const linkClasses = `cursor-pointer flex gap-2 items-center justify-between group px-2 py-[.1rem] rounded-lg hover:bg-gray-500 hover:bg-opacity-10`
360
373
361
374
return (
362
- < React . Fragment key = { i } >
375
+ < li key = { i } >
363
376
{ child . to . startsWith ( 'http' ) ? (
364
377
< a href = { child . to } className = { linkClasses } >
365
378
{ child . label }
@@ -423,11 +436,11 @@ export function DocsLayout({
423
436
} }
424
437
</ Link >
425
438
) }
426
- </ React . Fragment >
439
+ </ li >
427
440
)
428
441
} ) }
429
- </ div >
430
- </ div >
442
+ </ ul >
443
+ </ WrapperComp >
431
444
)
432
445
} )
433
446
0 commit comments