2015-10-17 23:25:15 +03:00
|
|
|
import React from 'react';
|
2016-05-22 21:15:45 +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 InjectIconButton from '../button/IconButton.js';
|
|
|
|
import InjectMenu from './Menu.js';
|
2015-10-17 23:25:15 +03:00
|
|
|
|
2016-05-29 22:24:22 +03:00
|
|
|
const factory = (IconButton, Menu) => {
|
|
|
|
class IconMenu extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
children: React.PropTypes.node,
|
|
|
|
className: React.PropTypes.string,
|
|
|
|
icon: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.string,
|
|
|
|
React.PropTypes.element
|
|
|
|
]),
|
|
|
|
iconRipple: React.PropTypes.bool,
|
|
|
|
menuRipple: React.PropTypes.bool,
|
|
|
|
onClick: React.PropTypes.func,
|
|
|
|
onHide: React.PropTypes.func,
|
|
|
|
onSelect: React.PropTypes.func,
|
|
|
|
onShow: React.PropTypes.func,
|
|
|
|
position: React.PropTypes.string,
|
|
|
|
selectable: React.PropTypes.bool,
|
|
|
|
selected: React.PropTypes.any,
|
|
|
|
theme: React.PropTypes.shape({
|
|
|
|
icon: React.PropTypes.string.isRequired,
|
|
|
|
iconMenu: React.PropTypes.string.isRequired
|
|
|
|
})
|
|
|
|
};
|
2015-10-17 23:25:15 +03:00
|
|
|
|
2016-05-29 22:24:22 +03:00
|
|
|
static defaultProps = {
|
|
|
|
className: '',
|
|
|
|
icon: 'more_vert',
|
|
|
|
iconRipple: true,
|
|
|
|
menuRipple: true,
|
|
|
|
position: 'auto',
|
|
|
|
selectable: false
|
|
|
|
};
|
2015-10-17 23:25:15 +03:00
|
|
|
|
2016-05-29 22:24:22 +03:00
|
|
|
state = {
|
|
|
|
active: false
|
|
|
|
}
|
2016-05-22 21:15:45 +03:00
|
|
|
|
2016-05-29 22:24:22 +03:00
|
|
|
handleButtonClick = (event) => {
|
|
|
|
this.setState({ active: !this.state.active });
|
|
|
|
if (this.props.onClick) this.props.onClick(event);
|
|
|
|
};
|
2015-10-17 23:25:15 +03:00
|
|
|
|
2016-05-29 22:24:22 +03:00
|
|
|
handleMenuHide = () => {
|
|
|
|
this.setState({ active: false });
|
|
|
|
if (this.props.onHide) this.props.onHide();
|
|
|
|
}
|
2015-10-17 23:25:15 +03:00
|
|
|
|
2016-05-29 22:24:22 +03:00
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<div className={classnames(this.props.theme.iconMenu, this.props.className)}>
|
|
|
|
<IconButton
|
|
|
|
className={this.props.theme.icon}
|
|
|
|
icon={this.props.icon}
|
|
|
|
onClick={this.handleButtonClick}
|
|
|
|
ripple={this.props.iconRipple}
|
|
|
|
/>
|
|
|
|
<Menu
|
|
|
|
ref='menu'
|
|
|
|
active={this.state.active}
|
|
|
|
onHide={this.handleMenuHide}
|
|
|
|
onSelect={this.props.onSelect}
|
|
|
|
onShow={this.props.onShow}
|
|
|
|
position={this.props.position}
|
|
|
|
ripple={this.props.menuRipple}
|
|
|
|
selectable={this.props.selectable}
|
|
|
|
selected={this.props.selected}
|
|
|
|
>
|
|
|
|
{this.props.children}
|
|
|
|
</Menu>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2015-10-17 23:25:15 +03:00
|
|
|
}
|
2015-10-22 02:31:17 +03:00
|
|
|
|
2016-05-29 22:24:22 +03:00
|
|
|
return IconMenu;
|
|
|
|
};
|
|
|
|
|
|
|
|
const IconMenu = factory(InjectIconButton, InjectMenu);
|
|
|
|
export default themr(MENU)(IconMenu);
|
|
|
|
export { factory as iconMenuFactory };
|
|
|
|
export { IconMenu };
|