@veracity/vui
Version:
Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.
50 lines (48 loc) • 1.59 kB
JavaScript
import { runIfFn } from "../utils/function.js";
import { filterUndefined } from "../utils/object.js";
import { PopoverProvider } from "./context.js";
import { PopoverContent } from "./popoverContent.js";
import { PopoverTrigger } from "./popoverTrigger.js";
import usePopover from "./usePopover.js";
import { jsx } from "react/jsx-runtime";
import { FloatingNode, FloatingTree, useFloatingNodeId, useFloatingParentNodeId } from "@floating-ui/react";
//#region src/popover/popover.tsx
/**
* Uses 'usePopover' hook to expose relevant data to its children parts.
* By default, renders provided content only when popover is opened (lazy).
*/
function PopoverInner(props) {
const nodeId = useFloatingNodeId();
const { children, isLazy = true, ...rest } = props;
const popoverProps = usePopover({
...rest,
nodeId
});
const { close, isOpen, open } = popoverProps;
const context = filterUndefined({
isLazy,
...popoverProps
});
return /* @__PURE__ */ jsx(FloatingNode, {
id: nodeId,
children: /* @__PURE__ */ jsx(PopoverProvider, {
value: context,
children: runIfFn(children, {
close,
isOpen,
open
})
})
});
}
function Popover(props) {
if (useFloatingParentNodeId() === null) return /* @__PURE__ */ jsx(FloatingTree, { children: /* @__PURE__ */ jsx(PopoverInner, { ...props }) });
return /* @__PURE__ */ jsx(PopoverInner, { ...props });
}
Popover.Content = PopoverContent;
Popover.Trigger = PopoverTrigger;
Popover.displayName = "Popover";
//#endregion
export { Popover as default };
globalThis.__vuiVersion__ = "5.3.1"
//# sourceMappingURL=popover.js.map