Skip to content

Commit ca4e598

Browse files
authored
Merge pull request #36 from steel-dev/dane/feat-navigation-expand-mobile-menu-visibility-to-desktop
2 parents 50af774 + acd342b commit ca4e598

2 files changed

Lines changed: 53 additions & 52 deletions

File tree

‎components/layout/mobile-menu-button.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function MobileMenuButton({ tree }: MobileMenuButtonProps) {
1818
<Button
1919
variant="ghost"
2020
size="icon"
21-
className="h-8 w-8 md:hidden"
21+
className="h-8 w-8 xl:hidden"
2222
onClick={open}
2323
aria-label="Open navigation menu"
2424
aria-expanded={isOpen}

‎components/layout/mobile-navigation.tsx‎

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { TreeContextProvider } from 'fumadocs-ui/contexts/tree';
55
import { ChevronRight, X } from 'lucide-react';
66
import Link from 'next/link';
77
import { usePathname } from 'next/navigation';
8-
import React, { useMemo, useState } from 'react';
8+
import React, { useState } from 'react';
99
import { baseOptions } from '@/app/layout.config';
1010
import { Sidebar } from '@/components/layouts/docs';
1111
import {
@@ -17,6 +17,7 @@ import {
1717
BreadcrumbSeparator,
1818
} from '@/components/ui/breadcrumb';
1919
import { DocsLogo } from '@/components/ui/icon';
20+
import { isActive } from '@/lib/is-active';
2021
import { cn } from '@/lib/utils';
2122
import { SearchToggle } from '../layout/search-toggle';
2223

@@ -28,7 +29,6 @@ interface MobileNavigationProps {
2829

2930
export 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

Comments
 (0)