import { useRef } from 'react'; export default function Segmented({ label, options, value, onChange, variant = 'radio', className = '', itemClassName = '' }) { const groupRef = useRef(null); const tabs = variant === 'tabs'; function onKeyDown(e) { const step = { ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1 }[e.key]; if (!step) return; e.preventDefault(); e.stopPropagation(); const i = options.findIndex(o => o.value === value); const next = options[(i + step + options.length) % options.length]; onChange(next.value); groupRef.current?.querySelector(`[data-value="${next.value}"]`)?.focus(); } return (
{options.map(o => { const active = o.value === value; return ( ); })}
); }