import { ReactNode, useRef } from 'react' import { useActivePill } from './useActivePill' import { selectionHaptic } from '../../native/haptics' export interface MSegmentedOption { value: T label: ReactNode } interface MSegmentedProps { options: MSegmentedOption[] value: T onChange: (value: T) => void /** stretch = equal-width segments (costs tabs), intrinsic = pill hugs its label (dashboard filter) */ variant?: 'stretch' | 'intrinsic' className?: string } /** * Segment pill with a sliding active indicator. Active segment reads in * --m-actfg on the --m-act pill, idle segments in --m-ink (Spec 07 ยง6). */ export default function MSegmented({ options, value, onChange, variant = 'stretch', className = '', }: MSegmentedProps) { const trackRef = useRef(null) const pill = useActivePill(trackRef, '[data-active="true"]', [value, options.length]) return (
{pill && ) }