index.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. }: INavProps) => {
  25. const [hovered, setHovered] = useState(false)
  26. const segment = useSelectedLayoutSegment()
  27. const isActived = Array.isArray(activeSegment) ? activeSegment.includes(segment!) : segment === activeSegment
  28. return (
  29. <div className={`
  30. flex items-center h-8 mr-3 px-0.5 rounded-xl text-[14px] shrink-0
  31. ${isActived && 'bg-white shadow-[0_2px_5px_-1px_rgba(0,0,0,0.05),0_2px_4px_-2px_rgba(0,0,0,0.05)]'}
  32. `}>
  33. <Link href={link}>
  34. <div
  35. className={classNames(`
  36. flex items-center h-8 pl-2.5 pr-2
  37. font-semibold cursor-pointer rounded-[10px]
  38. ${isActived ? 'text-[#1C64F2]' : 'text-gray-500 hover:bg-gray-200'}
  39. ${curNav && isActived && 'hover:bg-[#EBF5FF]'}
  40. `)}
  41. onMouseEnter={() => setHovered(true)}
  42. onMouseLeave={() => setHovered(false)}
  43. >
  44. {
  45. (hovered && curNav && isActived)
  46. ? <ArrowLeftIcon className='mr-1 w-[18px] h-[18px]' />
  47. : icon
  48. }
  49. {text}
  50. </div>
  51. </Link>
  52. {
  53. curNav && isActived && (
  54. <>
  55. <div className='font-light text-gray-300 '>/</div>
  56. <NavSelector
  57. curNav={curNav}
  58. navs={navs}
  59. createText={createText}
  60. onCreate={onCreate}
  61. />
  62. </>
  63. )
  64. }
  65. </div>
  66. )
  67. }
  68. export default Nav