UNPKG

@kubit-ui-web/react-components

Version:

Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience

34 lines 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Portal = void 0; const react_dom_1 = require("react-dom"); /** * Creates a wrapper element and appends it to the <body> tag. * @param wrapperId - The ID of the wrapper element. * @returns The created wrapper element. */ const createWrapperAndAppendToBody = (wrapperId) => { const wrapperElement = document.createElement('div'); wrapperElement.setAttribute('id', wrapperId); document.body.appendChild(wrapperElement); return wrapperElement; }; /** * @deprecated This component has been deprecated and will be not exported in the next MAJOR release * Renders a portal component that can be appended to the <body> tag or a custom wrapper element. * @param children - The content to be rendered inside the portal. * @param wrapperId - The ID of the custom wrapper element (optional). * @returns The portal component. */ const Portal = ({ children, wrapperId }) => { let element = document.body; if (wrapperId) { element = document.getElementById(wrapperId); if (!element) { element = createWrapperAndAppendToBody(wrapperId); } } return (0, react_dom_1.createPortal)(children, element); }; exports.Portal = Portal; //# sourceMappingURL=portal.js.map