import { useRef, useState, useLayoutEffect } from 'react' import type { IconComponent } from '../shared/Icons' export interface Tab { value: T label: string Icon?: IconComponent } interface TabsProps { value: T onChange: (value: T) => void tabs: Tab[] className?: string } export function Tabs({ value, onChange, tabs, className = '', }: TabsProps) { const containerRef = useRef(null) const [indicatorStyle, setIndicatorStyle] = useState({ left: 0, width: 0 }) useLayoutEffect(() => { const container = containerRef.current if (!container) return const activeIndex = tabs.findIndex(tab => tab.value === value) const buttons = container.querySelectorAll('button') const activeButton = buttons[activeIndex] if (activeButton) { setIndicatorStyle({ left: activeButton.offsetLeft, width: activeButton.offsetWidth, }) } }, [value, tabs]) return (
{tabs.map((tab) => { const isActive = tab.value === value return ( ) })}
) }