index.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use client'
  2. import React, { useState } from 'react'
  3. import Link from 'next/link'
  4. import { useSelectedLayoutSegment } from 'next/navigation'
  5. import classNames from 'classnames'
  6. import { ArrowLeftIcon } from '@heroicons/react/24/solid'
  7. import type { INavSelectorProps } from './nav-selector'
  8. import NavSelector from './nav-selector'
  9. type INavProps = {
  10. icon: React.ReactNode
  11. text: string
  12. activeSegment: string | string[]
  13. link: string
  14. } & INavSelectorProps
  15. const Nav = ({
  16. icon,
  17. text,
  18. activeSegment,
  19. link,
  20. curNav,
  21. navs,
  22. createText,
  23. onCreate,
  24. onLoadmore,
  25. }: INavProps) => {
  26. const [hovered, setHovered] = useState(false)
  27. const segment = useSelectedLayoutSegment()
  28. const isActived = Array.isArray(activeSegment) ? activeSegment.includes(segment!) : segment === activeSegment
  29. return (
  30. <div className={`
  31. flex items-center h-8 mr-3 px-0.5 rounded-xl text-[14px] shrink-0
  32. ${isActived && 'bg-white shadow-[0_2px_5px_-1px_rgba(0,0,0,0.05),0_2px_4px_-2px_rgba(0,0,0,0.05)]'}
  33. `}>
  34. <Link href={link}>
  35. <div
  36. className={classNames(`
  37. flex items-center h-7 pl-2.5 pr-2
  38. font-semibold cursor-pointer rounded-[10px]
  39. ${isActived ? 'text-[#1C64F2]' : 'text-gray-500 hover:bg-gray-200'}
  40. ${curNav && isActived && 'hover:bg-[#EBF5FF]'}
  41. `)}
  42. onMouseEnter={() => setHovered(true)}
  43. onMouseLeave={() => setHovered(false)}
  44. >
  45. {
  46. (hovered && curNav && isActived)
  47. ? <ArrowLeftIcon className='mr-1 w-[18px] h-[18px]' />
  48. : icon
  49. }
  50. {text}
  51. </div>
  52. </Link>
  53. {
  54. curNav && isActived && (
  55. <>
  56. <div className='font-light text-gray-300 '>/</div>
  57. <NavSelector
  58. curNav={curNav}
  59. navs={navs}
  60. createText={createText}
  61. onCreate={onCreate}
  62. onLoadmore={onLoadmore}
  63. />
  64. </>
  65. )
  66. }
  67. </div>
  68. )
  69. }
  70. export default Nav