import { animate, AnimatePresence, cubicBezier, motion } from "motion/react"; import { useEffect, useRef, useState } from "react"; import { tabs } from "@/components/app/(home)/sections/hero-input/Tabs/Tabs"; import { cn } from "@/utils/cn"; import { Endpoint } from "@/components/shared/Playground/Context/types"; export default function HeroInputTabsMobile(props: { setTab: (tab: Endpoint) => void; tab: Endpoint; allowedModes?: Endpoint[]; }) { // Filter tabs based on allowedModes if provided const visibleTabs = props.allowedModes ? tabs.filter((tab) => props.allowedModes!.includes(tab.value)) : tabs; const activeTab = visibleTabs.find((tab) => tab.value === props.tab)!; const [isOpen, setIsOpen] = useState(false); const ref = useRef(null); useEffect(() => { if (window.innerWidth > 996) { return; } document.addEventListener("click", (e) => { if (ref.current && e.composedPath().includes(ref.current)) { return; } setIsOpen(false); }); }, []); return ( <> {isOpen && (
Output
)}
); } function MenuItems(props: { tab: Endpoint; setTab: (tab: Endpoint) => void; visibleTabs: typeof tabs; }) { const backgroundRef = useRef(null); return (
{props.visibleTabs.map((tab) => (
{ animate( backgroundRef.current!, { scaleX: [1, 0.99, 1], scaleY: [1, 0.96, 1], opacity: [1, 0.9, 1], }, { ease: cubicBezier(0.165, 0.84, 0.44, 1), duration: 0.15, }, ); props.setTab(tab.value); }} onMouseEnter={async (e) => { const child = e.currentTarget as HTMLElement; if (backgroundRef.current?.getBoundingClientRect().height === 0) { backgroundRef.current!.style.height = child.offsetHeight + "px"; } if (getComputedStyle(backgroundRef.current!).opacity === "0") { await animate( backgroundRef.current!, { y: child.offsetTop, }, { ease: cubicBezier(0.165, 0.84, 0.44, 1), duration: 0.01, }, ); } animate(backgroundRef.current!, { scale: 0.995 }).then(() => animate(backgroundRef.current!, { scale: 1 }), ); animate( backgroundRef.current!, { y: child.offsetTop, opacity: 1, height: child.offsetHeight + "px", }, { ease: cubicBezier(0.165, 0.84, 0.44, 1), duration: 0.2, }, ); }} onMouseLeave={() => { animate( backgroundRef.current!, { opacity: 0, }, { ease: cubicBezier(0.165, 0.84, 0.44, 1), duration: 0.2, }, ); }} >
{tab.label}
))}
); }