/* eslint-disable no-unused-vars */ import { useRef, useEffect, useState } from "react"; import { gsap } from "gsap"; import "./FlowingMenu.css"; import { ScrollToPlugin } from "gsap/ScrollToPlugin"; gsap.registerPlugin(ScrollToPlugin); function FlowingMenu({ items = [], speed = 15, textColor = "#fff", bgColor = "transparent", marqueeBgColor = "rgba(0,0,0,0.8)", // Sera écrasé par le CSS pour le glassmorphism marqueeTextColor = "#fff", borderColor = "rgba(255,255,255,0.1)", }) { const [activeIdx, setActiveIdx] = useState(null); const toggleItem = (idx) => { setActiveIdx(activeIdx === idx ? null : idx); }; return (
); } function MenuItem({ text, image, speed, textColor, marqueeBgColor, marqueeTextColor, borderColor, isOpen, onClick, Component, }) { const itemRef = useRef(null); const marqueeRef = useRef(null); const marqueeInnerRef = useRef(null); const contentRef = useRef(null); const [repetitions, setRepetitions] = useState(2); useEffect(() => { const calculateRepetitions = () => { if (!marqueeInnerRef.current) return; const singlePart = marqueeInnerRef.current.querySelector(".marquee__part"); if (!singlePart) return; const partWidth = singlePart.offsetWidth; const windowWidth = window.innerWidth; if (partWidth > 0) { const needed = Math.ceil(windowWidth / partWidth) + 4; setRepetitions(needed); } }; calculateRepetitions(); window.addEventListener("resize", calculateRepetitions); return () => window.removeEventListener("resize", calculateRepetitions); }, [text]); useEffect(() => { const marqueeContent = marqueeInnerRef.current?.querySelector(".marquee__part"); if (!marqueeContent) return; const contentWidth = marqueeContent.offsetWidth; if (contentWidth === 0) return; const tl = gsap.to(marqueeInnerRef.current, { x: -contentWidth, duration: speed, ease: "none", repeat: -1, }); return () => tl.kill(); }, [speed, repetitions]); useEffect(() => { if (isOpen) { gsap.to(contentRef.current, { height: "auto", opacity: 1, duration: 0.6, ease: "power3.out", }); gsap.to(window, { duration: 1, delay: 0.4, scrollTo: { y: itemRef.current, offsetY: 60, autoKill: true, }, ease: "power3.inOut", }); gsap.to(marqueeRef.current, { y: "101%", duration: 0.4, ease: "power2.out", }); } else { gsap.to(contentRef.current, { height: 0, opacity: 0, duration: 0.4, ease: "power3.in", }); } }, [isOpen]); const handleMouseEnter = () => { if (isOpen) return; gsap.to(marqueeRef.current, { y: "0%", duration: 0.6, ease: "expo" }); gsap.set(marqueeInnerRef.current, { force3D: true }); }; const handleMouseLeave = () => { gsap.to(marqueeRef.current, { y: "101%", duration: 0.6, ease: "expo" }); }; return (
{text}
{/* ZONE DÉTAILS */}
{Component && }
{/* MARQUEE */} {/* Note : Le background est géré par le CSS pour le glassmorphism */}
); } export default FlowingMenu;