@blueprintjs/core
Version:
Core styles & components
62 lines (60 loc) • 2.66 kB
JavaScript
/*
* Copyright 2015 Palantir Technologies, Inc. All rights reserved.
* Licensed under the BSD-3 License as modified (the “License”); you may obtain a copy
* of the license at https://github.com/palantir/blueprint/blob/master/LICENSE
* and https://github.com/palantir/blueprint/blob/master/PATENTS
*/
;
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var React = require("react");
var ReactDOM = require("react-dom");
var Classes = require("../../common/classes");
var props_1 = require("../../common/props");
var utils_1 = require("../../common/utils");
/**
* This component detaches its contents and re-attaches them to document.body.
* Use it when you need to circumvent DOM z-stacking (for dialogs, popovers, etc.).
* Any class names passed to this element will be propagated to the new container element on document.body.
*/
var Portal = (function (_super) {
__extends(Portal, _super);
function Portal() {
_super.apply(this, arguments);
this.displayName = "Blueprint.Portal";
}
Portal.prototype.render = function () {
return null;
};
Portal.prototype.componentDidMount = function () {
var targetElement = document.createElement("div");
targetElement.classList.add(Classes.PORTAL);
document.body.appendChild(targetElement);
this.targetElement = targetElement;
this.componentDidUpdate();
};
Portal.prototype.componentDidUpdate = function () {
var _this = this;
// use special render function to preserve React context, in case children need it
ReactDOM.unstable_renderSubtreeIntoContainer(
/* parentComponent */ this, React.createElement("div", __assign({}, props_1.removeNonHTMLProps(this.props), {ref: this.props.containerRef}), this.props.children), this.targetElement, function () { return utils_1.safeInvoke(_this.props.onChildrenMount); });
};
Portal.prototype.componentWillUnmount = function () {
ReactDOM.unmountComponentAtNode(this.targetElement);
this.targetElement.remove();
};
return Portal;
}(React.Component));
exports.Portal = Portal;
//# sourceMappingURL=portal.js.map