UNPKG

@kiwicom/orbit-components

Version:

Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.

43 lines (33 loc) 1.12 kB
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } import * as React from "react"; import ReactDOM from "react-dom"; export default class Portal extends React.Component { constructor(props) { super(props); _defineProperty(this, "node", void 0); _defineProperty(this, "el", void 0); if (typeof window !== "undefined") { this.node = this.props.element && document.getElementById(this.props.element) ? document.getElementById(this.props.element) : document.body; this.el = document.createElement("div"); } } componentDidMount() { if (this.node && this.el) { this.node.appendChild(this.el); } } componentWillUnmount() { if (this.node && this.el) { this.node.removeChild(this.el); } } render() { const { children } = this.props; if (typeof window !== "undefined" && this.el) { return ReactDOM.createPortal(children, this.el); } return null; } }