1- import { useState } from "react" ;
1+ import { useEffect , useRef , useState } from "react" ;
22import { NavLink } from "react-router-dom" ;
33import { Tooltip } from "flowbite-react" ;
44import { MdInfo , MdSearch , MdTableChart } from "react-icons/md" ;
@@ -11,6 +11,24 @@ const navItems = [
1111
1212export function Navbar ( ) {
1313 const [ footerOpen , setFooterOpen ] = useState ( false ) ;
14+ const infoPanelRef = useRef < HTMLDivElement > ( null ) ;
15+ const infoButtonRef = useRef < HTMLButtonElement > ( null ) ;
16+
17+ useEffect ( ( ) => {
18+ function handleClickOutside ( e : MouseEvent ) {
19+ const clickedInside =
20+ infoPanelRef . current ?. contains ( e . target as Node ) ||
21+ infoButtonRef . current ?. contains ( e . target as Node ) ;
22+ if ( ! clickedInside ) {
23+ setFooterOpen ( false ) ;
24+ }
25+ }
26+
27+ if ( footerOpen ) {
28+ document . addEventListener ( "mousedown" , handleClickOutside ) ;
29+ }
30+ return ( ) => document . removeEventListener ( "mousedown" , handleClickOutside ) ;
31+ } , [ footerOpen ] ) ;
1432
1533 return (
1634 < >
@@ -40,27 +58,22 @@ export function Navbar() {
4058 ) ) }
4159
4260 < div className = "mt-auto" >
43- < Tooltip
44- content = "Info"
45- placement = "right"
46- arrow = { false }
47- className = "bg-gray-600 z-10 backdrop-blur-sm bg-opacity-99 border-1"
61+ < button
62+ ref = { infoButtonRef }
63+ onClick = { ( ) => setFooterOpen ( ! footerOpen ) }
64+ className = { `w-9 h-9 flex items-center justify-center rounded-lg transition-colors duration-300 cursor-pointer ${
65+ footerOpen
66+ ? "bg-[#646cff] text-white"
67+ : "text-neutral-400 hover:bg-neutral-700 hover:text-white"
68+ } `}
4869 >
49- < button
50- onClick = { ( ) => setFooterOpen ( ! footerOpen ) }
51- className = { `w-9 h-9 flex items-center justify-center rounded-lg transition-colors duration-300 cursor-pointer ${
52- footerOpen
53- ? "bg-[#646cff] text-white"
54- : "text-neutral-400 hover:bg-neutral-700 hover:text-white"
55- } `}
56- >
57- < MdInfo size = { 20 } />
58- </ button >
59- </ Tooltip >
70+ < MdInfo size = { 20 } />
71+ </ button >
6072 </ div >
6173 </ nav >
6274
6375 < div
76+ ref = { infoPanelRef }
6477 className = { `fixed left-14 bottom-4 z-20 border-1 rounded-lg py-3 px-4 shadow-lg backdrop-blur-sm bg-[#1a1a1a] transition-all duration-300 ease-in-out ${
6578 footerOpen
6679 ? "opacity-100 translate-y-0"
0 commit comments