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