Navbar Menu
A beautiful animated dropdown menu for navigation with support for icons and descriptions.
Category
NavigationReact
CSS
Tailwind
Manual
Create a file and paste the following code into it.
navbar-menu.tsx
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
"use client";
import { AnimatePresence, motion } from "motion/react";
import Image from "next/image";
import * as React from "react";
import { ArrowDown01Icon, HugeiconsIcon } from "@/components/icons";
import { cn } from "@/lib/cn";
import { RaisedButton } from "@/registry/new-york/ui/raised-button";
export interface NavbarMenuLink {
label: string;
href: string;
icon?: React.ReactNode;
external?: boolean;
description?: string;
backgroundImage?: string;
rowSpan?: number;
}
export interface NavbarMenuSection {
id: string;
links: NavbarMenuLink[];
gridLayout?: string;
}
export interface NavbarMenuProps {
activeMenu: string;
sections: NavbarMenuSection[];
onClose?: () => void;
}
export interface NavbarWithMenuProps {
sections: NavbarMenuSection[];
navItems?: Array<
| { type: "link"; label: string; href: string }
| { type: "dropdown"; label: string; menu: string }
>;
logo?: React.ReactNode;
cta?: React.ReactNode;
}
const ListItem = React.forwardRef<
HTMLAnchorElement,
React.AnchorHTMLAttributes<HTMLAnchorElement> & {
title: string;
children?: React.ReactNode;
href: string;
external?: boolean;
icon?: React.ReactNode;
backgroundImage?: string;
rowSpan?: number;
}
>(
(
{
className,
title,
children,
href,
external,
icon,
backgroundImage,
rowSpan,
...props
},
ref,
) => {
return (
<li className={cn("list-none", rowSpan === 2 && "row-span-2")}>
<a
ref={ref}
href={href}
target={external ? "_blank" : undefined}
rel={external ? "noopener noreferrer" : undefined}
className={cn(
"group relative flex h-full min-h-18 w-full flex-col justify-center overflow-hidden rounded-2xl bg-zinc-800/0 p-3.5 leading-none no-underline outline-none transition-all duration-150 select-none hover:bg-zinc-800 hover:text-zinc-100 focus:bg-zinc-800 focus:text-zinc-100",
className,
)}
{...props}
>
{backgroundImage && (
<>
<Image
fill
src={backgroundImage}
alt={title}
className="absolute inset-0 z-0 h-full w-full object-cover transition-all group-hover:brightness-60"
/>
<div className="absolute inset-0 z-[1] bg-gradient-to-t from-black/90 via-black/50 to-black/20" />
</>
)}
<div
className={cn(
"flex items-start gap-3",
backgroundImage && "relative z-[2] mt-auto",
)}
>
{icon && (
<span
className={cn(
"relative flex min-h-10 min-w-10 items-center justify-center rounded-xl p-2 text-primary transition group-hover:text-zinc-300",
backgroundImage
? "bg-white/5 backdrop-blur group-hover:bg-white/10"
: "bg-zinc-800/80 group-hover:bg-zinc-700/80",
)}
>
{icon}
</span>
)}
<div className="flex h-full flex-col justify-start gap-1 leading-none font-normal text-zinc-100">
{title}
{children && (
<p
className={cn(
"line-clamp-2 text-sm leading-tight font-light text-zinc-500",
backgroundImage && "relative z-[2]",
)}
>
{children}
</p>
)}
</div>
</div>
</a>
</li>
);
},
);
export function NavbarMenu({ activeMenu, sections }: NavbarMenuProps) {
const activeSection = sections.find((section) => section.id === activeMenu);
if (!activeSection) return null;
const gridLayout =
activeSection.gridLayout || "grid w-full grid-cols-2 gap-4";
return (
<motion.div
initial={{ scaleY: 0.95, opacity: 0 }}
animate={{ scaleY: 1, opacity: 1 }}
exit={{ scaleY: 0.95, opacity: 0 }}
transition={{
ease: [0.19, 1, 0.15, 1.01],
}}
className={cn(
"absolute top-full left-0 z-40 w-full origin-top overflow-hidden rounded-b-2xl border-1 border-y-0 border-white/5 bg-gradient-to-b from-zinc-950 to-zinc-900/30 backdrop-blur-2xl outline-none",
)}
>
<div className="p-6">
<ul className={gridLayout}>
{activeSection.links.map((link) => (
<ListItem
key={link.href}
href={link.href}
title={link.label}
external={link.external}
icon={link.icon}
backgroundImage={link.backgroundImage}
rowSpan={link.rowSpan}
>
{link.description}
</ListItem>
))}
</ul>
</div>
</motion.div>
);
}
export function NavbarWithMenu({
sections,
navItems,
logo,
cta,
}: NavbarWithMenuProps) {
const [activeDropdown, setActiveDropdown] = React.useState<string | null>(
null,
);
const [hoveredItem, setHoveredItem] = React.useState<string | null>(null);
const defaultNavItems = [
{ type: "dropdown", label: "Product", menu: "product" },
{ type: "dropdown", label: "Resources", menu: "resources" },
{ type: "dropdown", label: "Socials", menu: "socials" },
] as const;
const items = navItems || defaultNavItems;
const handleNavbarMouseLeave = () => {
setActiveDropdown(null);
setHoveredItem(null);
};
const handleMouseEnter = (menu: string) => {
setActiveDropdown(menu);
setHoveredItem(menu);
};
return (
<div className="min-h-[350px] w-full bg-zinc-950 p-4 flex items-start justify-center transition">
{/* biome-ignore lint/a11y/noStaticElementInteractions: Hover container for menu, not interactive content */}
<div
className="relative mx-auto w-screen max-w-4xl"
onMouseLeave={handleNavbarMouseLeave}
>
<div
className={cn(
"navbar_content flex h-14 w-full items-center justify-between border border-white/5 px-3 backdrop-blur-md transition-all",
activeDropdown
? "rounded-t-2xl border-b-0 bg-zinc-950"
: "rounded-2xl bg-zinc-900/30",
)}
>
<div className="flex items-center gap-2 px-2">
{logo || (
<Image
src="/media/text_w_logo_white.webp"
alt="Logo"
width={100}
height={30}
className="object-contain"
/>
)}
</div>
<div className="flex items-center gap-1 rounded-lg px-1 py-1">
{items.map((item) =>
item.type === "link" ? (
<button
type="button"
key={item.href}
className={cn(
"relative flex h-9 cursor-pointer items-center rounded-xl px-4 py-2 text-sm transition-colors hover:bg-zinc-800/40",
hoveredItem === item.label.toLowerCase()
? "text-zinc-100"
: "text-zinc-400 hover:text-zinc-100",
)}
onMouseEnter={() => {
setHoveredItem(item.label.toLowerCase());
setActiveDropdown(null);
}}
>
<span className="relative z-10">{item.label}</span>
</button>
) : (
<button
type="button"
key={item.menu}
className="relative flex h-9 cursor-pointer items-center rounded-xl px-4 py-2 text-sm text-zinc-400 capitalize transition-colors hover:text-zinc-100"
onMouseEnter={() => handleMouseEnter(item.menu)}
>
{hoveredItem === item.menu && (
<div className="absolute inset-0 h-full w-full rounded-xl bg-zinc-800 transition-all duration-300 ease-out" />
)}
<div className="relative z-10 flex items-center gap-2">
<span>
{item.label.charAt(0).toUpperCase() + item.label.slice(1)}
</span>
<HugeiconsIcon
icon={ArrowDown01Icon}
size={17}
className={cn(
"transition duration-200",
hoveredItem === item.menu && "rotate-180",
)}
/>
</div>
</button>
),
)}
</div>
<div className="flex items-center gap-2">
{cta || <RaisedButton color="#00bbff">Get Started</RaisedButton>}
</div>
</div>
<AnimatePresence>
{activeDropdown && (
<NavbarMenu activeMenu={activeDropdown} sections={sections} />
)}
</AnimatePresence>
</div>
</div>
);
}
Update the import paths to match your project setup.