import React, { useState, useRef, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { ChevronLeft, ChevronRight } from 'lucide-react'; const SidebarTabs = ({ tabs, onTabChange }) => { const [activeTab, setActiveTab] = useState(tabs[0].id); const [showLeftArrow, setShowLeftArrow] = useState(false); const [showRightArrow, setShowRightArrow] = useState(false); const scrollRef = useRef(null); const handleTabChange = (tabId) => { setActiveTab(tabId); if (onTabChange) { onTabChange(tabId); } }; const updateArrows = () => { const el = scrollRef.current; if (!el) return; setShowLeftArrow(el.scrollLeft > 0); setShowRightArrow(el.scrollLeft + el.clientWidth < el.scrollWidth - 1); }; useEffect(() => { updateArrows(); const el = scrollRef.current; if (!el) return; el.addEventListener('scroll', updateArrows); window.addEventListener('resize', updateArrows); return () => { el.removeEventListener('scroll', updateArrows); window.removeEventListener('resize', updateArrows); }; }, [tabs]); const scroll = (direction) => { const el = scrollRef.current; if (!el) return; el.scrollBy({ left: direction === 'left' ? -150 : 150, behavior: 'smooth' }); }; return (
{/* Tabs Header */}
{/* Flèche gauche */} {showLeftArrow && ( )} {/* Liste des onglets scrollable */}
{tabs.map((tab) => ( ))}
{/* Flèche droite */} {showRightArrow && ( )}
{/* Tabs Content */}
{tabs.map( (tab) => activeTab === tab.id && ( {tab.content} ) )}
); }; export default SidebarTabs;