class-item.tsx 1.6 KB

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