form-input.tsx 1.1 KB

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