-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
Select.js
67 lines (58 loc) · 1.25 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
import PropTypes from 'prop-types';
import React from 'react';
const styles = {
display: 'table-cell',
boxSizing: 'border-box',
verticalAlign: 'middle',
height: '26px',
width: '100%',
outline: 'none',
border: '1px solid #f7f4f4',
borderRadius: 2,
fontSize: 11,
padding: '5px',
color: '#555',
};
class SelectType extends React.Component {
_makeOpt(key, val) {
const opts = {
key,
value: key,
};
return <option {...opts}>{val}</option>;
}
_options(values) {
let data = [];
if (Array.isArray(values)) {
data = values.map(val => this._makeOpt(val, val));
} else {
data = Object.keys(values).map(key => this._makeOpt(key, values[key]));
}
return data;
}
render() {
const { knob, onChange } = this.props;
return (
<select
id={knob.name}
ref="input"
style={styles}
value={knob.value}
onChange={e => onChange(e.target.value)}
>
{this._options(knob.options)}
</select>
);
}
}
SelectType.propTypes = {
knob: PropTypes.object,
onChange: PropTypes.func,
};
SelectType.serialize = function(value) {
return value;
};
SelectType.deserialize = function(value) {
return value;
};
export default SelectType;