import React, { type PropsWithChildren, useEffect, useState } from 'react'; interface Props { inner: React.ReactNode position: string space: number extraClasses?: string hint?: string } export default function Popup({ inner, position, space, extraClasses, children }: PropsWithChildren) { const [isVisible, setIsVisible] = useState(false); const [showPopup, setShowPopup] = useState(true); useEffect(() => { const mediaQuery = window.matchMedia('(min-width: 640px)'); const handleChange = (e: MediaQueryListEvent) => { setShowPopup(e.matches); }; setShowPopup(mediaQuery.matches); mediaQuery.addEventListener('change', handleChange); return () => mediaQuery.removeEventListener('change', handleChange); }, []); let positionClasses = ''; let spaceCSS: React.CSSProperties = {}; if (position === 'top') { positionClasses = `top-${space} -bottom-2 -translate-y-1/2 -translate-x-1/2`; } else if (position === 'right') { positionClasses = `bottom-1 -translate-x-1/2`; spaceCSS = { left: 70 + space }; } return (
setIsVisible(true)} onMouseLeave={() => setIsVisible(false)} > {children} {showPopup && (
{inner}
)}
); }