Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2108 | Rev 2110 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 2108 Rev 2109
Línea 1... Línea 1...
1
import React from 'react'
1
import React from 'react'
-
 
2
import { Controller } from 'react-hook-form'
2
import {
3
import {
3
  FormControl,
4
  FormControl,
4
  InputLabel,
5
  InputLabel,
5
  MenuItem,
6
  MenuItem,
6
  Select as MuiSelect
7
  Select as MuiSelect
Línea 9... Línea 10...
9
import FormErrorFeedback from '../form/FormErrorFeedback'
10
import FormErrorFeedback from '../form/FormErrorFeedback'
Línea 10... Línea 11...
10
 
11
 
11
const Select = ({
12
const Select = ({
12
  label,
13
  label,
13
  name,
14
  name,
14
  value,
15
  control,
15
  placeholder,
16
  placeholder,
16
  defaultValue,
17
  defaultValue,
17
  options = [],
18
  options = [],
18
  error = null,
19
  rules,
19
  inputRef = null,
-
 
20
  onChange = () => {}
20
  error = null
21
}) => {
21
}) => {
22
  return (
22
  return (
23
    <FormControl fullWidth>
23
    <FormControl fullWidth>
24
      {label ? (
24
      {label ? (
25
        <InputLabel shrink htmlFor={name}>
25
        <InputLabel shrink htmlFor={name}>
26
          {label}
26
          {label}
27
        </InputLabel>
27
        </InputLabel>
Línea 28... Línea 28...
28
      ) : null}
28
      ) : null}
29
 
-
 
30
      <MuiSelect
-
 
31
        ref={inputRef}
-
 
32
        defaultValue={defaultValue}
-
 
33
        value={value}
29
 
34
        onChange={onChange}
30
      <Controller
35
        name={name}
31
        name={name}
-
 
32
        control={control}
36
        id={name}
33
        rules={rules}
37
        sx={{
34
        defaultValue={defaultValue}
-
 
35
        render={(field) => (
38
          borderRadius: '4px'
36
          <MuiSelect
39
        }}
37
            {...field}
-
 
38
            fullWidth
-
 
39
            displayEmpty
-
 
40
            sx={{
40
        fullWidth
41
              borderRadius: '4px'
41
        displayEmpty
42
            }}
-
 
43
          >
42
      >
44
            <MenuItem value=''>{placeholder}</MenuItem>
43
        <MenuItem value=''>{placeholder}</MenuItem>
45
 
44
        {options.map(({ name, value }) => (
46
            {options.map(({ name, value }) => (
45
          <MenuItem key={value} value={value}>
47
              <MenuItem key={value} value={value}>
46
            {name}
48
                {name}
47
          </MenuItem>
49
              </MenuItem>
-
 
50
            ))}
-
 
51
          </MuiSelect>
Línea 48... Línea 52...
48
        ))}
52
        )}
49
      </MuiSelect>
53
      />
50
 
54
 
51
      {error ? <FormErrorFeedback>{error}</FormErrorFeedback> : null}
55
      {error ? <FormErrorFeedback>{error}</FormErrorFeedback> : null}