forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PopoverAnimationDefault.js
106 lines (92 loc) · 2.61 KB
/
PopoverAnimationDefault.js
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
import transitions from '../styles/transitions';
import React from 'react';
import propTypes from '../utils/propTypes';
import Paper from '../Paper';
function getStyles(props, context, state) {
const {targetOrigin} = props;
const {open} = state;
const {muiTheme} = context;
const horizontal = targetOrigin.horizontal.replace('middle', 'vertical');
return {
root: {
opacity: open ? 1 : 0,
transform: open ? 'scale(1, 1)' : 'scale(0, 0)',
transformOrigin: `${horizontal} ${targetOrigin.vertical}`,
position: 'fixed',
zIndex: muiTheme.zIndex.popover,
transition: transitions.easeOut('250ms', ['transform', 'opacity']),
maxHeight: '100%',
},
horizontal: {
maxHeight: '100%',
overflowY: 'auto',
transform: open ? 'scaleX(1)' : 'scaleX(0)',
opacity: open ? 1 : 0,
transformOrigin: `${horizontal} ${targetOrigin.vertical}`,
transition: transitions.easeOut('250ms', ['transform', 'opacity']),
},
vertical: {
opacity: open ? 1 : 0,
transform: open ? 'scaleY(1)' : 'scaleY(0)',
transformOrigin: `${horizontal} ${targetOrigin.vertical}`,
transition: transitions.easeOut('500ms', ['transform', 'opacity']),
},
};
}
class PopoverDefaultAnimation extends React.Component {
static propTypes = {
children: React.PropTypes.node,
/**
* The css class name of the root element.
*/
className: React.PropTypes.string,
open: React.PropTypes.bool.isRequired,
/**
* Override the inline-styles of the root element.
*/
style: React.PropTypes.object,
targetOrigin: propTypes.origin,
zDepth: propTypes.zDepth,
};
static defaultProps = {
style: {},
zDepth: 1,
};
static contextTypes = {
muiTheme: React.PropTypes.object.isRequired,
};
state = {
open: false,
};
componentDidMount() {
this.setState({open: true}); // eslint-disable-line react/no-did-mount-set-state
}
componentWillReceiveProps(nextProps) {
this.setState({
open: nextProps.open,
});
}
render() {
const {
className,
style,
zDepth,
} = this.props;
const {prepareStyles} = this.context.muiTheme;
const styles = getStyles(this.props, this.context, this.state);
return (
<Paper
style={Object.assign(styles.root, style)}
zDepth={zDepth}
className={className}
>
<div style={prepareStyles(styles.horizontal)}>
<div style={prepareStyles(styles.vertical)}>
{this.props.children}
</div>
</div>
</Paper>
);
}
}
export default PopoverDefaultAnimation;