form-input.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import type { FC } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import { memo } from 'react'
  4. type InputProps = {
  5. form: any
  6. value: string
  7. onChange: (variable: string, value: string) => void
  8. }
  9. const FormInput: FC<InputProps> = ({
  10. form,
  11. value,
  12. onChange,
  13. }) => {
  14. const { t } = useTranslation()
  15. const {
  16. type,
  17. label,
  18. required,
  19. max_length,
  20. variable,
  21. } = form
  22. if (type === 'paragraph') {
  23. return (
  24. <textarea
  25. value={value}
  26. className='grow h-[104px] rounded-lg bg-gray-100 px-2.5 py-2 outline-none appearance-none resize-none'
  27. onChange={e => onChange(variable, e.target.value)}
  28. placeholder={`${label}${!required ? `(${t('appDebug.variableTable.optional')})` : ''}`}
  29. />
  30. )
  31. }
  32. return (
  33. <input
  34. className='grow h-9 rounded-lg bg-gray-100 px-2.5 outline-none appearance-none'
  35. value={value || ''}
  36. maxLength={max_length}
  37. onChange={e => onChange(variable, e.target.value)}
  38. placeholder={`${label}${!required ? `(${t('appDebug.variableTable.optional')})` : ''}`}
  39. />
  40. )
  41. }
  42. export default memo(FormInput)