forked from pterolex/react-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Menu.jsx
76 lines (66 loc) · 2.09 KB
/
Menu.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
/**
* @jsx React.DOM
*/
'use strict';
var React = require('react');
var cx = React.addons.classSet;
require('./Menu.less');
var Menu = React.createClass({
propTypes: {
onChange: React.PropTypes.func.isRequired,
items: React.PropTypes.array.isRequired,
checkedId: React.PropTypes.string.isRequired,
},
handleChange(id) {
if (this.props.onChange) {
this.props.onChange(id);
}
},
render() {
var rootClass = cx({
'WLC-Menu': true
});
var index = this.props.items.findIndex( item => item.id === this.props.checkedId );
return (
<div className={rootClass + ' WLC-total-' + this.props.items.length}>
<div className={'WLC-caret WLC-num-'+index}>
<div className='WLC-caret-inner' />
</div>
<div className='WLC-options'>
{ this.props.items.map(item => {
var optClass = cx({
'WLC-option': true,
'WLC-checked': item.id == this.props.checkedId
});
return (
<div key={item.id}
className={optClass}
onTouchTap={this.handleChange.bind(this, item.id)}
onClick={this.handleChange.bind(this, item.id)}>
<span>{item.label}</span>
</div>
);
}) }
</div>
</div>
);
}
});
module.exports = Menu;
/*===================================
= How to: =
===================================*/
//
// <Menu onChange={this.handleMenuChange}
// checkedId='{this.state.menuVal}'
// items={[{
// id: 'option1',
// label: 'option1'
// }, {
// id: 'option2',
// label: 'option2'
// }, {
// id: 'option3',
// label: 'option3'
// }]} />
//