-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelect.js
70 lines (60 loc) · 1.84 KB
/
Select.js
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
68
69
70
import PropTypes from 'prop-types';
import { Field, ErrorMessage } from 'formik';
function Select(props) {
const {
darkMode = false,
label,
name,
onChange,
options = []
} = props;
const passProps = {};
if (onChange) passProps.onChange = onChange;
return (
<div>
{ label && (
<label
htmlFor={ name }
className={
`block text-sm font-medium mb-1
${darkMode ? 'text-gray-400' : 'text-gray-700'}`
}
>
{ label }
</label>
) }
<Field
id={ name }
name={ name }
as="select"
className={
`block w-full pl-3 pr-10 py-2 text-base sm:text-sm rounded-md
focus:outline-none focus:ring-indigo-500 focus:border-indigo-500
${darkMode ? 'border-indigo-500 text-gray-100 bg-gray-800' : 'border-gray-300'}`
}
children={
options.map((option, loopIndex) => (
<option value={ option.value } key={ loopIndex }>
{ option.label }
</option>
))
}
{ ...passProps }
/>
<ErrorMessage
name={ name }
component="div"
className="mt-2 text-sm text-red-600"
id={ `${name}-error` }
/>
</div>
);
}
Select.propTypes = {
name: PropTypes.string.isRequired,
options: PropTypes.array.isRequired,
label: PropTypes.string,
onChange: PropTypes.func,
darkMode: PropTypes.bool
};
export default Select;