diff --git a/src/components/HowItWorksPage/EconomyFlow/index.tsx b/src/components/HowItWorksPage/EconomyFlow/index.tsx index 65817b3f..1235c85e 100644 --- a/src/components/HowItWorksPage/EconomyFlow/index.tsx +++ b/src/components/HowItWorksPage/EconomyFlow/index.tsx @@ -1,14 +1,33 @@ import Image from "next/image"; import { allBgImg, demmortalBlastFrame } from "../../../store/img"; import { motion } from "framer-motion"; -import { useState } from "react"; +import { useEffect, useRef, useState } from "react"; const EconomyFlow: React.FC = () => { - const [isActive,setIsActive] = useState(false); + const [isActive, setIsActive] = useState(false); + const imageRef = useRef(null); const clickHandler = () => { - setIsActive(prevState=>!prevState) - console.log("hellllllllo"); - } + setIsActive((prevState) => !prevState); + }; + const handleOutsideClick = (event: any) => { + if ( + isActive && + imageRef.current && + // @ts-ignore + !imageRef.current.contains(event.target) + ) { + setIsActive(false); + } + }; + useEffect(() => { + if (isActive) { + document.addEventListener('mousedown', handleOutsideClick); + } + + return () => { + document.removeEventListener('mousedown', handleOutsideClick); + }; + }, [isActive]); return (
{ Economy Flow
- +