output-vars.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import cn from 'classnames'
  6. import { useBoolean } from 'ahooks'
  7. import { ChevronRight } from '@/app/components/base/icons/src/vender/line/arrows'
  8. type Props = {
  9. className?: string
  10. title?: string
  11. children: JSX.Element
  12. }
  13. const OutputVars: FC<Props> = ({
  14. className,
  15. title,
  16. children,
  17. }) => {
  18. const { t } = useTranslation()
  19. const [isFold, {
  20. toggle: toggleFold,
  21. }] = useBoolean(true)
  22. return (
  23. <div>
  24. <div
  25. onClick={toggleFold}
  26. className={cn(className, 'flex justify-between leading-[18px] text-[13px] font-semibold text-gray-700 uppercase cursor-pointer')}>
  27. <div>{title || t('workflow.nodes.common.outputVars')}</div>
  28. <ChevronRight className='w-4 h-4 text-gray-500 transform transition-transform' style={{ transform: isFold ? 'rotate(0deg)' : 'rotate(90deg)' }} />
  29. </div>
  30. {!isFold && (
  31. <div className='mt-2 space-y-1'>
  32. {children}
  33. </div>
  34. )}
  35. </div>
  36. )
  37. }
  38. type VarItemProps = {
  39. name: string
  40. type: string
  41. description: string
  42. subItems?: {
  43. name: string
  44. type: string
  45. description: string
  46. }[]
  47. }
  48. export const VarItem: FC<VarItemProps> = ({
  49. name,
  50. type,
  51. description,
  52. subItems,
  53. }) => {
  54. return (
  55. <div className='py-1'>
  56. <div className='flex leading-[18px] items-center'>
  57. <div className='text-[13px] font-medium text-gray-900 font-mono'>{name}</div>
  58. <div className='ml-2 text-xs font-normal text-gray-500 capitalize'>{type}</div>
  59. </div>
  60. <div className='mt-0.5 leading-[18px] text-xs font-normal text-gray-600'>
  61. {description}
  62. {subItems && (
  63. <div className='ml-2 border-l border-gray-200 pl-2'>
  64. {subItems.map((item, index) => (
  65. <VarItem
  66. key={index}
  67. name={item.name}
  68. type={item.type}
  69. description={item.description}
  70. />
  71. ))}
  72. </div>
  73. )}
  74. </div>
  75. </div>
  76. )
  77. }
  78. export default React.memo(OutputVars)