import { useEffect, useRef } from "react"; const TABS = [ { label: "Home" }, { label: "Timeline" } ]; interface AnimatedTabsProps { activeTab: string; setActiveTab: (tab: string) => void; } export function AnimatedTabs({ activeTab, setActiveTab }: AnimatedTabsProps) { const containerRef = useRef(null); const activeTabRef = useRef(null); useEffect(() => { const container = containerRef.current; if (container && activeTab) { const activeTabElement = activeTabRef.current; if (activeTabElement) { const { offsetLeft, offsetWidth } = activeTabElement; const clipLeft = offsetLeft; const clipRight = offsetLeft + offsetWidth; container.style.clipPath = `inset(0 ${Number(100 - (clipRight / container.offsetWidth) * 100).toFixed()}% 0 ${Number((clipLeft / container.offsetWidth) * 100).toFixed()}% round 17px)`; } } }, [activeTab, activeTabRef, containerRef]); return (
{TABS.map((tab, index) => ( ))}
{TABS.map(({ label }, index) => { const isActive = activeTab === label; return ( ); })}
); }