index.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. 'use client'
  2. import { Fragment } from 'react'
  3. import { ChevronDownIcon, PlusIcon } from '@heroicons/react/24/solid'
  4. import { Menu, Transition } from '@headlessui/react'
  5. import { useRouter } from 'next/navigation'
  6. import Indicator from '../../indicator'
  7. import AppIcon from '@/app/components/base/app-icon'
  8. type NavItem = {
  9. id: string
  10. name: string
  11. link: string
  12. }
  13. export interface INavSelectorProps {
  14. navs: NavItem[]
  15. curNav?: Omit<NavItem, 'link'>
  16. createText: string
  17. onCreate: () => void
  18. }
  19. const itemClassName = `
  20. flex items-center w-full h-10 px-3 text-gray-700 text-[14px]
  21. rounded-lg font-normal hover:bg-gray-100 cursor-pointer
  22. `
  23. const NavSelector = ({ curNav, navs, createText, onCreate }: INavSelectorProps) => {
  24. const router = useRouter()
  25. return (
  26. <div className="">
  27. <Menu as="div" className="relative inline-block text-left">
  28. <div>
  29. <Menu.Button
  30. className="
  31. inline-flex items-center w-full h-7 justify-center
  32. rounded-[10px] pl-2 pr-2.5 text-[14px] font-semibold
  33. text-[#1C64F2] hover:bg-[#EBF5FF]
  34. "
  35. >
  36. {curNav?.name}
  37. <ChevronDownIcon
  38. className="w-3 h-3 ml-1"
  39. aria-hidden="true"
  40. />
  41. </Menu.Button>
  42. </div>
  43. <Transition
  44. as={Fragment}
  45. enter="transition ease-out duration-100"
  46. enterFrom="transform opacity-0 scale-95"
  47. enterTo="transform opacity-100 scale-100"
  48. leave="transition ease-in duration-75"
  49. leaveFrom="transform opacity-100 scale-100"
  50. leaveTo="transform opacity-0 scale-95"
  51. >
  52. <Menu.Items
  53. className="
  54. absolute -left-11 right-0 mt-1.5 w-60 max-w-80
  55. divide-y divide-gray-100 origin-top-right rounded-lg bg-white
  56. shadow-[0_10px_15px_-3px_rgba(0,0,0,0.1),0_4px_6px_rgba(0,0,0,0.05)]
  57. "
  58. >
  59. <div className="px-1 py-1 overflow-auto" style={{ maxHeight: '50vh' }}>
  60. {
  61. navs.map((nav) => (
  62. <Menu.Item key={nav.id}>
  63. <div className={itemClassName} onClick={() => router.push(nav.link)}>
  64. <div className='relative w-6 h-6 mr-2 bg-[#D5F5F6] rounded-[6px]'>
  65. <AppIcon size='tiny' />
  66. <div className='flex justify-center items-center absolute -right-0.5 -bottom-0.5 w-2.5 h-2.5 bg-white rounded'>
  67. <Indicator />
  68. </div>
  69. </div>
  70. {nav.name}
  71. </div>
  72. </Menu.Item>
  73. ))
  74. }
  75. </div>
  76. <Menu.Item>
  77. <div className='p-1' onClick={onCreate}>
  78. <div
  79. className='flex items-center h-12 rounded-lg cursor-pointer hover:bg-gray-100'
  80. >
  81. <div
  82. className='
  83. flex justify-center items-center
  84. ml-4 mr-2 w-6 h-6 bg-gray-100 rounded-[6px]
  85. border-[0.5px] border-gray-200 border-dashed
  86. '
  87. >
  88. <PlusIcon className='w-4 h-4 text-gray-500' />
  89. </div>
  90. <div className='font-normal text-[14px] text-gray-700'>{createText}</div>
  91. </div>
  92. </div>
  93. </Menu.Item>
  94. </Menu.Items>
  95. </Transition>
  96. </Menu>
  97. </div>
  98. )
  99. }
  100. export default NavSelector