forked from react-toolbox/react-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIconMenu.js
More file actions
88 lines (80 loc) · 2.35 KB
/
IconMenu.js
File metadata and controls
88 lines (80 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React, { Component, PropTypes } from 'react';
import classnames from 'classnames';
import { themr } from 'react-css-themr';
import { MENU } from '../identifiers.js';
import InjectIconButton from '../button/IconButton.js';
import InjectMenu from './Menu.js';
const factory = (IconButton, Menu) => {
class IconMenu extends Component {
static propTypes = {
children: PropTypes.node,
className: PropTypes.string,
icon: PropTypes.oneOfType([
PropTypes.string,
PropTypes.element
]),
iconRipple: PropTypes.bool,
menuRipple: PropTypes.bool,
onClick: PropTypes.func,
onHide: PropTypes.func,
onSelect: PropTypes.func,
onShow: PropTypes.func,
position: PropTypes.string,
selectable: PropTypes.bool,
selected: PropTypes.any,
theme: PropTypes.shape({
icon: PropTypes.string,
iconMenu: PropTypes.string
})
};
static defaultProps = {
className: '',
icon: 'more_vert',
iconRipple: true,
menuRipple: true,
position: 'auto',
selectable: false
};
state = {
active: false
}
handleButtonClick = (event) => {
this.setState({ active: !this.state.active });
if (this.props.onClick) this.props.onClick(event);
};
handleMenuHide = () => {
this.setState({ active: false });
if (this.props.onHide) this.props.onHide();
}
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>
);
}
}
return IconMenu;
};
const IconMenu = factory(InjectIconButton, InjectMenu);
export default themr(MENU)(IconMenu);
export { factory as iconMenuFactory };
export { IconMenu };