@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.
35 lines (33 loc) • 1.2 kB
JavaScript
'use client';
import * as React from 'react';
import { useTooltipRootContext } from "../root/TooltipRootContext.js";
import { TooltipPortalContext } from "./TooltipPortalContext.js";
import { FloatingPortalLite } from "../../utils/FloatingPortalLite.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 Tooltip](https://base-ui.com/react/components/tooltip)
*/
import { jsx as _jsx } from "react/jsx-runtime";
export const TooltipPortal = /*#__PURE__*/React.forwardRef(function TooltipPortal(props, forwardedRef) {
const {
keepMounted = false,
...portalProps
} = props;
const store = useTooltipRootContext();
const mounted = store.useState('mounted');
const shouldRender = mounted || keepMounted;
if (!shouldRender) {
return null;
}
return /*#__PURE__*/_jsx(TooltipPortalContext.Provider, {
value: keepMounted,
children: /*#__PURE__*/_jsx(FloatingPortalLite, {
ref: forwardedRef,
...portalProps
})
});
});
if (process.env.NODE_ENV !== "production") TooltipPortal.displayName = "TooltipPortal";