"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Portal = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const react_dom_1 = require("react-dom");
/** Provided children are portaled to document.body or custom container. */
const Portal = props => {
    const { children, containerRef, disablePortal } = props;
    const [mountNode, setMountNode] = (0, react_1.useState)();
    (0, react_1.useEffect)(() => {
        var _a;
        if (!disablePortal) {
            setMountNode((_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) !== null && _a !== void 0 ? _a : document.body);
        }
    }, [disablePortal]);
    if (disablePortal)
        return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
    return mountNode ? (0, react_dom_1.createPortal)(children, mountNode) : (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: mountNode });
};
exports.Portal = Portal;
exports.Portal.displayName = 'Portal';
exports.default = exports.Portal;
//# sourceMappingURL=portal.js.map