You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import Textarea from '@/app/components/base/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 system-xs-semibold text-text-primary'>{name}</div>
  32. <Textarea
  33. value={content}
  34. onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => onChange(e.target.value)}
  35. placeholder={placeholder}
  36. autoFocus
  37. />
  38. </div>
  39. </div>
  40. )
  41. }
  42. export default React.memo(EditItem)