output-vars.tsx 2.0 KB

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