2015-10-13 03:37:11 +03:00
|
|
|
import React from 'react';
|
2016-05-22 21:43:54 +03:00
|
|
|
import classnames from 'classnames';
|
|
|
|
import { themr } from 'react-css-themr';
|
2015-10-13 03:37:11 +03:00
|
|
|
import FontIcon from '../font_icon';
|
2015-12-07 04:34:12 +03:00
|
|
|
import Ripple from '../ripple';
|
2015-10-13 03:37:11 +03:00
|
|
|
|
2015-10-22 02:31:17 +03:00
|
|
|
class MenuItem extends React.Component {
|
2015-10-20 08:40:51 +03:00
|
|
|
static propTypes = {
|
2015-11-01 14:06:04 +03:00
|
|
|
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,
|
2015-10-13 03:37:11 +03:00
|
|
|
disabled: React.PropTypes.bool,
|
2016-04-07 04:24:31 +03:00
|
|
|
icon: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.string,
|
|
|
|
React.PropTypes.element
|
|
|
|
]),
|
2015-11-22 21:20:05 +03:00
|
|
|
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
|
|
|
|
})
|
2015-10-20 08:40:51 +03:00
|
|
|
};
|
2015-10-13 03:37:11 +03:00
|
|
|
|
2015-10-20 08:40:51 +03:00
|
|
|
static defaultProps = {
|
2015-10-28 13:23:45 +03:00
|
|
|
className: '',
|
2015-10-20 08:40:51 +03:00
|
|
|
disabled: false,
|
|
|
|
selected: false
|
|
|
|
};
|
2015-10-13 03:37:11 +03:00
|
|
|
|
2015-10-22 02:31:17 +03:00
|
|
|
handleClick = (event) => {
|
2015-10-17 22:20:15 +03:00
|
|
|
if (this.props.onClick && !this.props.disabled) {
|
|
|
|
this.props.onClick(event, this);
|
|
|
|
}
|
2015-10-22 02:31:17 +03:00
|
|
|
};
|
2015-10-17 22:20:15 +03:00
|
|
|
|
2015-10-13 03:37:11 +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);
|
2015-10-13 03:37:11 +03:00
|
|
|
|
|
|
|
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}
|
2015-10-13 03:37:11 +03:00
|
|
|
</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};
|