SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

Sparkline

A row-sized trend line with no axes.

api.acme.dev142 msapi.acme.dev response time, stableStable
checkout.acme.dev612 mscheckout.acme.dev response time, degradingDegrading
billing.acme.dev—billing.acme.dev response time, downDown
status.acme.dev88 msstatus.acme.dev response time, recoveredRecovered
View code
tsx
{MONITORS.map((monitor) => (
	<div key={monitor.name} mix={[grid(), raw({ gridTemplateColumns: "minmax(0, 1fr) 5rem minmax(0, 12rem)", alignItems: "center", gap: "1rem" })]}>
		<span>{monitor.name}</span>
		<span mix={[tabularNums(), textAlign("end")]}>{monitor.latest}</span>
		<Sparkline
			values={monitor.values}
			label={`${monitor.name} response time, ${monitor.state.toLowerCase()}`}
			tone={monitor.tone}
			state={monitor.state}
		/>
	</div>
))}

Demo apps

Whole pages built only from @sdxc/ui, each for an invented product with its own palette and type. They open in a new tab.

Every demo, landings and docs sites alike, is listed in the demo gallery.

Installation

An ordinary dependency: install it, import the theme once, and import the component where it is used.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Usage

typescript
import { Sparkline } from "@sdxc/ui/app";

Renders the trend: a role="img" SVG named by label that fills the row's inline size at --ui-sparkline-block-size, with a stroke that stays --ui-sparkline-line-width wide at any size. The latest-point dot is a round box over the plot, so it stays round when the plot stretches.

Examples

tsx
<Sparkline values={checks} label={t("monitor.checks")} area dot={false} domain={[0, 100]} />

Props

Read from the component's own types, so every prop, every default and every allowed value is listed.

PropTypeRequiredDescription
valuesreadonly (number | null)[]YesSamples in time order; a null leaves a gap in the line instead of drawing a zero.
labelstringYesAccessible name of the graphic, summarising the trend ("p95 latency, rising").
descriptionstringNoLonger accessible description, such as the range and the latest value.
tone"brand" | "neutral" | "success" | "warning" | "danger"No
areabooleanNoFills the region under the line.
dotbooleanNoMarks the latest sample with a dot.
domainreadonly [number, number]No[min, max] the plot spans; the samples' own extremes when omitted, so rows can share a scale.
stateRemixNodeNoOne word beside the line that reads the trend ("Stable", "Degrading").
partsPartsPropsNo

Also accepts everything in Omit<TagProps<"span">, "children">.

Types

NameValuesWhat it decides
Tone"brand" | "neutral" | "success" | "warning" | "danger"Semantic role the line, area and dot are drawn in.
@sdxc/ui

Can’t find it? Contact us