Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
3452 stevensc 1
import React from 'react';
2
import { Controller, useFormContext } from 'react-hook-form';
3
import { FormControl, InputLabel, MenuItem, Select as MuiSelect, Typography } from '@mui/material';
4
 
5
export function FormSelect({
6
  name,
7
  label,
8
  rules,
9
  placeholder = 'Seleccione una opción',
10
  options = [],
11
  style = {},
12
  ...props
13
}) {
14
  const { control } = useFormContext();
15
 
16
  return (
17
    <Controller
18
      name={name}
19
      control={control}
20
      rules={rules}
21
      render={({ field, fieldState: { error } }) => (
22
        <FormControl variant='standard' fullWidth sx={style}>
23
          {label && <InputLabel shrink>{label}</InputLabel>}
24
 
25
          <MuiSelect
26
            {...field}
27
            fullWidth
28
            displayEmpty
29
            sx={{
3474 stevensc 30
              marginTop: '0',
3452 stevensc 31
              borderRadius: '4px'
32
            }}
33
            {...props}
34
          >
35
            <MenuItem value='' disabled>
36
              {placeholder}
37
            </MenuItem>
38
            {options.map(({ label, value }) => (
39
              <MenuItem key={value} value={value}>
40
                {label}
41
              </MenuItem>
42
            ))}
43
          </MuiSelect>
44
 
45
          {error && (
3473 stevensc 46
            <Typography variant='caption' color='red'>
47
              {error.message}
48
            </Typography>
3452 stevensc 49
          )}
50
        </FormControl>
51
      )}
52
    />
53
  );
54
}