import { getCSSVar } from "@/app/utils"; import { useMemo, useState } from "react"; const ArrowIcon = ({ color }: { color: string }) => { return ( ); }; const baseZIndex = 100; export default function Popover(props: { content?: JSX.Element | string; children?: JSX.Element; show?: boolean; onShow?: (v: boolean) => void; className?: string; popoverClassName?: string; trigger?: "hover" | "click"; placement?: "t" | "lt" | "rt" | "lb" | "rb" | "b"; noArrow?: boolean; bgcolor?: string; }) { const { content, children, show, onShow, className, popoverClassName, trigger = "hover", placement = "t", noArrow = false, bgcolor, } = props; const [internalShow, setShow] = useState(false); const mergedShow = show ?? internalShow; let placementClassName; let arrowClassName = "absolute left-[50%] translate-x-[calc(-50%)]"; // "absolute rotate-45 w-[8.5px] h-[8.5px] left-[50%] translate-x-[calc(-50%)] bg-black rounded-[1px] "; arrowClassName += " "; switch (placement) { case "b": placementClassName = "top-[calc(100%+0.5rem)] left-[50%] translate-x-[calc(-50%)]"; arrowClassName += "top-[calc(100%+0.5rem)] translate-y-[calc(-100%)]"; break; // case 'l': // placementClassName = ''; // break; // case 'r': // placementClassName = ''; // break; case "rb": placementClassName = "top-[calc(100%+0.5rem)] translate-x-[calc(-2%)]"; arrowClassName += "top-[calc(100%+0.5rem)] translate-y-[calc(-100%)]"; break; case "lt": placementClassName = "bottom-[calc(100%+0.5rem)] left-[100%] translate-x-[calc(-98%)]"; arrowClassName += "bottom-[calc(100%+0.5rem)] translate-y-[calc(100%)]"; break; case "lb": placementClassName = "top-[calc(100%+0.5rem)] left-[100%] translate-x-[calc(-98%)]"; arrowClassName += "top-[calc(100%+0.5rem)] translate-y-[calc(-100%)]"; break; case "rt": placementClassName = "bottom-[calc(100%+0.5rem)] translate-x-[calc(-2%)]"; arrowClassName += "bottom-[calc(100%+0.5rem)] translate-y-[calc(100%)]"; break; case "t": default: placementClassName = "bottom-[calc(100%+0.5rem)] left-[50%] translate-x-[calc(-50%)]"; arrowClassName += "bottom-[calc(100%+0.5rem)] translate-y-[calc(100%)]"; } const popoverCommonClass = "absolute p-2 box-border"; if (noArrow) { arrowClassName = "hidden"; } const internalBgColor = useMemo(() => { return bgcolor ?? getCSSVar("--tip-popover-color"); }, [bgcolor]); if (trigger === "click") { return (