Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3000 | Rev 3238 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
2073 stevensc 1
import React from 'react'
2080 stevensc 2
import {
3
  FormControl,
4
  InputAdornment,
5
  InputBase,
2843 stevensc 6
  InputLabel
2080 stevensc 7
} from '@mui/material'
2773 stevensc 8
import { Controller } from 'react-hook-form'
9
 
2080 stevensc 10
import FormErrorFeedback from '../form/FormErrorFeedback'
2073 stevensc 11
 
2080 stevensc 12
const Input = ({
2773 stevensc 13
  name,
14
  control,
2081 stevensc 15
  label,
2773 stevensc 16
  rules,
2791 stevensc 17
  defaultValue,
2773 stevensc 18
  onChange,
2791 stevensc 19
  value,
2773 stevensc 20
  icon,
2081 stevensc 21
  accept,
2773 stevensc 22
  error,
3234 stevensc 23
  style,
2773 stevensc 24
  ...props
2080 stevensc 25
}) => {
2773 stevensc 26
  if (control) {
27
    return (
28
      <Controller
29
        name={name}
30
        control={control}
31
        defaultValue={defaultValue}
32
        rules={rules}
2794 stevensc 33
        render={({ field }) => (
2773 stevensc 34
          <FormControl variant='standard' fullWidth>
3000 stevensc 35
            {label && <InputLabel shrink>{label}</InputLabel>}
2773 stevensc 36
 
2843 stevensc 37
            <InputBase
2773 stevensc 38
              {...field}
39
              inputProps={{
40
                accept
41
              }}
42
              startAdornment={
43
                icon ? <InputAdornment>{icon}</InputAdornment> : null
44
              }
45
              fullWidth
3234 stevensc 46
              sx={style}
2773 stevensc 47
              {...props}
48
            />
49
 
50
            {error ? <FormErrorFeedback>{error}</FormErrorFeedback> : null}
51
          </FormControl>
52
        )}
53
      />
54
    )
55
  }
56
 
2077 stevensc 57
  return (
2079 stevensc 58
    <FormControl variant='standard' fullWidth>
3000 stevensc 59
      {label && <InputLabel shrink>{label}</InputLabel>}
2099 stevensc 60
 
2843 stevensc 61
      <InputBase
2080 stevensc 62
        name={name}
63
        onChange={onChange}
2773 stevensc 64
        defaultValue={defaultValue}
2791 stevensc 65
        value={value}
2099 stevensc 66
        inputProps={{
67
          accept
68
        }}
2773 stevensc 69
        startAdornment={icon ? <InputAdornment>{icon}</InputAdornment> : null}
2080 stevensc 70
        fullWidth
3234 stevensc 71
        sx={style}
2773 stevensc 72
        {...props}
2080 stevensc 73
      />
2099 stevensc 74
 
2080 stevensc 75
      {error ? <FormErrorFeedback>{error}</FormErrorFeedback> : null}
2078 stevensc 76
    </FormControl>
2077 stevensc 77
  )
2073 stevensc 78
}
79
 
80
export default Input