-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnav-menu.tsx
42 lines (38 loc) · 1.44 KB
/
nav-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
"use client";
import { cn } from "@/lib/utils";
import { NavigationMenu, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, navigationMenuTriggerStyle } from "./ui/navigation-menu";
import { usePathname, useSelectedLayoutSegment, useSelectedLayoutSegments } from "next/navigation";
import Link from "next/link";
interface NavMenuProps {
basePath: string;
navItems: {
label: string;
path?: string;
}[];
};
export const NavMenu = ({
basePath,
navItems
}: NavMenuProps) => {
const segment = useSelectedLayoutSegment();
return (
<NavigationMenu className="border rounded-lg mb-8 p-1">
<NavigationMenuList className="rounded-sm">
{navItems.map((item, index) => (
<NavigationMenuItem key={index}>
<Link href={`${basePath}/${item.path}`} legacyBehavior passHref>
<NavigationMenuLink
className={cn(
navigationMenuTriggerStyle(),
item.path === (segment || "") && "bg-primary/10 text-primary-500",
)}
>
{item.label}
</NavigationMenuLink>
</Link>
</NavigationMenuItem>
))}
</NavigationMenuList>
</NavigationMenu>
)
};