@@ -5,7 +5,7 @@ import { TreeContextProvider } from 'fumadocs-ui/contexts/tree';
55import { ChevronRight , X } from 'lucide-react' ;
66import Link from 'next/link' ;
77import { usePathname } from 'next/navigation' ;
8- import React , { useMemo , useState } from 'react' ;
8+ import React , { useState } from 'react' ;
99import { baseOptions } from '@/app/layout.config' ;
1010import { Sidebar } from '@/components/layouts/docs' ;
1111import {
@@ -17,6 +17,7 @@ import {
1717 BreadcrumbSeparator ,
1818} from '@/components/ui/breadcrumb' ;
1919import { DocsLogo } from '@/components/ui/icon' ;
20+ import { isActive } from '@/lib/is-active' ;
2021import { cn } from '@/lib/utils' ;
2122import { SearchToggle } from '../layout/search-toggle' ;
2223
@@ -28,7 +29,6 @@ interface MobileNavigationProps {
2829
2930export function MobileNavigation ( { isOpen = false , onClose, tree } : MobileNavigationProps ) {
3031 const [ activeSubmenu , setActiveSubmenu ] = useState < string | null > ( null ) ;
31- const [ showMainMenu , setShowMainMenu ] = useState ( false ) ;
3232 const pathname = usePathname ( ) ;
3333
3434 const isInDocsContext = ! ! tree ;
@@ -37,12 +37,50 @@ export function MobileNavigation({ isOpen = false, onClose, tree }: MobileNaviga
3737
3838 const handleClose = ( ) => {
3939 setActiveSubmenu ( null ) ;
40- setShowMainMenu ( false ) ;
4140 onClose ?.( ) ;
4241 } ;
4342
43+ const renderMainLinks = ( ) => (
44+ < >
45+ { baseOptions . links
46+ ?. filter ( ( item ) => {
47+ if ( ! ( 'url' in item ) || ! item . url ) return true ;
48+
49+ const activeMode =
50+ 'active' in item ? ( item . active ?? 'url' ) : item . type === 'menu' ? 'nested-url' : 'url' ;
51+ if ( activeMode === 'none' ) return true ;
52+
53+ return ! isActive ( item . url , pathname , activeMode === 'nested-url' ) ;
54+ } )
55+ . map ( ( item , index ) => (
56+ < div key = { index } >
57+ { item . type === 'menu' ? (
58+ < button
59+ type = "button"
60+ className = "w-full flex items-center justify-between px-2 py-2 text-[0.75rem] leading-none tracking-wide font-mono font-bold hover:bg-accent transition-colors text-left"
61+ onClick = { ( ) => setActiveSubmenu ( String ( item . text ) ) }
62+ >
63+ < span className = "text-muted-foreground" > { item . text } </ span >
64+ < ChevronRight className = "h-4 w-4 text-muted-foreground" />
65+ </ button >
66+ ) : (
67+ 'url' in item && (
68+ < Link
69+ href = { item . url as string }
70+ onClick = { handleClose }
71+ className = "flex items-center justify-between px-2 py-2 text-[0.75rem] leading-none tracking-wide font-mono font-bold hover:bg-accent transition-colors"
72+ >
73+ { item . text }
74+ </ Link >
75+ )
76+ ) }
77+ </ div >
78+ ) ) }
79+ </ >
80+ ) ;
81+
4482 return (
45- < div className = "fixed inset-0 z-50 md :hidden" >
83+ < div className = "fixed inset-0 z-50 xl :hidden" >
4684 < div
4785 className = "fixed inset-0 bg-black/50 transition-opacity duration-200"
4886 onClick = { handleClose }
@@ -73,7 +111,6 @@ export function MobileNavigation({ isOpen = false, onClose, tree }: MobileNaviga
73111 type = "button"
74112 onClick = { ( ) => {
75113 setActiveSubmenu ( null ) ;
76- setShowMainMenu ( true ) ;
77114 } }
78115 >
79116 ..
@@ -89,9 +126,6 @@ export function MobileNavigation({ isOpen = false, onClose, tree }: MobileNaviga
89126 </ BreadcrumbList >
90127 </ Breadcrumb >
91128 ) : (
92- // isInDocsContext && !showMainMenu ? (
93- // getMobileBreadcrumb()
94- // ) :
95129 < Link href = "/" onClick = { handleClose } >
96130 < DocsLogo />
97131 </ Link >
@@ -129,52 +163,19 @@ export function MobileNavigation({ isOpen = false, onClose, tree }: MobileNaviga
129163 </ Link >
130164 ) ;
131165 } )
132- ) : isInDocsContext && ! showMainMenu ? (
133- < TreeContextProvider tree = { tree } >
134- < div className = "bg-background" >
135- < div className = "[&_aside]:!relative [&_aside]:!top-auto [&_aside]:!w-full [&_aside]:!h-auto [&_aside]:!visible [&_aside]:!px-0 [&_aside]:!pt-0 [&_aside]:!pb-10" >
136- < Sidebar />
137- </ div >
138- </ div >
139- </ TreeContextProvider >
140166 ) : (
141- // TODO: Hide get started link for now
142167 < >
143- { /* <Link
144- href="/start"
145- onClick={handleClose}
146- className="font-mono text-muted-foreground flex items-center justify-between px-4 py-3 text-base hover:bg-accent transition-colors"
147- >
148- Get Started
149- </Link> */ }
168+ { renderMainLinks ( ) }
150169
151- { baseOptions . links ?. map ( ( item , index ) => (
152- < div key = { index } className = "" >
153- { item . type === 'menu' ? (
154- < button
155- type = "button"
156- className = "w-full flex items-center justify-between px-4 py-3 text-lg hover:bg-accent transition-colors text-left"
157- onClick = { ( ) => {
158- setActiveSubmenu ( String ( item . text ) ) ;
159- setShowMainMenu ( false ) ;
160- } }
161- >
162- < span className = "font-mono text-muted-foreground" > { item . text } </ span >
163- < ChevronRight className = "h-4 w-4 text-muted-foreground" />
164- </ button >
165- ) : (
166- 'url' in item && (
167- < Link
168- href = { item . url as string }
169- onClick = { handleClose }
170- className = "font-mono flex items-center justify-between px-4 py-3 text-lg hover:bg-accent transition-colors"
171- >
172- { item . text }
173- </ Link >
174- )
175- ) }
176- </ div >
177- ) ) }
170+ { isInDocsContext ? (
171+ < TreeContextProvider tree = { tree } >
172+ < div className = "bg-background pt-2" >
173+ < div className = "[&_aside]:!relative [&_aside]:!top-auto [&_aside]:!w-full [&_aside]:!h-auto [&_aside]:!visible [&_aside]:!px-0 [&_aside]:!pt-0 [&_aside]:!pb-10" >
174+ < Sidebar />
175+ </ div >
176+ </ div >
177+ </ TreeContextProvider >
178+ ) : null }
178179 </ >
179180 ) }
180181 </ div >
0 commit comments