-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavbar.tsx
More file actions
77 lines (65 loc) · 2.79 KB
/
Navbar.tsx
File metadata and controls
77 lines (65 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"use client";
import { useState } from "react";
import { usePathname } from "next/navigation";
import { Logo } from "@/components/navbar/Logo";
import { NavbarActions } from "@/components/navbar/NavbarActions";
import { NavTabs } from "@/components/navbar/NavTabs";
import { cn } from "@/lib/utils";
const ALL_LISTINGS_PAGES = ["/", "/items", "/sublets"] as const;
type AllListingsPagePath = (typeof ALL_LISTINGS_PAGES)[number];
const ALL_LISTINGS_PAGES_CONFIG: Record<AllListingsPagePath, { text: string; href: string }> = {
"/": { text: "New Item", href: "/create/item" },
"/items": { text: "New Item", href: "/create/item" },
"/sublets": { text: "New Sublet", href: "/create/sublet" },
} as const;
const isAllListingsPage = (path: string): path is AllListingsPagePath => {
return ALL_LISTINGS_PAGES.includes(path as AllListingsPagePath);
};
export const Navbar = () => {
const pathname = usePathname();
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
const showListingsTabs = isAllListingsPage(pathname);
const createNewConfig = showListingsTabs ? ALL_LISTINGS_PAGES_CONFIG[pathname] : undefined;
const toggleMobileMenu = () => setIsMobileMenuOpen(!isMobileMenuOpen);
const closeMobileMenu = () => setIsMobileMenuOpen(false);
return (
<nav className="fixed top-0 z-50 w-full" role="navigation" aria-label="Main navigation">
<div className="relative z-50 border-b bg-gray-50 shadow-xs backdrop-blur supports-[backdrop-filter]:bg-gray-50/95">
<div className="flex flex-col py-3">
{/* top row */}
<div className="mx-auto flex h-10 w-full max-w-[96rem] items-center justify-between gap-4 px-4 sm:px-12">
<Logo onLogoClick={closeMobileMenu} />
{/* desktop only tabs */}
{showListingsTabs && (
<div className="hidden md:block">
<NavTabs variant="desktop" />
</div>
)}
<NavbarActions
createNewConfig={createNewConfig}
mobileShowHamburger={showListingsTabs}
isMobileMenuOpen={isMobileMenuOpen}
onToggleMobileMenu={toggleMobileMenu}
/>
</div>
</div>
</div>
{/* mobile only menu */}
<div
id="mobile-menu"
className={cn(
"bg-background fixed inset-x-0 border-b shadow-lg transition-all duration-300 ease-in-out md:hidden",
isMobileMenuOpen
? "z-40 translate-y-0 opacity-100"
: "pointer-events-none z-30 -translate-y-full opacity-0"
)}
aria-hidden={!isMobileMenuOpen}
>
<div className="mx-auto flex max-w-[96rem] flex-col">
{/* mobile only tabs */}
<NavTabs variant="mobile" onLinkClick={closeMobileMenu} />
</div>
</div>
</nav>
);
};