Stat Card
FreeKPI metric cards with sparklines, trend chips and four layout variants.
Complexity tier: Primitive Presents a value: held to semantic markup and contrast, with its right-to-left and print gaps recorded and the right-to-left debt allowed only to shrink.
import { SvStatCardComponent } from '@styloviz/stat-card';Demo & usage
Basic usage
Usage example — open the gallery for the full interactive demo.
An interactive demo for this component lives in the gallery.
Open live demoMore examples
With sparkline & link
<sv-stat-card title="Active users" [value]="12840" [trendPercent]="-3.2" [sparkline]="series" linkLabel="View report" (linkClick)="open()" />
Clickable card, keyboard accessible (Pro)
<sv-stat-card-pro title="Open tickets" [value]="42" variant="warning" [clickable]="true" (cardClick)="drillDown()" />
When to use
- Surfacing a single headline metric with its trend at the top of a dashboard.
- You want an inline sparkline and a semantic up/down trend chip.
- For many metrics at once, arrange several cards in a Widget Grid.
Async states
- loading
- error
- retry
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| title | string | '' | Card title / metric label. |
| value | string | number | '' | Primary metric value — string or number, displayed as-is or formatted. |
| prefix | string | '' | Optional prefix rendered before the value (e.g. "$", "€"). |
| suffix | string | '' | Optional suffix rendered after the value (e.g. "K", "%", "ms"). |
| description | string | '' | Short helper text beneath the title (e.g. "Last 30 days"). |
| trend | StatCardTrend | 'neutral' | Direction of change. |
| trendValue | number | null | null | Absolute delta value shown alongside the trend icon. |
| trendPercent | number | null | null | Percentage change shown in the trend chip. |
| trendLabel | string | '' | Comparison context label (e.g. "vs last month"). |
| updatedAt | string | '' | When this figure was last refreshed, as `YYYY-MM-DD` or an ISO timestamp. A CACHED KPI LOOKS IDENTICAL TO A LIVE ONE. A number is a number, and nothing about a stale one announces itself — so the reader assumes the dashboard is current, which is exactly the assumption a broken pipeline exploits. This is in the FREE tier deliberately. Telling a reader their figure may be out of date is an honesty feature, not a premium one, and a free card that hides staleness is the defect rather than a smaller version of it. |
| staleAfterMinutes | number | 60 | How many minutes before the figure is called out as possibly stale. |
| source | string | '' | Where the figure came from — a warehouse, a job, a service. |
| variant | StatCardVariant | 'default' | Deprecated, and has no effect: the free card has one colour treatment. |
| layout | StatCardLayout | 'default' | Card layout mode. |
| icon | string | '' | Name of an icon in `@styloviz/icons`, e.g. `'trending-up'`. This was `iconPath` — a raw `<path d="…">` — with a companion `iconViewBox` because a pasted path might be 20-box or 24-box. Both are gone: a library name is always 24-box, and the viewBox binding is what hid these glyphs from `check:ui` in the first place (a bound `viewBox` does not match a literal `viewBox="…"` test). |
| sparkline | SparkPoint[] | [] | Array of data points for the inline sparkline. Values should be on a consistent numeric scale; the component normalises them internally. Empty array hides the sparkline. |
| loading | boolean | false | Show skeleton loading shimmer instead of content. |
| error | SvDataError | string | null | null | The figure could not be loaded. Rendered in place of the metric, because a card that keeps showing a stale number after a failed refresh is worse than one that admits it: the reader has no way to tell the two apart. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`. |
| linkLabel | string | '' | Label for the bottom "view more" link. Empty string hides the link. |
| customClass | string | '' | Additional CSS classes merged on the root card element. |
Outputs
| Event | Payload type | Description |
|---|---|---|
| cardClick | void | Deprecated, and never emitted: the free card is not interactive. |
| linkClick | void | Emitted when the "view more" link is clicked. |
| retry | void | The host should re-run the failed load. |
<sv-stat-card-pro>
Also in this family — SvStatCardProComponent from @styloviz-pro/stat-card.
Async states
- loading
- error
- retry
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| title | string | '' | Card title / metric label. |
| value | string | number | '' | Primary metric value — string or number, displayed as-is or formatted. |
| prefix | string | '' | Optional prefix rendered before the value (e.g. "$", "€"). |
| suffix | string | '' | Optional suffix rendered after the value (e.g. "K", "%", "ms"). |
| description | string | '' | Short helper text beneath the title (e.g. "Last 30 days"). |
| trend | StatCardTrend | 'neutral' | Direction of change. |
| trendValue | number | null | null | Absolute delta value shown alongside the trend icon. |
| trendPercent | number | null | null | Percentage change shown in the trend chip. |
| trendLabel | string | '' | What the trend is measured AGAINST — "vs last month", "vs Q3". A KPI WITHOUT ITS COMPARISON PERIOD IS A DECORATION. "+12%" against last week, last month and last year are three different claims, and the reader has no way to pick between them. Supplying this is not optional in any real dashboard; it is left as an input rather than made required only because doing otherwise would break every existing call site. Where it is missing, the trend's accessible name says so rather than reading a bare percentage as though it meant something. |
| updatedAt | string | '' | When this figure was last refreshed, as `YYYY-MM-DD` or an ISO timestamp. A CACHED KPI LOOKS IDENTICAL TO A LIVE ONE. That is the whole defect: a number is a number, and nothing about a stale one announces itself. The reader is left to assume the dashboard is current, which is exactly the assumption a broken pipeline exploits. |
| staleAfterMinutes | number | 60 | How many minutes before the figure is called out as possibly stale. |
| source | string | '' | Where the figure came from — a warehouse, a job, a service. |
| variant | StatCardVariant | 'default' | Color variant — drives icon background, accent line and trend colors. |
| layout | StatCardLayout | 'default' | Card layout mode. |
| icon | string | '' | Name of an icon in `@styloviz/icons`, e.g. `'trending-up'`. This was `iconPath` — a raw `<path d="…">` — with a companion `iconViewBox` because a pasted path might be 20-box or 24-box. Both are gone: a library name is always 24-box, and the viewBox binding is what hid these glyphs from `check:ui` in the first place (a bound `viewBox` does not match a literal `viewBox="…"` test). |
| sparkline | SparkPoint[] | [] | Array of data points for the inline sparkline. Values should be on a consistent numeric scale; the component normalises them internally. Empty array hides the sparkline. |
| loading | boolean | false | Show skeleton loading shimmer instead of content. |
| error | SvDataError | string | null | null | The figure could not be loaded. Rendered in place of the metric, because a card that keeps showing a stale number after a failed refresh is worse than one that admits it: the reader has no way to tell the two apart. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`. |
| linkLabel | string | '' | Label for the bottom "view more" link. Empty string hides the link. |
| clickable | boolean | false | Make the whole card interactive (clickable + keyboard focusable). When `true` the root becomes a `role="button"` that emits `cardClick` on click, Enter or Space. |
| customClass | string | '' | Additional CSS classes merged on the root card element. |
Outputs
| Event | Payload type | Description |
|---|---|---|
| cardClick | void | Emitted when an interactive card is activated by click, Enter or Space. |
| linkClick | void | Emitted when the "view more" link is clicked. |
| retry | void | The host should re-run the failed load. |
Wire it to your API
This component is headless about transport: it renders what you give it and reports what the user asks for. Nothing below requires @styloviz/data — drive it from whatever you already use.
Template
Bound to the names this component actually exposes.
<sv-stat-card [sparkline]="data.items()" [loading]="data.loading()" [error]="data.error()" (retry)="data.reload()" />
Host class
Drive the three async inputs from your own fetch.
// This component reports its state but does not emit a query, so drive // it from your own fetch and bind the three async inputs. readonly items = signal<Row[]>([]); readonly loading = signal(false); readonly error = signal<SvDataError | null>(null); async load(): Promise<void> { this.loading.set(true); this.error.set(null); try { this.items.set(await this.api.fetchRows()); } catch (e) { this.error.set(toSvDataError(e)); } finally { this.loading.set(false); } }
- This component does not emit a query, so it renders what you give it. Fetch on your own trigger and bind `sparkline`, `loading` and `error`.
- Normalize failures with `toSvDataError()` from `@styloviz/core`. It derives `retryable` from the status, so a 404 does not get a "Try again" button that can only fail again.
Full walkthrough: Connecting to a backend.
Customization & theming
- Four layouts plus optional inline sparkline.
- Trend chip colors follow the semantic palette.
- Format values with your own pipe before binding.
- Set `clickable` on `sv-stat-card-pro` to make the whole card an interactive button that emits `cardClick`.
Best practices
- Do: Pre-format large numbers (e.g. 12.8k, $48.2K) before binding to `value`.
- Do: Use `trendPercent` sign to drive color so up/down reads instantly.
- Don't: Don't pack more than one metric into a single card — split them.
Accessibility
- Values and trends are real text, not images.
- Sufficient contrast across variants and dark mode.
- A `clickable` card (Pro) exposes `role="button"`, is focusable, and activates on Enter/Space.
- Decorative icons and sparklines are hidden from assistive tech; loading state sets `aria-busy`.
Feedback on Stat Card
Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.