-
Notifications
You must be signed in to change notification settings - Fork 82
/
MenuItem.jsx
59 lines (47 loc) · 1.06 KB
/
MenuItem.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
'use strict';
import './_MenuItem.scss';
import React from 'react';
import classnames from 'classnames';
var { PropTypes } = React;
class MenuItem extends React.Component {
constructor(...args) {
super(...args);
this.state = {
isSelected: false
};
}
handleClick() {
console.log('You clicked on: %s', this.props.item.label);
this.toggleSelected();
this.props[
this.isSelected() ? 'onDeselect' : 'onSelect'
](this.props.item);
}
toggleSelected() {
this.setState({
isSelected: !this.state.isSelected
});
}
isSelected() {
return this.state.isSelected;
}
getClassName() {
return classnames({
'menu-item': true,
'-selected': this.isSelected()
});
}
render() {
return (
<li className={this.getClassName()} onClick={this.handleClick.bind(this)}>
{this.props.item.label}
</li>
);
}
}
MenuItem.propTypes = {
item: PropTypes.object.isRequired,
onSelect: PropTypes.func.isRequired,
onDeselect: PropTypes.func.isRequired
};
export default MenuItem;