navLink.tsx 1010 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use client'
  2. import { useSelectedLayoutSegment } from 'next/navigation'
  3. import classNames from 'classnames'
  4. import Link from 'next/link'
  5. export default function NavLink({
  6. name,
  7. href,
  8. iconMap,
  9. }: {
  10. name: string
  11. href: string
  12. iconMap: { selected: any; normal: any }
  13. }) {
  14. const segment = useSelectedLayoutSegment()
  15. const isActive = href.toLowerCase().split('/')?.pop() === segment?.toLowerCase()
  16. const NavIcon = isActive ? iconMap.selected : iconMap.normal
  17. return (
  18. <Link
  19. prefetch
  20. key={name}
  21. href={href}
  22. className={classNames(
  23. isActive ? 'bg-primary-50 text-primary-600 font-semibold' : 'text-gray-700 hover:bg-gray-100 hover:text-gray-700',
  24. 'group flex items-center rounded-md px-2 py-2 text-sm font-normal',
  25. )}
  26. >
  27. <NavIcon
  28. className={classNames(
  29. 'mr-2 h-4 w-4 flex-shrink-0',
  30. isActive ? 'text-primary-600' : 'text-gray-700',
  31. )}
  32. aria-hidden="true"
  33. />
  34. {name}
  35. </Link>
  36. )
  37. }