react-toolbox/components/menu/IconMenu.js

94 lines
2.5 KiB
JavaScript
Raw Normal View History

import React, { Component, PropTypes } from 'react';
2016-05-22 21:15:45 +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 InjectIconButton from '../button/IconButton';
import InjectMenu from './Menu';
2015-10-17 23:25:15 +03:00
2016-05-29 22:24:22 +03:00
const factory = (IconButton, Menu) => {
class IconMenu extends Component {
2016-05-29 22:24:22 +03:00
static propTypes = {
children: PropTypes.node,
className: PropTypes.string,
icon: PropTypes.oneOfType([
PropTypes.string,
2017-01-26 20:05:32 +03:00
PropTypes.element,
2016-05-29 22:24:22 +03:00
]),
iconRipple: PropTypes.bool,
menuRipple: PropTypes.bool,
onClick: PropTypes.func,
onHide: PropTypes.func,
onSelect: PropTypes.func,
onShow: PropTypes.func,
position: PropTypes.string,
selectable: PropTypes.bool,
2017-01-26 20:05:32 +03:00
selected: PropTypes.node,
theme: PropTypes.shape({
icon: PropTypes.string,
2017-01-26 20:05:32 +03:00
iconMenu: PropTypes.string,
}),
2016-05-29 22:24:22 +03:00
};
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',
2017-01-26 20:05:32 +03:00
selectable: false,
2016-05-29 22:24:22 +03:00
};
2015-10-17 23:25:15 +03:00
2016-05-29 22:24:22 +03:00
state = {
2017-01-26 20:05:32 +03:00
active: false,
2016-05-29 22:24:22 +03:00
}
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
2017-01-26 20:05:32 +03:00
render() {
2016-11-23 11:59:51 +03:00
const {
2017-01-17 15:56:50 +03:00
children, className, icon, iconRipple, inverse, menuRipple, onHide, // eslint-disable-line
2016-11-23 11:59:51 +03:00
onSelect, onShow, position, selectable, selected, theme, ...other
} = this.props;
2016-05-29 22:24:22 +03:00
return (
2016-11-23 11:59:51 +03:00
<div {...other} className={classnames(theme.iconMenu, className)}>
2016-05-29 22:24:22 +03:00
<IconButton
2016-11-23 11:59:51 +03:00
className={theme.icon}
icon={icon}
2017-01-17 15:56:50 +03:00
inverse={inverse}
2016-05-29 22:24:22 +03:00
onClick={this.handleButtonClick}
2016-11-23 11:59:51 +03:00
ripple={iconRipple}
2016-05-29 22:24:22 +03:00
/>
<Menu
active={this.state.active}
onHide={this.handleMenuHide}
2016-11-23 11:59:51 +03:00
onSelect={onSelect}
onShow={onShow}
position={position}
ripple={menuRipple}
selectable={selectable}
selected={selected}
theme={theme}
2016-05-29 22:24:22 +03:00
>
2016-11-23 11:59:51 +03:00
{children}
2016-05-29 22:24:22 +03:00
</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 };