navLink.tsx 995 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. key={name}
  20. href={href}
  21. className={classNames(
  22. isActive ? 'bg-primary-50 text-primary-600 font-semibold' : 'text-gray-700 hover:bg-gray-100 hover:text-gray-700',
  23. 'group flex items-center rounded-md px-2 py-2 text-sm font-normal',
  24. )}
  25. >
  26. <NavIcon
  27. className={classNames(
  28. 'mr-2 h-4 w-4 flex-shrink-0',
  29. isActive ? 'text-primary-600' : 'text-gray-700',
  30. )}
  31. aria-hidden="true"
  32. />
  33. {name}
  34. </Link>
  35. )
  36. }