sidebar.tsx100 lines, 2.2 KB
| 1 | "use client"; |
| 2 | |
| 3 | import { cn } from "@/lib/utils"; |
| 4 | import { FileText, Home, LayoutDashboard, Settings } from "lucide-react"; |
| 5 | import Link from "next/link"; |
| 6 | import { usePathname } from "next/navigation"; |
| 7 | import { ElementType } from "react"; |
| 8 | |
| 9 | export const Sidebar = () => { |
| 10 | return ( |
| 11 | <aside className="bg-white text-black border-r border-gray-200 w-[280px] min-h-screen hidden lg:block"> |
| 12 | {SidebarContent()} |
| 13 | </aside> |
| 14 | ); |
| 15 | }; |
| 16 | |
| 17 | const SidebarContent = () => { |
| 18 | const pathname = usePathname(); |
| 19 | |
| 20 | const sidebarItems = [ |
| 21 | { |
| 22 | icon: Home, |
| 23 | label: "Home", |
| 24 | href: "/", |
| 25 | }, |
| 26 | { |
| 27 | icon: LayoutDashboard, |
| 28 | label: "Dashboard", |
| 29 | href: "/dashboard", |
| 30 | }, |
| 31 | { |
| 32 | icon: FileText, |
| 33 | label: "Results", |
| 34 | href: "/dashboard/results", |
| 35 | }, |
| 36 | { |
| 37 | icon: Settings, |
| 38 | label: "Settings", |
| 39 | href: "/dashboard/settings", |
| 40 | }, |
| 41 | ]; |
| 42 | |
| 43 | return ( |
| 44 | <div className="bg-white text-black h-full flex flex-col"> |
| 45 | <nav className="flex-grow p-6"> |
| 46 | <ul role="list" className="flex flex-col flex-grow"> |
| 47 | <li> |
| 48 | <ul role="list" className="-mx-2 space-y-1"> |
| 49 | {sidebarItems.map((item) => ( |
| 50 | <Navlink key={item.label} path={pathname} link={item} /> |
| 51 | ))} |
| 52 | </ul> |
| 53 | </li> |
| 54 | </ul> |
| 55 | </nav> |
| 56 | </div> |
| 57 | ); |
| 58 | }; |
| 59 | |
| 60 | const Navlink = ({ |
| 61 | path, |
| 62 | link, |
| 63 | }: { |
| 64 | path: string; |
| 65 | link: { |
| 66 | icon: ElementType; |
| 67 | label: string; |
| 68 | href: string; |
| 69 | target?: string; |
| 70 | }; |
| 71 | }) => { |
| 72 | return ( |
| 73 | <li key={link.label}> |
| 74 | <Link |
| 75 | href={link.href} |
| 76 | target={link.target} |
| 77 | className={cn( |
| 78 | "group flex h-9 items-center gap-x-3 rounded-md px-3 text-sm font-semibold leading-5 text-black", |
| 79 | path === link.href ? "bg-gray-200" : "hover:bg-gray-200" |
| 80 | )} |
| 81 | > |
| 82 | <link.icon className="size-4 shrink-0" /> |
| 83 | {link.label} |
| 84 | </Link> |
| 85 | </li> |
| 86 | ); |
| 87 | }; |
| 88 | |
| 89 | interface DashboardLayoutProps { |
| 90 | children: React.ReactNode; |
| 91 | } |
| 92 | |
| 93 | export default function DashboardLayout({ children }: DashboardLayoutProps) { |
| 94 | return ( |
| 95 | <div className="flex h-screen bg-gray-100"> |
| 96 | <Sidebar /> |
| 97 | <div className="flex-1 flex flex-col overflow-hidden">{children}</div> |
| 98 | </div> |
| 99 | ); |
| 100 | } |