Skip to main content

Navbar

Create a file at components/Navbar.tsx:

"use client"

import { useState } from "react"
import Link from "next/link"
import { Menu, X, ChevronDown, User } from "lucide-react"

import { Button } from "@/components/ui/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"

export default function Navbar() {
const [isMenuOpen, setIsMenuOpen] = useState(false)

return (
<nav className="bg-white shadow-md">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex items-center justify-between h-16">
<div className="flex items-center">
<div className="flex-shrink-0">
<Link href="/" className="text-xl font-bold text-gray-800">
Logo
</Link>
</div>
<div className="hidden md:block">
<div className="ml-10 flex items-baseline space-x-4">
<Link href="/" className="text-gray-600 hover:text-gray-900 px-3 py-2 rounded-md text-sm font-medium">
Home
</Link>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="flex items-center text-gray-600 hover:text-gray-900 px-3 py-2 rounded-md text-sm font-medium">
Products <ChevronDown className="ml-1 h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem>
<Link href="/products/category1">Category 1</Link>
</DropdownMenuItem>
<DropdownMenuItem>
<Link href="/products/category2">Category 2</Link>
</DropdownMenuItem>
<DropdownMenuItem>
<Link href="/products/category3">Category 3</Link>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<Link href="/about" className="text-gray-600 hover:text-gray-900 px-3 py-2 rounded-md text-sm font-medium">
About
</Link>
<Link href="/contact" className="text-gray-600 hover:text-gray-900 px-3 py-2 rounded-md text-sm font-medium">
Contact
</Link>
</div>
</div>
</div>
<div className="hidden md:block">
<div className="ml-4 flex items-center md:ml-6">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="flex items-center">
<Avatar>
<AvatarImage src="/placeholder-avatar.jpg" alt="User" />
<AvatarFallback>
<User className="h-5 w-5" />
</AvatarFallback>
</Avatar>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem>
<Link href="/profile">Profile</Link>
</DropdownMenuItem>
<DropdownMenuItem>
<Link href="/settings">Settings</Link>
</DropdownMenuItem>
<DropdownMenuItem>
<Link href="/logout">Logout</Link>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
<div className="flex md:hidden">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" size="icon" className="mr-2">
<Avatar>
<AvatarImage src="/placeholder-avatar.jpg" alt="User" />
<AvatarFallback>
<User className="h-5 w-5" />
</AvatarFallback>
</Avatar>
<span className="sr-only">Open user menu</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem>
<Link href="/profile">Profile</Link>
</DropdownMenuItem>
<DropdownMenuItem>
<Link href="/settings">Settings</Link>
</DropdownMenuItem>
<DropdownMenuItem>
<Link href="/logout">Logout</Link>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<Button
variant="ghost"
size="icon"
onClick={() => setIsMenuOpen(!isMenuOpen)}
aria-label="Toggle menu"
>
{isMenuOpen ? (
<X className="h-6 w-6" />
) : (
<Menu className="h-6 w-6" />
)}
</Button>
</div>
</div>
</div>
{isMenuOpen && (
<div className="md:hidden">
<div className="px-2 pt-2 pb-3 space-y-1 sm:px-3">
<Link href="/" className="text-gray-600 hover:text-gray-900 block px-3 py-2 rounded-md text-base font-medium">
Home
</Link>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="w-full justify-start text-gray-600 hover:text-gray-900 px-3 py-2 rounded-md text-base font-medium">
Products <ChevronDown className="ml-1 h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem>
<Link href="/products/category1">Category 1</Link>
</DropdownMenuItem>
<DropdownMenuItem>
<Link href="/products/category2">Category 2</Link>
</DropdownMenuItem>
<DropdownMenuItem>
<Link href="/products/category3">Category 3</Link>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<Link href="/about" className="text-gray-600 hover:text-gray-900 block px-3 py-2 rounded-md text-base font-medium">
About
</Link>
<Link href="/contact" className="text-gray-600 hover:text-gray-900 block px-3 py-2 rounded-md text-base font-medium">
Contact
</Link>
</div>
</div>
)}
</nav>
)
}