Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3440 | | Comparar con el anterior | Ultima modificación | Ver Log |

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