import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
import { useEffect, useState } from 'react';
import { createPortal } from 'react-dom';
/** Provided children are portaled to document.body or custom container. */
export const Portal = props => {
    const { children, containerRef, disablePortal } = props;
    const [mountNode, setMountNode] = useState();
    useEffect(() => {
        if (!disablePortal) {
            setMountNode(containerRef?.current ?? document.body);
        }
    }, [disablePortal]);
    if (disablePortal)
        return _jsx(_Fragment, { children: children });
    return mountNode ? createPortal(children, mountNode) : _jsx(_Fragment, { children: mountNode });
};
Portal.displayName = 'Portal';
export default Portal;
//# sourceMappingURL=portal.js.map