You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.9 KiB
73 lines
1.9 KiB
10 years ago
|
"use strict";
|
||
|
|
||
|
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
|
||
|
|
||
|
var React = _interopRequire(require("react"));
|
||
|
|
||
|
var CustomPropTypes = _interopRequire(require("./utils/CustomPropTypes"));
|
||
|
|
||
|
var domUtils = _interopRequire(require("./utils/domUtils"));
|
||
|
|
||
|
module.exports = {
|
||
|
propTypes: {
|
||
|
container: CustomPropTypes.mountable
|
||
|
},
|
||
|
|
||
|
componentWillUnmount: function componentWillUnmount() {
|
||
|
this._unrenderOverlay();
|
||
|
if (this._overlayTarget) {
|
||
|
this.getContainerDOMNode().removeChild(this._overlayTarget);
|
||
|
this._overlayTarget = null;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
componentDidUpdate: function componentDidUpdate() {
|
||
|
this._renderOverlay();
|
||
|
},
|
||
|
|
||
|
componentDidMount: function componentDidMount() {
|
||
|
this._renderOverlay();
|
||
|
},
|
||
|
|
||
|
_mountOverlayTarget: function _mountOverlayTarget() {
|
||
|
this._overlayTarget = document.createElement("div");
|
||
|
this.getContainerDOMNode().appendChild(this._overlayTarget);
|
||
|
},
|
||
|
|
||
|
_renderOverlay: function _renderOverlay() {
|
||
|
if (!this._overlayTarget) {
|
||
|
this._mountOverlayTarget();
|
||
|
}
|
||
|
|
||
|
var overlay = this.renderOverlay();
|
||
|
|
||
|
// Save reference to help testing
|
||
|
if (overlay !== null) {
|
||
|
this._overlayInstance = React.render(overlay, this._overlayTarget);
|
||
|
} else {
|
||
|
// Unrender if the component is null for transitions to null
|
||
|
this._unrenderOverlay();
|
||
|
}
|
||
|
},
|
||
|
|
||
|
_unrenderOverlay: function _unrenderOverlay() {
|
||
|
React.unmountComponentAtNode(this._overlayTarget);
|
||
|
this._overlayInstance = null;
|
||
|
},
|
||
|
|
||
|
getOverlayDOMNode: function getOverlayDOMNode() {
|
||
|
if (!this.isMounted()) {
|
||
|
throw new Error("getOverlayDOMNode(): A component must be mounted to have a DOM node.");
|
||
|
}
|
||
|
|
||
|
if (this._overlayInstance) {
|
||
|
return React.findDOMNode(this._overlayInstance);
|
||
|
}
|
||
|
|
||
|
return null;
|
||
|
},
|
||
|
|
||
|
getContainerDOMNode: function getContainerDOMNode() {
|
||
|
return React.findDOMNode(this.props.container) || domUtils.ownerDocument(this).body;
|
||
|
}
|
||
|
};
|