diff --git a/app/components/SectionsDisplay.jsx b/app/components/SectionsDisplay.jsx index 7ef4919..c4e2c50 100755 --- a/app/components/SectionsDisplay.jsx +++ b/app/components/SectionsDisplay.jsx @@ -1,27 +1,69 @@ 'use client'; import Link from 'next/link'; -import { motion } from 'framer-motion'; +import { motion, AnimatePresence } from 'framer-motion'; import { FiChevronRight, FiSearch, FiInfo } from 'react-icons/fi'; -import { useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; const InfoPopup = ({ info }) => { return ( -
+ {Object.entries(info).map(([key, value]) => (
{key}: {value}
))} -
+ ); }; const SectionsDisplay = ({ sections, searchQuery }) => { const [hoveredSection, setHoveredSection] = useState(null); + // Touch devices get tap-to-toggle; pointer devices keep the hover behaviour. + const [hasHover, setHasHover] = useState(true); + const infoRef = useRef(null); + + useEffect(() => { + const mq = window.matchMedia('(hover: hover) and (pointer: fine)'); + const update = () => setHasHover(mq.matches); + update(); + mq.addEventListener('change', update); + return () => mq.removeEventListener('change', update); + }, []); + + // Dismiss the popup on scroll, on a tap outside it, or on Escape. + useEffect(() => { + if (hoveredSection === null || hasHover) return; + + const close = () => setHoveredSection(null); + const onPointerDown = (e) => { + if (!infoRef.current?.contains(e.target)) close(); + }; + const onKeyDown = (e) => { + if (e.key === 'Escape') close(); + }; + + window.addEventListener('scroll', close, { passive: true, capture: true }); + window.addEventListener('resize', close); + document.addEventListener('pointerdown', onPointerDown); + document.addEventListener('keydown', onKeyDown); + return () => { + window.removeEventListener('scroll', close, { capture: true }); + window.removeEventListener('resize', close); + document.removeEventListener('pointerdown', onPointerDown); + document.removeEventListener('keydown', onKeyDown); + }; + }, [hoveredSection, hasHover]); return ( -
+
{sections.map((section, sectionIndex) => ( { className="group relative bg-white dark:bg-neutral-950 rounded-2xl shadow-sm border border-gray-200 dark:border-gray-700/50 overflow-hidden transition-all duration-300 hover:shadow-lg hover:border-blue-400/30 dark:hover:border-blue-500/30" > {/* Section Header */} -
+
{section.icon} @@ -39,15 +81,30 @@ const SectionsDisplay = ({ sections, searchQuery }) => {

{section.title}

{section.info && ( -
setHoveredSection(sectionIndex)} - onMouseLeave={() => setHoveredSection(null)} + ref={hoveredSection === sectionIndex ? infoRef : null} + onMouseEnter={hasHover ? () => setHoveredSection(sectionIndex) : undefined} + onMouseLeave={hasHover ? () => setHoveredSection(null) : undefined} > - - {hoveredSection === sectionIndex && ( - - )} + + + {hoveredSection === sectionIndex && ( + + )} +
)}
diff --git a/app/components/hero.jsx b/app/components/hero.jsx index 3ab0185..0410fdf 100755 --- a/app/components/hero.jsx +++ b/app/components/hero.jsx @@ -51,9 +51,9 @@ const HeroSection = () => { className="path" /> - Updates: Stack Visualization Updated ! + New : Added Graphs & Trees visualizer ! - +