tabs.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import type { FC } from 'react'
  2. import {
  3. memo,
  4. useState,
  5. } from 'react'
  6. import cn from 'classnames'
  7. import type { BlockEnum } from '../types'
  8. import { useTabs } from './hooks'
  9. import type { ToolDefaultValue } from './types'
  10. import { TabsEnum } from './types'
  11. import Blocks from './blocks'
  12. import AllTools from './all-tools'
  13. export type TabsProps = {
  14. searchText: string
  15. onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
  16. availableBlocksTypes?: BlockEnum[]
  17. noBlocks?: boolean
  18. }
  19. const Tabs: FC<TabsProps> = ({
  20. searchText,
  21. onSelect,
  22. availableBlocksTypes,
  23. noBlocks,
  24. }) => {
  25. const tabs = useTabs()
  26. const [activeTab, setActiveTab] = useState(noBlocks ? TabsEnum.Tools : TabsEnum.Blocks)
  27. return (
  28. <div onClick={e => e.stopPropagation()}>
  29. {
  30. !noBlocks && (
  31. <div className='flex items-center px-3 border-b-[0.5px] border-b-black/5'>
  32. {
  33. tabs.map(tab => (
  34. <div
  35. key={tab.key}
  36. className={cn(
  37. 'relative mr-4 h-[34px] leading-[34px] text-[13px] font-medium cursor-pointer',
  38. activeTab === tab.key
  39. ? 'text-gray-700 after:absolute after:bottom-0 after:left-0 after:h-0.5 after:w-full after:bg-primary-600'
  40. : 'text-gray-500',
  41. )}
  42. onClick={() => setActiveTab(tab.key)}
  43. >
  44. {tab.name}
  45. </div>
  46. ))
  47. }
  48. </div>
  49. )
  50. }
  51. {
  52. activeTab === TabsEnum.Blocks && !noBlocks && (
  53. <Blocks
  54. searchText={searchText}
  55. onSelect={onSelect}
  56. availableBlocksTypes={availableBlocksTypes}
  57. />
  58. )
  59. }
  60. {
  61. activeTab === TabsEnum.Tools && (
  62. <AllTools
  63. searchText={searchText}
  64. onSelect={onSelect}
  65. />
  66. )
  67. }
  68. </div>
  69. )
  70. }
  71. export default memo(Tabs)