class-item.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useCallback } from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import type { Topic } from '../types'
  6. import TextEditor from '../../_base/components/editor/text-editor'
  7. import { Trash03 } from '@/app/components/base/icons/src/vender/line/general'
  8. const i18nPrefix = 'workflow.nodes.questionClassifiers'
  9. type Props = {
  10. payload: Topic
  11. onChange: (payload: Topic) => void
  12. onRemove: () => void
  13. index: number
  14. readonly?: boolean
  15. }
  16. const ClassItem: FC<Props> = ({
  17. payload,
  18. onChange,
  19. onRemove,
  20. index,
  21. readonly,
  22. }) => {
  23. const { t } = useTranslation()
  24. const handleNameChange = useCallback((value: string) => {
  25. onChange({ ...payload, name: value })
  26. }, [onChange, payload])
  27. return (
  28. <TextEditor
  29. isInNode
  30. title={<div>
  31. <div className='w-[200px]'>
  32. <div
  33. className='leading-4 text-xs font-semibold text-gray-700'
  34. >
  35. {`${t(`${i18nPrefix}.class`)} ${index}`}
  36. </div>
  37. </div>
  38. </div>}
  39. value={payload.name}
  40. onChange={handleNameChange}
  41. placeholder={t(`${i18nPrefix}.topicPlaceholder`)!}
  42. headerRight={(
  43. <div className='flex items-center h-full'>
  44. <div className='text-xs font-medium text-gray-500'>{payload.name.length}</div>
  45. <div className='mx-3 h-3 w-px bg-gray-200'></div>
  46. {!readonly && (
  47. <Trash03
  48. className='mr-1 w-3.5 h-3.5 text-gray-500 cursor-pointer'
  49. onClick={onRemove}
  50. />
  51. )}
  52. </div>
  53. )}
  54. readonly={readonly}
  55. minHeight={64}
  56. />
  57. )
  58. }
  59. export default React.memo(ClassItem)