forked from auth0/styleguide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (45 loc) · 1.28 KB
/
Copy pathindex.js
File metadata and controls
49 lines (45 loc) · 1.28 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
import React, { PropTypes } from 'react';
/**
* Select: Drop-down list.
*/
const Select = ({ options, selected, label, color, handleChange }) =>
<div className="a0r-select">
{ label && <span>{label}</span> }
<span className="a0r-value text-truncate" style={{ color }}>{options[selected].label}</span>
<i className="icon-budicon-460" />
<select
// Pass event and selected option object to onChange handler
onChange={e => handleChange(e, options.filter(opt => opt.value === e.target.value)[0])}
value={options[selected].value}
>
{ options.map((opt, index) => <option key={index} value={opt.value}>{opt.label}</option>) }
</select>
</div>;
Select.defaultProps = {
selected: 0,
label: '',
handleChange: () => {}
};
Select.propTypes = {
/**
* List of options
*/
options: PropTypes.arrayOf(
PropTypes.shape({
label: PropTypes.string.isRequired,
value: PropTypes.string.isRequired
})
).isRequired,
/**
* Index of default selected value
*/
selected: PropTypes.number,
/**
* Handler for option change, it receives two parameters:
* the event and the selected option object.
*/
handleChange: PropTypes.func.isRequired,
label: PropTypes.string,
color: PropTypes.string
};
export default Select;