From f81a2151335ec805d53ae6090ced9a56cf82ef68 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 7 Apr 2025 15:16:41 +0700 Subject: [PATCH] tooltip updates + close on click / popover open --- .../app/components/reusable/Tooltip.tsx | 71 ++++++++++++++++-- .../comps/GenerateModals/Activity.tsx | 2 +- .../PageEnigma/comps/PromptBox/PromptBox.tsx | 74 +++++++++++-------- 3 files changed, 112 insertions(+), 35 deletions(-) diff --git a/frontend/editor3d/app/components/reusable/Tooltip.tsx b/frontend/editor3d/app/components/reusable/Tooltip.tsx index 15bc2ead7c..09b430bf2c 100644 --- a/frontend/editor3d/app/components/reusable/Tooltip.tsx +++ b/frontend/editor3d/app/components/reusable/Tooltip.tsx @@ -1,4 +1,4 @@ -import React, { useState, useRef } from "react"; +import React, { useState, useRef, useEffect } from "react"; import { Transition } from "@headlessui/react"; import { twMerge } from "tailwind-merge"; @@ -8,6 +8,7 @@ interface TooltipProps { position: "top" | "bottom" | "left" | "right"; className?: string; delay?: number; + closeOnClick?: boolean; } export const Tooltip = ({ @@ -16,11 +17,48 @@ export const Tooltip = ({ position, className, delay = 300, + closeOnClick = false, }: TooltipProps) => { const [isShowing, setIsShowing] = useState(false); const triggerRef = useRef(null); const tooltipRef = useRef(null); + const checkForOpenPopovers = () => { + if (!triggerRef.current) return false; + return ( + triggerRef.current.querySelectorAll('[data-headlessui-state="open"]') + .length > 0 + ); + }; + + useEffect(() => { + const observer = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + if ( + mutation.type === "attributes" && + mutation.attributeName === "data-headlessui-state" + ) { + const target = mutation.target as HTMLElement; + if (target.getAttribute("data-headlessui-state") === "open") { + setIsShowing(false); + } + } + }); + }); + + if (triggerRef.current) { + observer.observe(triggerRef.current, { + attributes: true, + subtree: true, + attributeFilter: ["data-headlessui-state"], + }); + } + + return () => { + observer.disconnect(); + }; + }, []); + const getStyleForPosition = () => { if (triggerRef.current) { const rect = triggerRef.current.getBoundingClientRect(); @@ -55,17 +93,34 @@ export const Tooltip = ({ } }; + const handleClick = (e: React.MouseEvent) => { + if (closeOnClick) { + setIsShowing(false); + e.stopPropagation(); + } + }; + return (
setIsShowing(true)} - onMouseLeave={() => setIsShowing(false)} + onMouseEnter={() => { + if (!checkForOpenPopovers()) { + setIsShowing(true); + } + }} + onMouseLeave={() => { + setIsShowing(false); + }} + onClick={handleClick} className="relative" > {children}
+ {
- - } - /> - - } - showAddButton - showIconsInList - mode="toggle" - panelTitle="Camera" - panelActionLabel="Settings" - onPanelAction={() => setIsCameraSettingsOpen(true)} - /> + + + } + /> + + + + } + showAddButton + showIconsInList + mode="toggle" + panelTitle="Camera" + panelActionLabel="Settings" + onPanelAction={() => setIsCameraSettingsOpen(true)} + /> + { } position="top" className="z-50" - delay={100} + delay={200} > { content="Download frame" position="top" className="z-50" - delay={100} + closeOnClick={true} + delay={200} >