class-item.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. title={<div>
  30. <div className='w-[200px]'>
  31. <div
  32. className='leading-4 text-xs font-semibold text-gray-700'
  33. >
  34. {`${t(`${i18nPrefix}.class`)} ${index}`}
  35. </div>
  36. </div>
  37. </div>}
  38. value={payload.name}
  39. onChange={handleNameChange}
  40. placeholder={t(`${i18nPrefix}.topicPlaceholder`)!}
  41. headerRight={(
  42. <div className='flex items-center h-full'>
  43. <div className='text-xs font-medium text-gray-500'>{payload.name.length}</div>
  44. <div className='mx-3 h-3 w-px bg-gray-200'></div>
  45. {!readonly && (
  46. <Trash03
  47. className='mr-1 w-3.5 h-3.5 text-gray-500 cursor-pointer'
  48. onClick={onRemove}
  49. />
  50. )}
  51. </div>
  52. )}
  53. readonly={readonly}
  54. minHeight={64}
  55. />
  56. )
  57. }
  58. export default React.memo(ClassItem)