-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverlay.jsx.js
60 lines (60 loc) · 1.74 KB
/
overlay.jsx.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
/**
* @file 覆盖层
*/
var React = require('react');
var Portal = require('./popup/portal.jsx');
var Overlay = React.createClass({
componentDidMount: function () {
if (this.props.isRootClose) {
this.isRootClose = true;
document.addEventListener('click', this.handleRootClose);
}
},
componentWillReceiveProps: function (nextProps) {
// 将要关闭
if (nextProps.isOpen === false && this.props.isOpen === true) {
this.setState({
isOpen: false
});
// 将要打开
} else if (nextProps.isOpen === true && this.props.isOpen === false) {
this.setState({
isOpen: true
});
}
},
componentWillUnmount: function () {
if (this.isRootClose) {
document.removeEventListener('click', this.handleRootClose, false);
}
},
getDefaultProps: function () {
return {
isOpen: false,
container: null,
onClose: function () {},
rootClose: false
};
},
getInitialState: function () {
return {
isOpen: this.props.isOpen
};
},
handleRootClose: function (e) {
// console.log(this.props.target.ownerDocument);
// console.log(this.props.target, require('react-dom').findDOMNode(this.props.target));
// this.props.onClose();
},
render: function () {
if (!this.state.isOpen) {
return null;
}
return (
<Portal container={this.props.container}>
{this.props.children}
</Portal>
);
}
});
module.exports = Overlay;