Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3536 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3536 Rev 3719
Línea 1... Línea 1...
1
import React from 'react';
1
import React from 'react';
2
import { FormControl, InputAdornment, InputBase, InputLabel, Typography } from '@mui/material';
2
import { FormControl, InputAdornment, InputBase, InputLabel, Typography } from '@mui/material';
3
import { Controller, useFormContext } from 'react-hook-form';
3
import { Controller, useFormContext } from 'react-hook-form';
4
 
4
 
5
export function FormInput({ icon, name, rules, label, disabled, endAdornment, ...props }) {
5
export function FormInput({ icon, name, rules, label, disabled, endAdornment, ...props }) {
6
  const { control } = useFormContext();
6
  const { control } = useFormContext();
7
 
7
 
8
  return (
8
  return (
9
    <Controller
9
    <Controller
10
      name={name}
10
      name={name}
11
      control={control}
11
      control={control}
12
      disabled={disabled}
12
      disabled={disabled}
13
      rules={rules}
13
      rules={rules}
14
      render={({ field, fieldState: { error } }) => (
14
      render={({ field, fieldState: { error } }) => (
15
        <FormControl variant='standard' fullWidth>
15
        <FormControl variant='standard' fullWidth>
16
          {label && <InputLabel shrink>{label}</InputLabel>}
16
          {label && <InputLabel shrink>{label}</InputLabel>}
17
          <InputBase
17
          <InputBase
18
            {...field}
18
            {...field}
19
            startAdornment={icon && <InputAdornment>{icon}</InputAdornment>}
19
            startAdornment={icon && <InputAdornment>{icon}</InputAdornment>}
20
            endAdornment={endAdornment && <InputAdornment>{endAdornment}</InputAdornment>}
20
            endAdornment={endAdornment && <InputAdornment>{endAdornment}</InputAdornment>}
21
            fullWidth
21
            fullWidth
22
            {...props}
22
            {...props}
23
          />
23
          />
24
          {error && (
24
          {error && (
25
            <Typography sx={{ color: 'red', fontSize: '0.75rem' }}>{error.message}</Typography>
25
            <Typography sx={{ color: 'red', fontSize: '0.75rem' }}>{error.message}</Typography>
26
          )}
26
          )}
27
        </FormControl>
27
        </FormControl>
28
      )}
28
      )}
29
    />
29
    />
30
  );
30
  );
31
}
31
}