24 lines
869 B
JavaScript
24 lines
869 B
JavaScript
"use client";
|
|
|
|
// packages/react/portal/src/Portal.tsx
|
|
import * as React from "react";
|
|
import ReactDOM from "react-dom";
|
|
import { Primitive } from "@radix-ui/react-primitive";
|
|
import { useLayoutEffect } from "@radix-ui/react-use-layout-effect";
|
|
import { jsx } from "react/jsx-runtime";
|
|
var PORTAL_NAME = "Portal";
|
|
var Portal = React.forwardRef((props, forwardedRef) => {
|
|
const { container: containerProp, ...portalProps } = props;
|
|
const [mounted, setMounted] = React.useState(false);
|
|
useLayoutEffect(() => setMounted(true), []);
|
|
const container = containerProp || mounted && globalThis?.document?.body;
|
|
return container ? ReactDOM.createPortal(/* @__PURE__ */ jsx(Primitive.div, { ...portalProps, ref: forwardedRef }), container) : null;
|
|
});
|
|
Portal.displayName = PORTAL_NAME;
|
|
var Root = Portal;
|
|
export {
|
|
Portal,
|
|
Root
|
|
};
|
|
//# sourceMappingURL=index.mjs.map
|