import React, { useState, useRef, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import type { TabbedContainerProps } from '../types/TabbedContainerProps'; import { useSettingsContext } from '../SettingsContext'; const TabbedContainer: React.FC = ({ tabs }) => { const [activeTab, setActiveTab] = useState(0); const [hoveredTab, setHoveredTab] = useState(null); const [tabWidth, setTabWidth] = useState(0); const [position, setPosition] = useState(0); const positionRef = useRef(position); const themeColor = useSettingsContext().settingsState.customThemeColor; useEffect(() => { const newPosition = -activeTab * 100; setPosition(newPosition); positionRef.current = newPosition; }, [activeTab]); const containerRef = useRef(null); const springTransition = { type: 'spring', stiffness: 250, damping: 25 }; const contentVariants = { hidden: { opacity: 0 }, visible: { opacity: 1 }, }; const fastOpacityTransition = { duration: 0.2 }; useEffect(() => { if (containerRef.current) { // @ts-expect-error for some reason its giving an error in TS but it works... const width = containerRef.current.getBoundingClientRect().width; setTabWidth(width / tabs.length); } }, [tabs.length]); const calcXPos = (index: number | null) => { if (index !== null) { return tabWidth * index; } return tabWidth * activeTab; }; return ( <>
{tabs.map((tab, index) => ( ))}
{tabs.map((tab, index) => ( activeTab === index && ( {tab.content} ) ))}
); }; export default TabbedContainer;