import { useId, useState, type CSSProperties, type ReactNode } from 'react' /** * One entry of a chart's colour key. `color` comes from the same palette constant the visual draws with (BOX_COLORS, * MEETING_GREYS, HOUSE_THEME.ramp, ...), never a copy of the hex, so the key cannot drift from the chart (#1409). */ export interface LegendItem { key: string /** Plain words for what this colour or shape means, in the topic's own position words where there are any. */ label: ReactNode color?: string /** `square` (default), `dot`, `ring` (a town on record), `hatch` (proposed), `ramp` (darker = more), `line`. */ shape?: 'square' | 'dot' | 'ring' | 'hatch' | 'ramp' | 'line' /** A class that colours the swatch (for marks coloured by a stylesheet class, e.g. `stance-swatch stance-dot--against`). */ className?: string /** The ramp's colours, light to dark (shape `ramp`). */ ramp?: readonly string[] } export interface ChartFrameProps { /** What the chart says, in plain words: the data's own conclusion or "Short-term rental meetings by county ยท Florida". */ title: ReactNode /** The colour key. Required: a visual never ships without saying what its colours and shapes mean. */ legend: readonly LegendItem[] | ReactNode /** One line saying what the visual shows (the description; the title is the takeaway). */ caption?: ReactNode /** The numbers behind the title, on a tap or hover of the info button (never a guess). */ titleSupport?: string | null /** Where the numbers come from (one short line). */ source?: ReactNode children: ReactNode /** The title's element; the page's own heading level decides. */ titleAs?: 'div' | 'p' | 'h2' | 'h3' | 'h4' className?: string style?: CSSProperties /** Key above the visual instead of below. */ legendFirst?: boolean /** A picker or button beside the title (the county map's "United States" and state picker). */ controls?: ReactNode /** Class names for the title row and the key, for figures that lay them out on a grid. */ headClassName?: string legendClassName?: string titleClassName?: string /** Extra attributes for the root (a `data-*` hook). */ rootProps?: Record } const SW = 9 function Swatch({ item }: { item: LegendItem }) { const color = item.color ?? 'currentColor' const base: CSSProperties = { display: 'inline-block', flex: 'none', width: SW, height: SW } if (item.className) return