forked from yuristrelets/react-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuItem.js
More file actions
55 lines (49 loc) · 1.52 KB
/
MenuItem.js
File metadata and controls
55 lines (49 loc) · 1.52 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
50
51
52
53
54
55
import React from 'react';
import FontIcon from '../font_icon';
import ClassNames from 'classnames';
import Ripple from '../ripple';
import style from './style.menu_item';
class MenuItem extends React.Component {
static propTypes = {
caption: React.PropTypes.string.isRequired,
children: React.PropTypes.any,
className: React.PropTypes.string,
disabled: React.PropTypes.bool,
icon: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.element
]),
onClick: React.PropTypes.func,
selected: React.PropTypes.bool,
shortcut: React.PropTypes.string
};
static defaultProps = {
className: '',
disabled: false,
selected: false
};
handleClick = (event) => {
if (this.props.onClick && !this.props.disabled) {
this.props.onClick(event, this);
}
};
render () {
const {icon, caption, children, shortcut, selected, disabled, ...others} = this.props;
const className = ClassNames(style.root, {
[style.selected]: selected,
[style.disabled]: disabled
}, this.props.className);
return (
<li {...others} data-react-toolbox='menu-item' className={className} onClick={this.handleClick}>
{icon ? <FontIcon value={icon} className={style.icon}/> : null}
<span className={style.caption}>{caption}</span>
{shortcut ? <small className={style.shortcut}>{shortcut}</small> : null}
{children}
</li>
);
}
}
export default Ripple({
className: style.ripple
})(MenuItem);
export {MenuItem as RawMenuItem};