react-toolbox/components/menu/MenuItem.js

78 lines
2.1 KiB
JavaScript
Raw Normal View History

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';
2017-01-26 20:05:32 +03:00
import { MENU } from '../identifiers';
import { FontIcon } from '../font_icon/FontIcon';
import rippleFactory from '../ripple/Ripple';
2016-05-29 22:24:22 +03:00
const factory = (ripple) => {
class MenuItem extends Component {
static propTypes = {
caption: PropTypes.string,
2017-01-26 20:05:32 +03:00
children: PropTypes.node,
2016-05-29 22:24:22 +03:00
className: PropTypes.string,
disabled: PropTypes.bool,
icon: PropTypes.oneOfType([
PropTypes.string,
2017-01-26 20:05:32 +03:00
PropTypes.element,
2016-05-29 22:24:22 +03:00
]),
onClick: PropTypes.func,
selected: PropTypes.bool,
shortcut: PropTypes.string,
theme: PropTypes.shape({
caption: PropTypes.string,
disabled: PropTypes.string,
icon: PropTypes.string,
menuItem: PropTypes.string,
selected: PropTypes.string,
2017-01-26 20:05:32 +03:00
shortcut: PropTypes.string,
}),
2016-05-29 22:24:22 +03:00
};
2016-05-29 22:24:22 +03:00
static defaultProps = {
className: '',
disabled: false,
2017-01-26 20:05:32 +03:00
selected: false,
2016-05-29 22:24:22 +03:00
};
2016-05-29 22:24:22 +03:00
handleClick = (event) => {
if (this.props.onClick && !this.props.disabled) {
this.props.onClick(event, this);
}
};
2017-01-26 20:05:32 +03:00
render() {
const {
caption,
children,
disabled,
icon,
selected,
shortcut,
theme,
...others
} = this.props;
2016-05-29 22:24:22 +03:00
const className = classnames(theme.menuItem, {
[theme.selected]: selected,
2017-01-26 20:05:32 +03:00
[theme.disabled]: disabled,
2016-05-29 22:24:22 +03:00
}, this.props.className);
2016-05-29 22:24:22 +03:00
return (
2017-01-26 20:05:32 +03:00
<li {...others} data-react-toolbox="menu-item" className={className} onClick={this.handleClick}>
{icon ? <FontIcon value={icon} className={theme.icon} /> : null}
2016-05-29 22:24:22 +03:00
<span className={theme.caption}>{caption}</span>
{shortcut ? <small className={theme.shortcut}>{shortcut}</small> : null}
{children}
</li>
);
}
}
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 };