@@ -190,7 +190,7 @@ export const SidebarLayout = ({ children }: { children: React.ReactNode }) => {
190190 const [ rotateChevron , setRotateChevron ] = useState ( false ) ;
191191 const handleRotate = ( ) => setRotateChevron ( ! rotateChevron ) ;
192192 const rotate = rotateChevron ? 'rotate(180deg)' : 'rotate(0)' ;
193- const pathWtihoutFragment = extractPathWithoutFragment ( router . asPath ) ;
193+ const pathWithoutFragment = extractPathWithoutFragment ( router . asPath ) ;
194194 useEffect ( ( ) => {
195195 if ( window ) {
196196 window . addEventListener ( 'resize' , ( ) => {
@@ -213,19 +213,19 @@ export const SidebarLayout = ({ children }: { children: React.ReactNode }) => {
213213 setOpen ( ! open ) ;
214214 } }
215215 >
216- { getDocsPath . includes ( pathWtihoutFragment ) && (
216+ { getDocsPath . includes ( pathWithoutFragment ) && (
217217 < h3 className = 'text-white ml-12' > Introduction</ h3 >
218218 ) }
219- { getStartedPath . includes ( pathWtihoutFragment ) && (
219+ { getStartedPath . includes ( pathWithoutFragment ) && (
220220 < h3 className = 'text-white ml-12' > Get started</ h3 >
221221 ) }
222- { getGuidesPath . includes ( pathWtihoutFragment ) && (
222+ { getGuidesPath . includes ( pathWithoutFragment ) && (
223223 < h3 className = 'text-white ml-12' > Guides</ h3 >
224224 ) }
225- { getReferencePath . includes ( pathWtihoutFragment ) && (
225+ { getReferencePath . includes ( pathWithoutFragment ) && (
226226 < h3 className = 'text-white ml-12' > Reference</ h3 >
227227 ) }
228- { getSpecificationPath . includes ( pathWtihoutFragment ) && (
228+ { getSpecificationPath . includes ( pathWithoutFragment ) && (
229229 < h3 className = 'text-white ml-12' > Specification</ h3 >
230230 ) }
231231 { router . pathname === null && (
@@ -294,24 +294,24 @@ export const DocsNav = ({
294294 getSpecification : false ,
295295 } ) ;
296296 useEffect ( ( ) => {
297- const pathWtihoutFragment = extractPathWithoutFragment ( router . asPath ) ;
297+ const pathWithoutFragment = extractPathWithoutFragment ( router . asPath ) ;
298298 const newActive = {
299299 getDocs : false ,
300300 getStarted : false ,
301301 getGuides : false ,
302302 getReference : false ,
303303 getSpecification : false ,
304304 } ;
305- if ( getDocsPath . includes ( pathWtihoutFragment ) ) {
305+ if ( getDocsPath . includes ( pathWithoutFragment ) ) {
306306 newActive . getDocs = true ;
307- } else if ( getStartedPath . includes ( pathWtihoutFragment ) ) {
307+ } else if ( getStartedPath . includes ( pathWithoutFragment ) ) {
308308 newActive . getStarted = true ;
309309 setActive ( { ...active , getStarted : true } ) ;
310- } else if ( getReferencePath . includes ( pathWtihoutFragment ) ) {
310+ } else if ( getReferencePath . includes ( pathWithoutFragment ) ) {
311311 newActive . getReference = true ;
312- } else if ( getSpecificationPath . includes ( pathWtihoutFragment ) ) {
312+ } else if ( getSpecificationPath . includes ( pathWithoutFragment ) ) {
313313 newActive . getSpecification = true ;
314- } else if ( getGuidesPath . includes ( pathWtihoutFragment ) ) {
314+ } else if ( getGuidesPath . includes ( pathWithoutFragment ) ) {
315315 newActive . getGuides = true ;
316316 }
317317 setActive ( newActive ) ;
@@ -339,17 +339,30 @@ export const DocsNav = ({
339339 }
340340 } , [ resolvedTheme ] ) ;
341341
342+ const handleAccordion = ( section : keyof typeof active ) => ( open : boolean ) => {
343+ if ( open ) {
344+ setActive ( {
345+ getDocs : false ,
346+ getStarted : false ,
347+ getGuides : false ,
348+ getReference : false ,
349+ getSpecification : false ,
350+ [ section ] : true ,
351+ } ) ;
352+ } else {
353+ setActive ( ( prev ) => ( {
354+ ...prev ,
355+ [ section ] : false ,
356+ } ) ) ;
357+ }
358+ } ;
359+
342360 return (
343361 < div id = 'sidebar' className = 'lg:mt-8 w-4/5 mx-auto lg:ml-4' >
344362 { /* Introduction */ }
345363 < Collapsible
346364 open = { active . getDocs }
347- onOpenChange = { ( open ) =>
348- setActive ( ( prev ) => ( {
349- ...prev ,
350- getDocs : open ,
351- } ) )
352- }
365+ onOpenChange = { handleAccordion ( 'getDocs' ) }
353366 className = 'my-2 bg-slate-200 dark:bg-slate-900 border-white border lg:border-hidden p-3 rounded transition-all duration-300 group'
354367 >
355368 < CollapsibleTrigger asChild >
@@ -451,12 +464,7 @@ export const DocsNav = ({
451464 { /* Get Started */ }
452465 < Collapsible
453466 open = { active . getStarted }
454- onOpenChange = { ( open ) =>
455- setActive ( ( prev ) => ( {
456- ...prev ,
457- getStarted : open ,
458- } ) )
459- }
467+ onOpenChange = { handleAccordion ( 'getStarted' ) }
460468 className = 'mb-2 bg-slate-200 dark:bg-slate-900 p-3 rounded border border-white lg:border-hidden transition-all duration-300 group'
461469 >
462470 < CollapsibleTrigger asChild >
@@ -555,12 +563,7 @@ export const DocsNav = ({
555563 { /* Guides */ }
556564 < Collapsible
557565 open = { active . getGuides }
558- onOpenChange = { ( open ) =>
559- setActive ( ( prev ) => ( {
560- ...prev ,
561- getGuides : open ,
562- } ) )
563- }
566+ onOpenChange = { handleAccordion ( 'getGuides' ) }
564567 className = 'mb-2 bg-slate-200 dark:bg-slate-900 p-3 rounded border border-white lg:border-hidden transition-all duration-300 group'
565568 >
566569 < CollapsibleTrigger asChild >
@@ -628,12 +631,7 @@ export const DocsNav = ({
628631 { /* Reference */ }
629632 < Collapsible
630633 open = { active . getReference }
631- onOpenChange = { ( open ) =>
632- setActive ( ( prev ) => ( {
633- ...prev ,
634- getReference : open ,
635- } ) )
636- }
634+ onOpenChange = { handleAccordion ( 'getReference' ) }
637635 className = 'mb-2 bg-slate-200 dark:bg-slate-900 p-3 rounded border border-white lg:border-hidden transition-all duration-300 group'
638636 >
639637 < CollapsibleTrigger asChild >
@@ -811,12 +809,7 @@ export const DocsNav = ({
811809 { /* Specification */ }
812810 < Collapsible
813811 open = { active . getSpecification }
814- onOpenChange = { ( open ) =>
815- setActive ( ( prev ) => ( {
816- ...prev ,
817- getSpecification : open ,
818- } ) )
819- }
812+ onOpenChange = { handleAccordion ( 'getSpecification' ) }
820813 className = 'mb-2 bg-slate-200 dark:bg-slate-900 p-3 rounded border border-white lg:border-hidden transition-all duration-300 group'
821814 >
822815 < CollapsibleTrigger asChild >
0 commit comments