index.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import Textarea from 'rc-textarea'
  6. import { Robot, User } from '@/app/components/base/icons/src/public/avatar'
  7. export enum EditItemType {
  8. Query = 'query',
  9. Answer = 'answer',
  10. }
  11. type Props = {
  12. type: EditItemType
  13. content: string
  14. onChange: (content: string) => void
  15. }
  16. const EditItem: FC<Props> = ({
  17. type,
  18. content,
  19. onChange,
  20. }) => {
  21. const { t } = useTranslation()
  22. const avatar = type === EditItemType.Query ? <User className='w-6 h-6' /> : <Robot className='w-6 h-6' />
  23. const name = type === EditItemType.Query ? t('appAnnotation.addModal.queryName') : t('appAnnotation.addModal.answerName')
  24. const placeholder = type === EditItemType.Query ? t('appAnnotation.addModal.queryPlaceholder') : t('appAnnotation.addModal.answerPlaceholder')
  25. return (
  26. <div className='flex' onClick={e => e.stopPropagation()}>
  27. <div className='shrink-0 mr-3'>
  28. {avatar}
  29. </div>
  30. <div className='grow'>
  31. <div className='mb-1 leading-[18px] text-xs font-semibold text-gray-900'>{name}</div>
  32. <Textarea
  33. className='mt-1 block w-full leading-5 max-h-none text-sm text-gray-700 outline-none appearance-none resize-none'
  34. value={content}
  35. onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => onChange(e.target.value)}
  36. autoSize={{ minRows: 3 }}
  37. placeholder={placeholder}
  38. autoFocus
  39. />
  40. </div>
  41. </div>
  42. )
  43. }
  44. export default React.memo(EditItem)