tabs.tsx 1.9 KB

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