index.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. 'use client'
  2. import React, { useState } from 'react'
  3. import Link from 'next/link'
  4. import { useSelectedLayoutSegment } from 'next/navigation'
  5. import type { INavSelectorProps } from './nav-selector'
  6. import NavSelector from './nav-selector'
  7. import classNames from '@/utils/classnames'
  8. import { ArrowNarrowLeft } from '@/app/components/base/icons/src/vender/line/arrows'
  9. import { useStore as useAppStore } from '@/app/components/app/store'
  10. type INavProps = {
  11. icon: React.ReactNode
  12. activeIcon?: React.ReactNode
  13. text: string
  14. activeSegment: string | string[]
  15. link: string
  16. isApp: boolean
  17. } & INavSelectorProps
  18. const Nav = ({
  19. icon,
  20. activeIcon,
  21. text,
  22. activeSegment,
  23. link,
  24. curNav,
  25. navs,
  26. createText,
  27. onCreate,
  28. onLoadmore,
  29. isApp,
  30. }: INavProps) => {
  31. const setAppDetail = useAppStore(state => state.setAppDetail)
  32. const [hovered, setHovered] = useState(false)
  33. const segment = useSelectedLayoutSegment()
  34. const isActivated = Array.isArray(activeSegment) ? activeSegment.includes(segment!) : segment === activeSegment
  35. return (
  36. <div className={`
  37. flex items-center h-8 mr-0 sm:mr-3 px-0.5 rounded-xl text-sm shrink-0 font-medium
  38. ${isActivated && 'bg-components-main-nav-nav-button-bg-active shadow-md font-semibold'}
  39. ${!curNav && !isActivated && 'hover:bg-components-main-nav-nav-button-bg-hover'}
  40. `}>
  41. <Link href={link}>
  42. <div
  43. onClick={() => setAppDetail()}
  44. className={classNames(`
  45. flex items-center h-7 px-2.5 cursor-pointer rounded-[10px]
  46. ${isActivated ? 'text-components-main-nav-nav-button-text-active' : 'text-components-main-nav-nav-button-text'}
  47. ${curNav && isActivated && 'hover:bg-components-main-nav-nav-button-bg-active-hover'}
  48. `)}
  49. onMouseEnter={() => setHovered(true)}
  50. onMouseLeave={() => setHovered(false)}
  51. >
  52. <div className='mr-2'>
  53. {
  54. (hovered && curNav)
  55. ? <ArrowNarrowLeft className='w-4 h-4' />
  56. : isActivated
  57. ? activeIcon
  58. : icon
  59. }
  60. </div>
  61. {text}
  62. </div>
  63. </Link>
  64. {
  65. curNav && isActivated && (
  66. <>
  67. <div className='font-light text-gray-300 '>/</div>
  68. <NavSelector
  69. isApp={isApp}
  70. curNav={curNav}
  71. navs={navs}
  72. createText={createText}
  73. onCreate={onCreate}
  74. onLoadmore={onLoadmore}
  75. />
  76. </>
  77. )
  78. }
  79. </div>
  80. )
  81. }
  82. export default Nav