-
Notifications
You must be signed in to change notification settings - Fork 3
/
Select.jsx
101 lines (98 loc) · 2.3 KB
/
Select.jsx
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { MenuItem, TextField } from "@mui/material";
import PropTypes from "prop-types";
import React from "react";
/**
* Select components are used for collecting user provided information from a list of options.
*/
export default function Select({
error = false,
disabled = false,
helperText,
label,
margin = "normal",
onChange = () => {},
options = [],
required = false,
size = "medium",
value,
variant = "outlined"
}) {
// return components
return (
<TextField
select
required={required}
variant={variant}
error={error}
margin={margin}
fullWidth
label={label}
value={options.includes(value) ? value : ""}
onChange={onChange}
disabled={disabled}
id={label}
helperText={helperText}
size={size}
>
{options.map(option => (
<MenuItem value={option} key={option}>
{option}
</MenuItem>
))}
</TextField>
);
}
Select.propTypes = {
/**
* If true, the label, input and helper text should be displayed in a disabled state.
*/
disabled: PropTypes.bool,
/**
* If true, the component will display an error state.
*/
error: PropTypes.bool,
/**
* Helper text to display below input.
*/
helperText: PropTypes.string,
/**
* Label to display above input.
*/
label: PropTypes.string,
/**
* If dense or normal, will adjust vertical spacing of this and contained components.
*/
margin: PropTypes.oneOf(["none", "dense", "normal"]),
/**
* Callback fired when the value is changed.
*
* **Signature**
* ```
* function(event: object) => void
* ```
* _event_: The event source of the callback. You can pull out the new value by accessing `event.target.value` (string).
*/
onChange: PropTypes.func,
/**
* Array of options to display.
*/
options: PropTypes.arrayOf(
PropTypes.oneOfType([PropTypes.string, PropTypes.number])
),
/**
* If true, the label will indicate that the input is required.
*/
required: PropTypes.bool,
/**
* The size of the select field.
*/
size: PropTypes.oneOf(["medium", "small"]),
/**
* The input value
*/
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* The variant to use.
*/
variant: PropTypes.oneOf(["standard", "outlined", "filled"])
};