UNPKG

@base-ui-components/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

44 lines (42 loc) 1.57 kB
'use client'; import * as React from 'react'; import { inertValue } from '@base-ui-components/utils/inertValue'; import { FloatingPortal } from "../../floating-ui-react/index.js"; import { useDialogRootContext } from "../root/DialogRootContext.js"; import { DialogPortalContext } from "./DialogPortalContext.js"; import { InternalBackdrop } from "../../utils/InternalBackdrop.js"; /** * A portal element that moves the popup to a different part of the DOM. * By default, the portal element is appended to `<body>`. * Renders a `<div>` element. * * Documentation: [Base UI Dialog](https://base-ui.com/react/components/dialog) */ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; export const DialogPortal = /*#__PURE__*/React.forwardRef(function DialogPortal(props, forwardedRef) { const { keepMounted = false, ...portalProps } = props; const { store } = useDialogRootContext(); const mounted = store.useState('mounted'); const modal = store.useState('modal'); const shouldRender = mounted || keepMounted; if (!shouldRender) { return null; } return /*#__PURE__*/_jsx(DialogPortalContext.Provider, { value: keepMounted, children: /*#__PURE__*/_jsxs(FloatingPortal, { ref: forwardedRef, ...portalProps, children: [mounted && modal === true && /*#__PURE__*/_jsx(InternalBackdrop, { ref: store.context.internalBackdropRef, inert: inertValue(!open) }), props.children] }) }); }); if (process.env.NODE_ENV !== "production") DialogPortal.displayName = "DialogPortal";