tabs.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import type { FC } from 'react'
  2. import { memo } from 'react'
  3. import type { BlockEnum } from '../types'
  4. import { useTabs } from './hooks'
  5. import type { ToolDefaultValue } from './types'
  6. import { TabsEnum } from './types'
  7. import Blocks from './blocks'
  8. import AllTools from './all-tools'
  9. import cn from '@/utils/classnames'
  10. export type TabsProps = {
  11. activeTab: TabsEnum
  12. onActiveTabChange: (activeTab: TabsEnum) => void
  13. searchText: string
  14. onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
  15. availableBlocksTypes?: BlockEnum[]
  16. noBlocks?: boolean
  17. }
  18. const Tabs: FC<TabsProps> = ({
  19. activeTab,
  20. onActiveTabChange,
  21. searchText,
  22. onSelect,
  23. availableBlocksTypes,
  24. noBlocks,
  25. }) => {
  26. const tabs = useTabs()
  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] text-[13px] leading-[34px] 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={() => onActiveTabChange(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)