tabs.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import type { FC } from 'react'
  2. import { memo } from 'react'
  3. import { useAllBuiltInTools, useAllCustomTools, useAllWorkflowTools } from '@/service/use-tools'
  4. import type { BlockEnum } from '../types'
  5. import { useTabs } from './hooks'
  6. import type { ToolDefaultValue } from './types'
  7. import { TabsEnum } from './types'
  8. import Blocks from './blocks'
  9. import AllTools from './all-tools'
  10. import cn from '@/utils/classnames'
  11. export type TabsProps = {
  12. activeTab: TabsEnum
  13. onActiveTabChange: (activeTab: TabsEnum) => void
  14. searchText: string
  15. tags: string[]
  16. onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
  17. availableBlocksTypes?: BlockEnum[]
  18. noBlocks?: boolean
  19. }
  20. const Tabs: FC<TabsProps> = ({
  21. activeTab,
  22. onActiveTabChange,
  23. tags,
  24. searchText,
  25. onSelect,
  26. availableBlocksTypes,
  27. noBlocks,
  28. }) => {
  29. const tabs = useTabs()
  30. const { data: buildInTools } = useAllBuiltInTools()
  31. const { data: customTools } = useAllCustomTools()
  32. const { data: workflowTools } = useAllWorkflowTools()
  33. return (
  34. <div onClick={e => e.stopPropagation()}>
  35. {
  36. !noBlocks && (
  37. <div className='flex items-center px-3 border-b-[0.5px] border-divider-subtle'>
  38. {
  39. tabs.map(tab => (
  40. <div
  41. key={tab.key}
  42. className={cn(
  43. 'relative mr-4 pt-1 pb-2 system-sm-medium cursor-pointer',
  44. activeTab === tab.key
  45. ? 'text-text-primary after:absolute after:bottom-0 after:left-0 after:h-0.5 after:w-full after:bg-util-colors-blue-brand-blue-brand-600'
  46. : 'text-text-tertiary',
  47. )}
  48. onClick={() => onActiveTabChange(tab.key)}
  49. >
  50. {tab.name}
  51. </div>
  52. ))
  53. }
  54. </div>
  55. )
  56. }
  57. {
  58. activeTab === TabsEnum.Blocks && !noBlocks && (
  59. <Blocks
  60. searchText={searchText}
  61. onSelect={onSelect}
  62. availableBlocksTypes={availableBlocksTypes}
  63. />
  64. )
  65. }
  66. {
  67. activeTab === TabsEnum.Tools && (
  68. <AllTools
  69. className='w-[315px]'
  70. searchText={searchText}
  71. onSelect={onSelect}
  72. tags={tags}
  73. buildInTools={buildInTools || []}
  74. customTools={customTools || []}
  75. workflowTools={workflowTools || []}
  76. />
  77. )
  78. }
  79. </div>
  80. )
  81. }
  82. export default memo(Tabs)