UNPKG

@itwin/core-react

Version:

A react component library of iTwin.js UI general purpose components

57 lines 2.53 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Dialog */ import * as React from "react"; import * as ReactDOM from "react-dom"; import { Dialog } from "./Dialog.js"; /** GlobalDialog React component used to display a [[Dialog]] on the top of screen * @public * @deprecated in 4.12.0. Use {@link https://itwinui.bentley.com/docs/dialog iTwinUI dialog} instead. */ export class GlobalDialog extends React.Component { // eslint-disable-next-line @typescript-eslint/no-deprecated constructor(props) { super(props); // eslint-disable-next-line @typescript-eslint/no-deprecated this.state = { parentDocument: null, }; this._handleRefSet = (popupDiv) => { const parentDocument = popupDiv?.ownerDocument ?? null; if (parentDocument) { this._container = parentDocument.createElement("div"); this._container.id = this.props.identifier !== undefined ? `dialog-${this.props.identifier}` : "core-dialog"; let rt = parentDocument.getElementById("core-dialog-root"); if (!rt) { rt = parentDocument.createElement("div"); rt.id = "core-dialog-root"; parentDocument.body.appendChild(rt); } rt.appendChild(this._container); // used to support component rendering in pop-out window this.setState({ parentDocument }); } }; } componentWillUnmount() { if (this._container && this._container.parentElement) { // cleanup this._container.parentElement.removeChild(this._container); } } render() { const { identifier, ...props } = this.props; return (React.createElement("div", { ref: this._handleRefSet }, this.state.parentDocument && ReactDOM.createPortal( // eslint-disable-next-line @typescript-eslint/no-deprecated React.createElement(Dialog, { ...props }), this.state.parentDocument.body))); } } //# sourceMappingURL=GlobalDialog.js.map