react-toolbox/components/menu/MenuItem.js

56 lines
1.5 KiB
JavaScript
Raw Normal View History

import React from 'react';
import FontIcon from '../font_icon';
2015-12-07 04:25:58 +03:00
import ClassNames from 'classnames';
2015-12-07 04:34:12 +03:00
import Ripple from '../ripple';
import style from './style.menu_item';
2015-10-22 02:31:17 +03:00
class MenuItem extends React.Component {
static propTypes = {
caption: React.PropTypes.string.isRequired,
2015-12-07 04:25:58 +03:00
children: React.PropTypes.any,
2015-10-28 13:23:45 +03:00
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 = {
2015-10-28 13:23:45 +03:00
className: '',
disabled: false,
selected: false
};
2015-10-22 02:31:17 +03:00
handleClick = (event) => {
if (this.props.onClick && !this.props.disabled) {
this.props.onClick(event, this);
}
2015-10-22 02:31:17 +03:00
};
render () {
2015-12-07 04:25:58 +03:00
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 (
2015-12-07 04:25:58 +03:00
<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>
);
}
2015-10-21 13:25:07 +03:00
}
2015-10-22 02:31:17 +03:00
2015-12-07 04:34:12 +03:00
export default Ripple({
2015-12-07 04:25:58 +03:00
className: style.ripple
})(MenuItem);
2016-01-22 16:12:53 +03:00
export {MenuItem as RawMenuItem};