{"version":3,"file":"Portal.cjs","names":[],"sources":["../../../src/components/Portal/Portal.tsx"],"sourcesContent":["import { useEffect, useState, type ReactNode } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { usePortalHost } from \"./portal-host\";\n\nexport interface PortalProps {\n    /** Content rendered through the portal. */\n    children: ReactNode;\n    /**\n     * Target DOM node to render into.\n     *\n     * Defaults to the fullscreen element while one is presented, and to\n     * `document.body` otherwise.\n     */\n    container?: Element | null;\n}\n\n/**\n * Renders its children into a different part of the DOM tree via a React portal.\n *\n * Useful for overlays (modals, tooltips, dropdowns) that must escape parent\n * overflow/stacking contexts.\n *\n * Without `container` the target is the element currently presented fullscreen,\n * and `document.body` the rest of the time. `body` alone would be wrong during\n * fullscreen: the browser paints only the fullscreen element's subtree, so an\n * overlay mounted outside it is invisible and unclickable while looking perfectly\n * healthy in the DOM. Passing `container` opts out of that and pins the target.\n *\n * SSR-safe: renders `null` on the server and on the first client render, then\n * mounts the portal after hydration (when `document` is available).\n *\n * @param props - The portal props.\n * @returns The portal node once mounted, otherwise `null`.\n */\nexport function Portal({ children, container }: PortalProps): ReactNode {\n    const [mounted, setMounted] = useState(false);\n    const host = usePortalHost();\n\n    useEffect(() => {\n        setMounted(true);\n        return () => setMounted(false);\n    }, []);\n\n    const target = container ?? host;\n    if (!mounted || !target) return null;\n\n    return createPortal(children, target);\n}\n"],"mappings":"mFAkCA,SAAgB,EAAO,CAAE,WAAU,aAAqC,CACpE,GAAM,CAAC,EAAS,IAAA,EAAc,EAAA,SAAA,CAAS,EAAK,EACtC,EAAO,EAAA,cAAc,GAE3B,EAAA,EAAA,UAAA,MACI,EAAW,EAAI,MACF,EAAW,EAAK,GAC9B,CAAC,CAAC,EAEL,IAAM,EAAS,GAAa,EAG5B,MAFI,CAAC,GAAW,CAAC,EAAe,MAEhC,EAAO,EAAA,aAAA,CAAa,EAAU,CAAM,CACxC"}