import React, { useEffect, useRef } from 'react'; import { ChevronLeft, ChevronRight } from 'lucide-react'; export interface SubView { id: T; label: string; description: string; } interface SubViewSliderProps { views: SubView[]; activeView: T; onViewChange: (view: T) => void; } const SubViewSlider = ({ views, activeView, onViewChange }: SubViewSliderProps) => { const activeIndex = Math.max(0, views.findIndex((view) => view.id === activeView)); const activeRef = useRef(null); const move = (direction: -1 | 1) => { const nextIndex = (activeIndex + direction + views.length) % views.length; onViewChange(views[nextIndex].id); }; // Keep the active card in view as the user pages through subviews. useEffect(() => { activeRef.current?.scrollIntoView({ behavior: 'smooth', inline: 'center', block: 'nearest' }); }, [activeView]); return (
{views.map((view, index) => { const active = view.id === activeView; return ( ); })}
); }; export default SubViewSlider;