react-toolbox/components/menu/MenuItem.js

63 lines
1.9 KiB
JavaScript
Raw Normal View History

import React from 'react';
2016-05-22 21:43:54 +03:00
import classnames from 'classnames';
import { themr } from 'react-css-themr';
import FontIcon from '../font_icon';
2015-12-07 04:34:12 +03:00
import Ripple from '../ripple';
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,
2016-05-22 21:43:54 +03:00
shortcut: React.PropTypes.string,
theme: React.PropTypes.shape({
caption: React.PropTypes.string.isRequired,
disabled: React.PropTypes.string.isRequired,
icon: React.PropTypes.string.isRequired,
menuItem: React.PropTypes.string.isRequired,
selected: React.PropTypes.string.isRequired,
shortcut: React.PropTypes.string.isRequired
})
};
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 () {
2016-05-22 21:43:54 +03:00
const {icon, caption, children, shortcut, selected, disabled, theme, ...others} = this.props;
const className = classnames(theme.menuItem, {
[theme.selected]: selected,
[theme.disabled]: disabled
2015-12-07 04:25:58 +03:00
}, this.props.className);
return (
2015-12-07 04:25:58 +03:00
<li {...others} data-react-toolbox='menu-item' className={className} onClick={this.handleClick}>
2016-05-22 21:43:54 +03:00
{icon ? <FontIcon value={icon} className={theme.icon}/> : null}
<span className={theme.caption}>{caption}</span>
{shortcut ? <small className={theme.shortcut}>{shortcut}</small> : null}
2015-12-07 04:25:58 +03:00
{children}
</li>
);
}
2015-10-21 13:25:07 +03:00
}
2015-10-22 02:31:17 +03:00
2016-05-22 21:43:54 +03:00
const RawMenuItem = themr('ToolboxMenu')(MenuItem);
export default themr('ToolboxMenu')(Ripple({})(MenuItem));
export {RawMenuItem as RawMenuItem};