'use client'; import { forwardRef, HTMLAttributes } from 'react'; export interface TimelineEra { /** Era identifier/index */ value: string | number; /** Label to display (e.g., year or era name) */ label: string; /** Optional aria label for accessibility */ ariaLabel?: string; /** Whether this era is currently active */ active?: boolean; /** Additional data attributes */ data?: Record; } export interface TimelineNavProps extends HTMLAttributes { /** Array of eras/timeline points */ eras: TimelineEra[]; /** Orientation of the timeline */ orientation?: 'horizontal' | 'vertical'; /** Callback when an era is clicked */ onEraClick?: (era: TimelineEra, index: number) => void; /** Show labels */ showLabels?: boolean; /** Show connecting line */ showLine?: boolean; /** Dot size */ dotSize?: 'small' | 'medium' | 'large'; } const orientationClasses: Record = { horizontal: 'flex-row items-center gap-6', vertical: 'flex-col items-center gap-8', }; const lineClasses: Record = { horizontal: 'top-1/2 left-0 right-0 h-0.5 -translate-y-1/2 bg-gradient-to-r from-transparent via-current to-transparent', vertical: 'left-1/2 top-0 bottom-0 w-0.5 -translate-x-1/2 bg-gradient-to-b from-transparent via-current to-transparent', }; const dotSizeClasses: Record = { small: 'w-2 h-2', medium: 'w-3 h-3', large: 'w-4.5 h-4.5', }; const activeDotSizeClasses: Record = { small: 'w-4 h-4', medium: 'w-6 h-6', large: 'w-9 h-9', }; const labelClasses: Record = { horizontal: 'top-full mt-2', vertical: 'left-full ml-3', }; export const TimelineNav = forwardRef( ( { eras, orientation = 'horizontal', onEraClick, showLabels = true, showLine = true, dotSize = 'medium', className, ...props }, ref ) => { return ( {showLine && ( )} {eras.map((era) => ( onEraClick?.(era, eras.indexOf(era))} aria-label={era.ariaLabel || `Era: ${era.label}`} aria-current={era.active ? 'step' : undefined} {...era.data} > {era.active && ( )} {showLabels && ( {era.label} )} ))} ); } ); TimelineNav.displayName = 'TimelineNav'; export default TimelineNav;