/** * InflationToggle — compact Nominal / Real pill for dollar charts. * * Matches the mockup: rounded-full pill, light gray track, white active * segment with subtle shadow. Stays small enough to sit in a KPI card * header without competing for attention with the headline number. * * State lives in ``useInflationToggle`` (localStorage-persisted, cross-tab * synced); this component is purely presentational, so the same hook can * drive multiple toggles on a page and they stay in sync. */ import type { InflationMode } from '../hooks/useInflationToggle' interface Props { mode: InflationMode onChange: (next: InflationMode) => void /** Hidden visually but read by screen readers — e.g. "median home value". */ ariaLabel?: string className?: string /** * CPI deflator couldn't be loaded (e.g. ``/api/cpi/annual`` failed), so real * dollars can't be computed. We render nominal regardless, so reflect that * honestly: disable the "Real" option and show Nominal as active rather than * leaving "Real" highlighted while the figures are actually nominal. */ realUnavailable?: boolean } export default function InflationToggle({ mode, onChange, ariaLabel, className, realUnavailable = false, }: Props) { const labelledBy = ariaLabel ? `inflation-toggle-${ariaLabel.replace(/\s+/g, '-')}` : undefined // When the deflator is unavailable the card shows nominal no matter the // persisted preference, so the pill must show Nominal as the live state. const effectiveMode: InflationMode = realUnavailable ? 'nominal' : mode return (
{labelledBy ? ( {ariaLabel}: nominal or real dollars ) : null}
) }