import React, { useRef, useState, useEffect } from 'react'; import { HiPlus, HiChevronDown } from 'react-icons/hi2'; import { Button } from '../../../ui/Button'; import { ScrollArea } from '../../../ui/scroll-area'; import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from '../../../ui/dropdown-menu'; import { cn } from '../../../../lib/utils'; import { WorkingBlock } from '../../../../types/block-tester.types'; import BlockTab from './BlockTab'; /** * Props for the BlockTabs component */ export interface BlockTabsProps { blocks: WorkingBlock[]; activeIndex: number; blockStates: Record; onTabSwitch: (index: number) => void; onTabClose: (index: number) => void; onTabCreate: () => void; onTabDuplicate: (index: number) => void; onTabReorder: (fromIndex: number, toIndex: number) => void; className?: string; } /** * Block tabs component with tab strip interface * Supports overflow handling and tab management */ const BlockTabs: React.FC = ({ blocks, activeIndex, blockStates, onTabSwitch, onTabClose, onTabCreate, onTabDuplicate, onTabReorder, className }) => { const [showOverflow, setShowOverflow] = useState(false); const tabsRef = useRef(null); useEffect(() => { const checkOverflow = () => { if (tabsRef.current) { const container = tabsRef.current; const isOverflowing = container.scrollWidth > container.clientWidth; setShowOverflow(isOverflowing); } }; checkOverflow(); window.addEventListener('resize', checkOverflow); return () => { window.removeEventListener('resize', checkOverflow); }; }, [blocks.length]); const getOverflowedTabs = () => { return blocks.map((block, index) => ({ block, index })); }; return (
{/* Scrollable tab container */}
{blocks.map((block, index) => ( onTabSwitch(index)} onClose={blocks.length > 1 ? () => onTabClose(index) : undefined} onDuplicate={() => onTabDuplicate(index)} /> ))}
{/* Overflow dropdown */} {showOverflow && ( {getOverflowedTabs().map(({ block, index }) => ( onTabSwitch(index)} className={cn( "flex items-center gap-2", index === activeIndex && "bg-accent" )} > {block.name} {blockStates[block.id]?.isDirty && (
)} ))} )} {/* New tab button */}
); }; export default BlockTabs;