/** * Tabs primitive — horizontal tab bar with overflow scroll arrows * tabs: [{ label, value, icon?, disabled? }] */ const { html } = window; const { useRef, useEffect, useState, useCallback } = hooks; export function Tabs({ tabs = [], active, onChange }) { const scrollRef = useRef(null); const [overflow, setOverflow] = useState({ left: false, right: false }); const checkOverflow = useCallback(() => { const el = scrollRef.current; if (!el) return; setOverflow({ left: el.scrollLeft > 0, right: el.scrollLeft + el.clientWidth < el.scrollWidth - 1, }); }, []); useEffect(() => { checkOverflow(); const el = scrollRef.current; if (el) el.addEventListener('scroll', checkOverflow, { passive: true }); window.addEventListener('resize', checkOverflow); return () => { if (el) el.removeEventListener('scroll', checkOverflow); window.removeEventListener('resize', checkOverflow); }; }, [checkOverflow, tabs]); const scroll = (dir) => { const el = scrollRef.current; if (el) el.scrollBy({ left: dir * 150, behavior: 'smooth' }); }; return html`
${overflow.left && html` `}
${tabs.map(tab => html` `)}
${overflow.right && html` `}
`; }