diff --git a/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/TextSizeMenu/index.jsx b/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/TextSizeMenu/index.jsx index 27e2c4154a8..d2a2359340f 100644 --- a/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/TextSizeMenu/index.jsx +++ b/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/TextSizeMenu/index.jsx @@ -1,140 +1,119 @@ -import { useState, useRef, useEffect } from "react"; +import { useState, useRef } from "react"; import { TextT } from "@phosphor-icons/react"; import { Tooltip } from "react-tooltip"; import { useTranslation } from "react-i18next"; +import { useTheme } from "@/hooks/useTheme"; export default function TextSizeButton() { - const [showTextSizeMenu, setShowTextSizeMenu] = useState(false); - const buttonRef = useRef(null); + const tooltipRef = useRef(null); const { t } = useTranslation(); + const { theme } = useTheme(); + + const toggleTooltip = () => { + if (!tooltipRef.current) return; + tooltipRef.current.isOpen + ? tooltipRef.current.close() + : tooltipRef.current.open(); + }; return ( <>
setShowTextSizeMenu(!showTextSizeMenu)} - className={`border-none relative flex justify-center items-center opacity-60 hover:opacity-100 light:opacity-100 light:hover:opacity-60 cursor-pointer ${ - showTextSizeMenu ? "!opacity-100" : "" - }`} + onClick={toggleTooltip} + className="border-none flex justify-center items-center opacity-60 hover:opacity-100 light:opacity-100 light:hover:opacity-60 cursor-pointer" > -
- + + + ); } -function TextSizeMenu({ showing, setShowing, buttonRef }) { +function TextSizeMenu({ tooltipRef }) { const { t } = useTranslation(); - const formRef = useRef(null); const [selectedSize, setSelectedSize] = useState( window.localStorage.getItem("anythingllm_text_size") || "normal" ); - useEffect(() => { - function listenForOutsideClick() { - if (!showing || !formRef.current) return false; - document.addEventListener("click", closeIfOutside); - } - listenForOutsideClick(); - }, [showing, formRef.current]); - - const closeIfOutside = ({ target }) => { - if (target.id === "text-size-btn") return; - const isOutside = !formRef?.current?.contains(target); - if (!isOutside) return; - setShowing(false); - }; - const handleTextSizeChange = (size) => { setSelectedSize(size); window.localStorage.setItem("anythingllm_text_size", size); window.dispatchEvent(new CustomEvent("textSizeChange", { detail: size })); + tooltipRef.current?.close(); }; - if (!buttonRef.current) return null; - return ( - ); }