Displays statistical summaries (min / avg / max) with a visual range bar, current reading, and
current-vs-average delta. The details toggle is a real button with aria-expanded.
CwStatCard summarises a series with min, average and max, and can expand to show median, standard deviation, count and range. Values are formatted with the shared number formatter and the unit you pass.
How to think about it
Pass precomputed statistics`stats` takes `min`, `max`, `avg`, `median`, `stdDev`, `count`, `lastReading` and `trend`. Missing values render as "—".
Let people expand for detailWith `expandable`, a “Show details” button (a real `<button aria-expanded>`) reveals the extra statistics as a description list.
Keep the accent readable`accentColor` colours the average marker and value. The default uses `--cw-accent-text`, which meets text contrast in both themes.
Props and callbacks
API
Type
Details
titleRequired
string
Card heading.
statsRequired
CwStatCardData
Statistics to display.
unit
string
Unit shown after values, e.g. "°C".
accentColor
Default: var(--cw-accent-text)
string
CSS colour for the average highlight.
expandable
Default: false
boolean
Adds the Show/Hide details toggle.
headingLevel
Default: 3
1–6
Heading level of the title.
loading
Default: false
boolean
Shows a skeleton while statistics load.
locale
string
Locale for number formatting.
labels
CwStatCardLabels
Overrides for every visible string, including `showDetails` and `hideDetails`.
Copy-paste examples
Each snippet is a complete, working example you can paste into a Svelte 5 component.