forked from shadcn-ui/taxonomy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain-nav.tsx
57 lines (52 loc) · 1.77 KB
/
main-nav.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
'use client'
import Link from 'next/link'
import { useSelectedLayoutSegment } from 'next/navigation'
import * as React from 'react'
import { MainNavItem } from 'types'
import { Icons } from '@/components/icons'
import { MobileNav } from '@/components/mobile-nav'
import { siteConfig } from '@/config/site'
import { cn } from '@/lib/utils'
interface MainNavProps {
items?: MainNavItem[]
children?: React.ReactNode
}
export function MainNav({ items, children }: MainNavProps) {
const segment = useSelectedLayoutSegment()
const [showMobileMenu, setShowMobileMenu] = React.useState<boolean>(false)
return (
<div className="flex gap-6 md:gap-10">
<Link href="/" className="hidden items-center space-x-2 md:flex">
<Icons.logo />
<span className="hidden font-bold sm:inline-block">
{siteConfig.name}
</span>
</Link>
{items?.length ? (
<nav className="hidden gap-6 md:flex">
{items?.map((item, index) => (
<Link
key={index}
href={item.disabled ? '#' : item.href}
className={cn(
'flex items-center text-lg font-semibold text-slate-600 sm:text-sm',
item.href.startsWith(`/${segment}`) && 'text-slate-900',
item.disabled && 'cursor-not-allowed opacity-80'
)}
>
{item.title}
</Link>
))}
</nav>
) : null}
<button
className="flex items-center space-x-2 md:hidden"
onClick={() => setShowMobileMenu(!showMobileMenu)}
>
{showMobileMenu ? <Icons.close /> : <Icons.logo />}
<span className="font-bold">Menu</span>
</button>
{showMobileMenu && <MobileNav items={items}>{children}</MobileNav>}
</div>
)
}