|
| 1 | +"use client"; |
| 2 | + |
1 | 3 | import { |
2 | 4 | UserGroupIcon, |
3 | 5 | HomeIcon, |
4 | 6 | DocumentDuplicateIcon, |
5 | | -} from '@heroicons/react/24/outline'; |
| 7 | +} from "@heroicons/react/24/outline"; |
| 8 | +import clsx from "clsx"; |
| 9 | + |
| 10 | +import Link from "next/link"; |
| 11 | +import { usePathname } from "next/navigation"; |
6 | 12 |
|
7 | 13 | // Map of links to display in the side navigation. |
8 | 14 | // Depending on the size of the application, this would be stored in a database. |
9 | 15 | const links = [ |
10 | | - { name: 'Home', href: '/dashboard', icon: HomeIcon }, |
| 16 | + { name: "Home", href: "/dashboard", icon: HomeIcon }, |
11 | 17 | { |
12 | | - name: 'Invoices', |
13 | | - href: '/dashboard/invoices', |
| 18 | + name: "Invoices", |
| 19 | + href: "/dashboard/invoices", |
14 | 20 | icon: DocumentDuplicateIcon, |
15 | 21 | }, |
16 | | - { name: 'Customers', href: '/dashboard/customers', icon: UserGroupIcon }, |
| 22 | + { name: "Customers", href: "/dashboard/customers", icon: UserGroupIcon }, |
17 | 23 | ]; |
18 | 24 |
|
19 | 25 | export default function NavLinks() { |
| 26 | + const pathname = usePathname(); |
| 27 | + |
20 | 28 | return ( |
21 | 29 | <> |
22 | 30 | {links.map((link) => { |
23 | 31 | const LinkIcon = link.icon; |
24 | 32 | return ( |
25 | | - <a |
| 33 | + <Link |
26 | 34 | key={link.name} |
27 | 35 | href={link.href} |
28 | | - className="flex h-[48px] grow items-center justify-center gap-2 rounded-md bg-gray-50 p-3 text-sm font-medium hover:bg-sky-100 hover:text-blue-600 md:flex-none md:justify-start md:p-2 md:px-3" |
| 36 | + className={clsx( |
| 37 | + "flex h-[48px] grow items-center justify-center gap-2 rounded-md bg-gray-50 p-3 text-sm font-medium hover:bg-sky-100 hover:text-blue-600 md:flex-none md:justify-start md:p-2 md:px-3", |
| 38 | + { "bg-sky-100 text-blue-600": pathname === link.href } |
| 39 | + )} |
29 | 40 | > |
30 | 41 | <LinkIcon className="w-6" /> |
31 | 42 | <p className="hidden md:block">{link.name}</p> |
32 | | - </a> |
| 43 | + </Link> |
33 | 44 | ); |
34 | 45 | })} |
35 | 46 | </> |
|
0 commit comments