2016-05-29 22:24:22 +03:00
|
|
|
import React, { Component, PropTypes } from 'react';
|
2016-05-22 21:43:54 +03:00
|
|
|
import classnames from 'classnames';
|
|
|
|
import { themr } from 'react-css-themr';
|
2016-05-29 22:24:22 +03:00
|
|
|
import { MENU } from '../identifiers.js';
|
|
|
|
import FontIcon from '../font_icon/FontIcon.js';
|
|
|
|
import rippleFactory from '../ripple/Ripple.js';
|
2015-10-13 03:37:11 +03:00
|
|
|
|
2016-05-29 22:24:22 +03:00
|
|
|
const factory = (ripple) => {
|
|
|
|
class MenuItem extends Component {
|
|
|
|
static propTypes = {
|
2016-06-04 00:44:33 +03:00
|
|
|
caption: PropTypes.string,
|
2016-05-29 22:24:22 +03:00
|
|
|
children: PropTypes.any,
|
|
|
|
className: PropTypes.string,
|
|
|
|
disabled: PropTypes.bool,
|
|
|
|
icon: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.element
|
|
|
|
]),
|
|
|
|
onClick: PropTypes.func,
|
|
|
|
selected: PropTypes.bool,
|
|
|
|
shortcut: PropTypes.string,
|
|
|
|
theme: PropTypes.shape({
|
2016-06-04 00:44:33 +03:00
|
|
|
caption: PropTypes.string,
|
|
|
|
disabled: PropTypes.string,
|
|
|
|
icon: PropTypes.string,
|
|
|
|
menuItem: PropTypes.string,
|
|
|
|
selected: PropTypes.string,
|
|
|
|
shortcut: PropTypes.string
|
2016-05-29 22:24:22 +03:00
|
|
|
})
|
|
|
|
};
|
2015-10-13 03:37:11 +03:00
|
|
|
|
2016-05-29 22:24:22 +03:00
|
|
|
static defaultProps = {
|
|
|
|
className: '',
|
|
|
|
disabled: false,
|
|
|
|
selected: false
|
|
|
|
};
|
2015-10-13 03:37:11 +03:00
|
|
|
|
2016-05-29 22:24:22 +03:00
|
|
|
handleClick = (event) => {
|
|
|
|
if (this.props.onClick && !this.props.disabled) {
|
|
|
|
this.props.onClick(event, this);
|
|
|
|
}
|
|
|
|
};
|
2015-10-17 22:20:15 +03:00
|
|
|
|
2016-05-29 22:24:22 +03:00
|
|
|
render () {
|
|
|
|
const {icon, caption, children, shortcut, selected, disabled, theme, ...others} = this.props;
|
|
|
|
const className = classnames(theme.menuItem, {
|
|
|
|
[theme.selected]: selected,
|
|
|
|
[theme.disabled]: disabled
|
|
|
|
}, this.props.className);
|
2015-10-13 03:37:11 +03:00
|
|
|
|
2016-05-29 22:24:22 +03:00
|
|
|
return (
|
|
|
|
<li {...others} data-react-toolbox='menu-item' className={className} onClick={this.handleClick}>
|
|
|
|
{icon ? <FontIcon value={icon} className={theme.icon}/> : null}
|
|
|
|
<span className={theme.caption}>{caption}</span>
|
|
|
|
{shortcut ? <small className={theme.shortcut}>{shortcut}</small> : null}
|
|
|
|
{children}
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
2015-10-13 03:37:11 +03:00
|
|
|
}
|
2015-10-22 02:31:17 +03:00
|
|
|
|
2016-05-29 22:24:22 +03:00
|
|
|
return ripple(MenuItem);
|
|
|
|
};
|
|
|
|
|
|
|
|
const MenuItem = factory(rippleFactory({}));
|
|
|
|
export default themr(MENU)(MenuItem);
|
|
|
|
export { factory as menuItemFactory };
|
|
|
|
export { MenuItem };
|