@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.
43 lines (42 loc) • 1.55 kB
JavaScript
;
'use client';
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PopoverPortal = void 0;
var React = _interopRequireWildcard(require("react"));
var _floatingUiReact = require("../../floating-ui-react");
var _PopoverRootContext = require("../root/PopoverRootContext");
var _PopoverPortalContext = require("./PopoverPortalContext");
var _jsxRuntime = require("react/jsx-runtime");
/**
* 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 Popover](https://base-ui.com/react/components/popover)
*/
const PopoverPortal = exports.PopoverPortal = /*#__PURE__*/React.forwardRef(function PopoverPortal(props, forwardedRef) {
const {
keepMounted = false,
...portalProps
} = props;
const {
store
} = (0, _PopoverRootContext.usePopoverRootContext)();
const mounted = store.useState('mounted');
const shouldRender = mounted || keepMounted;
if (!shouldRender) {
return null;
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_PopoverPortalContext.PopoverPortalContext.Provider, {
value: keepMounted,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_floatingUiReact.FloatingPortal, {
ref: forwardedRef,
...portalProps,
renderGuards: false
})
});
});
if (process.env.NODE_ENV !== "production") PopoverPortal.displayName = "PopoverPortal";