-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathSelect.jsx
More file actions
67 lines (61 loc) · 1.93 KB
/
Copy pathSelect.jsx
File metadata and controls
67 lines (61 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import FormControl from '@material-ui/core/FormControl'
import InputLabel from '@material-ui/core/InputLabel'
import MenuItem from '@material-ui/core/MenuItem'
import MUISelect from '@material-ui/core/Select'
import PropTypes from 'prop-types'
import React from 'react'
import {
formInput,
formInputMeta,
formOptions,
} from '../../utils/react/propTypes.js'
import { ErrorText } from './buildingBlocks/ErrorText.jsx'
import { inputWrapper } from './styles.jsx'
export const SelectField = (props) => (
<MUISelect {...props.input} disabled={props.disabled}>
{props.showEmptyOption && <MenuItem value="" />}
{props.options.map((option) => (
<MenuItem key={option.value} value={option.value}>
{option.label}
</MenuItem>
))}
</MUISelect>
)
SelectField.propTypes = {
disabled: PropTypes.bool.isRequired,
input: formInput.isRequired,
options: formOptions.isRequired,
showEmptyOption: PropTypes.bool.isRequired,
}
const { className, styles } = inputWrapper
export const Select = (props) => (
<FormControl className={className}>
<InputLabel htmlFor={props.input.name}>{props.placeholder}</InputLabel>
<SelectField
input={props.input}
showEmptyOption={props.showEmptyOption}
options={props.options}
disabled={props.disabled}
/>
<ErrorText
showErrorText={props.showErrorText}
error={props.meta.error || ''}
touched={props.meta.touched}
/>
{styles}
</FormControl>
)
Select.propTypes = {
input: formInput.isRequired,
meta: formInputMeta.isRequired,
options: formOptions.isRequired,
placeholder: PropTypes.string.isRequired,
disabled: PropTypes.bool,
showEmptyOption: PropTypes.bool,
showErrorText: PropTypes.bool,
}
Select.defaultProps = {
showEmptyOption: false,
showErrorText: false,
disabled: false,
}