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

30 lines 1.17 kB
import { createPortal } from '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. */ export const Portal = ({ children, wrapperId }) => { let element = document.body; if (wrapperId) { element = document.getElementById(wrapperId); if (!element) { element = createWrapperAndAppendToBody(wrapperId); } } return createPortal(children, element); }; //# sourceMappingURL=portal.js.map