@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.
51 lines (49 loc) • 1.86 kB
JavaScript
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import { FloatingPortal } from '@floating-ui/react';
import { usePortalContext } from './PortalContext.js';
import { HTMLElementType, refType } from '../utils/proptypes.js';
/**
* A portal element that moves the popup to a different part of the DOM.
* By default, the portal element is appended to `<body>`.
*
* Documentation: https://base-ui.com
*/
import { jsx as _jsx } from "react/jsx-runtime";
function Portal(props) {
const {
children,
container,
keepMounted = false
} = props;
const mounted = usePortalContext();
const shouldRender = mounted || keepMounted;
if (!shouldRender) {
return null;
}
return /*#__PURE__*/_jsx(FloatingPortal, {
root: container,
children: children
});
}
process.env.NODE_ENV !== "production" ? Portal.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* @ignore
*/
children: PropTypes.node,
/**
* A parent element to render the portal into.
*/
container: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([HTMLElementType, refType]),
/**
* Whether to keep the portal mounted in the DOM while the popup is hidden.
* @default false
*/
keepMounted: PropTypes.bool
} : void 0;
export { Portal };