forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrop-down-icon.jsx
122 lines (105 loc) · 3.11 KB
/
drop-down-icon.jsx
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
let React = require('react');
let StylePropable = require('./mixins/style-propable');
let Transitions = require('./styles/transitions');
let ClickAwayable = require('./mixins/click-awayable');
let FontIcon = require('./font-icon');
let Menu = require('./menu/menu');
let DropDownIcon = React.createClass({
mixins: [StylePropable, ClickAwayable],
contextTypes: {
muiTheme: React.PropTypes.object,
},
propTypes: {
onChange: React.PropTypes.func,
menuItems: React.PropTypes.array.isRequired,
closeOnMenuItemTouchTap: React.PropTypes.bool,
iconStyle: React.PropTypes.object,
iconClassName: React.PropTypes.string,
iconLigature: React.PropTypes.string,
},
getInitialState() {
return {
open: false,
};
},
getDefaultProps() {
return {
closeOnMenuItemTouchTap: true,
};
},
componentDidMount() {
// This component can be deprecated once ./menu/menu has been deprecated.
// if (process.env.NODE_ENV !== 'production') {
// console.warn('DropDownIcon has been deprecated. Use IconMenu instead.');
// }
},
componentClickAway() {
this.setState({ open: false });
},
getStyles() {
let spacing = this.context.muiTheme.spacing;
let iconWidth = 48;
let styles = {
root: {
display: 'inline-block',
width: iconWidth + 'px !important',
position: 'relative',
height: spacing.desktopToolbarHeight,
fontSize: spacing.desktopDropDownMenuFontSize,
cursor: 'pointer',
},
menu: {
transition: Transitions.easeOut(),
right: '-14px !important',
top: '9px !important',
opacity: (this.state.open) ? 1 : 0,
},
menuItem: { // similair to drop down menu's menu item styles
paddingRight: (spacing.iconSize + (spacing.desktopGutterLess*2)),
height: spacing.desktopDropDownMenuItemHeight,
lineHeight: spacing.desktopDropDownMenuItemHeight +'px',
},
};
return styles;
},
render() {
let {
style,
children,
menuItems,
closeOnMenuItemTouchTap,
iconStyle,
iconClassName,
...other,
} = this.props;
let styles = this.getStyles();
return (
<div {...other} style={this.mergeAndPrefix(styles.root, this.props.style)}>
<div onTouchTap={this._onControlClick}>
<FontIcon
className={iconClassName}
style={iconStyle}>{this.props.iconLigature}</FontIcon>
{this.props.children}
</div>
<Menu
ref="menuItems"
style={this.mergeAndPrefix(styles.menu)}
menuItems={menuItems}
menuItemStyle={styles.menuItem}
hideable={true}
visible={this.state.open}
onItemTap={this._onMenuItemClick} />
</div>
);
},
_onControlClick() {
this.setState({ open: !this.state.open });
},
_onMenuItemClick(e, key, payload) {
if (this.props.onChange) this.props.onChange(e, key, payload);
if (this.props.closeOnMenuItemTouchTap) {
this.setState({ open: false });
}
},
});
module.exports = DropDownIcon;