@yamada-ui/popover
Version:
Yamada UI popover component
140 lines (138 loc) • 3.84 kB
JavaScript
"use client"
import {
PopoverCloseButton
} from "./chunk-YGXEZMNZ.mjs";
import {
usePopover
} from "./chunk-QNKQMZVS.mjs";
// src/popover-content.tsx
import { ui } from "@yamada-ui/core";
import { motion, motionForwardRef } from "@yamada-ui/motion";
import { scaleFadeProps, slideFadeProps } from "@yamada-ui/transitions";
import { cx, findChildren, funcAll, getValidChildren } from "@yamada-ui/utils";
import { jsx, jsxs } from "react/jsx-runtime";
var getPopoverContentProps = (animation = "scale", duration) => {
const custom = {
duration,
enter: { visibility: "visible" },
reverse: true,
transitionEnd: { exit: { visibility: "hidden" } }
};
switch (animation) {
case "scale":
return {
...scaleFadeProps,
custom: { ...custom, scale: 0.95 }
};
case "top":
return {
...slideFadeProps,
custom: { ...custom, offsetX: 0, offsetY: -16 }
};
case "right":
return {
...slideFadeProps,
custom: { ...custom, offsetX: 16, offsetY: 0 }
};
case "left":
return {
...slideFadeProps,
custom: { ...custom, offsetX: -16, offsetY: 0 }
};
case "bottom":
return {
...slideFadeProps,
custom: { ...custom, offsetX: 0, offsetY: 16 }
};
}
};
var PopoverContent = motionForwardRef(
({
className,
children,
maxW,
maxWidth = maxW,
minW,
minWidth = minW,
w,
width = w,
z,
zIndex = z,
containerProps,
__css,
...rest
}, ref) => {
var _a, _b, _c, _d, _e;
const {
animation,
closeOnButton,
duration,
open,
shouldRenderContent,
styles,
getPopoverProps,
getPopperProps,
onAnimationComplete
} = usePopover();
if (!shouldRenderContent) return null;
const validChildren = getValidChildren(children);
const [customPopoverCloseButton, ...cloneChildren] = findChildren(
validChildren,
PopoverCloseButton
);
const css = (_a = __css != null ? __css : styles.container) != null ? _a : {};
const computedCSS = {
display: "flex",
flexDirection: "column",
outline: 0,
position: "relative",
w: "100%",
...css
};
width != null ? width : width = (_b = css.width) != null ? _b : css.w;
minWidth != null ? minWidth : minWidth = (_c = css.minWidth) != null ? _c : css.minW;
maxWidth != null ? maxWidth : maxWidth = (_d = css.maxWidth) != null ? _d : css.maxW;
zIndex != null ? zIndex : zIndex = (_e = css.zIndex) != null ? _e : css.z;
return /* @__PURE__ */ jsx(
ui.div,
{
...getPopperProps({
style: { visibility: open ? "visible" : "hidden" }
}),
className: "ui-popover",
maxWidth,
minWidth,
outline: "none",
width,
zIndex,
...containerProps,
children: /* @__PURE__ */ jsxs(
motion.section,
{
className: cx("ui-popover__content", className),
...animation !== "none" ? getPopoverContentProps(animation, duration) : {},
...getPopoverProps(rest, ref),
animate: open ? "enter" : "exit",
exit: "exit",
initial: "exit",
onAnimationComplete: funcAll(
onAnimationComplete,
rest.onAnimationComplete
),
__css: computedCSS,
children: [
customPopoverCloseButton != null ? customPopoverCloseButton : closeOnButton ? /* @__PURE__ */ jsx(PopoverCloseButton, {}) : null,
cloneChildren
]
}
)
}
);
}
);
PopoverContent.displayName = "PopoverContent";
PopoverContent.__ui__ = "PopoverContent";
export {
PopoverContent
};
//# sourceMappingURL=chunk-ODLFQHGZ.mjs.map