Skip to content
Haze UI

Sparkline

A compact trend line with the latest reading and a native disclosure for the full data.

pnpm dlx shadcn@latest add @haze/sparkline
Open preview in a new tab
Liveno JavaScript

When to use

  • A small stat card needs recent trend context
  • Readers need exact numeric samples as well as the line

When not to use

  • The values correspond to unrelated categories. Use bar-list.
  • Multiple series or axes need detailed comparison.

Installation

Add the Haze registry to components.json once, then install Sparkline with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/sparkline
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
labelstring"Request duration"Metric caption.
samples{ label: string; value: number }[]–Finite samples in time order, with a readable label for each.
unitstring"ms"Abbreviated unit, or an empty string.
detailsLabelstring"View samples"Label for the sample disclosure.
emptyLabelstring"No samples yet."Text displayed when there are no samples.
classstring–Additional classes on the figure.

Keyboard interactions

Enter or Space
Toggle the list of samples when its summary is focused.

Accessibility

  • The SVG is decorative. The latest value and the full list of samples are available as text.
  • Samples are spaced evenly. Aggregate at a regular interval when the horizontal spacing carries meaning.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Sparkline" with `npx shadcn@latest add @haze/sparkline`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Sparkline from "@/components/haze/ui/sparkline.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/sparkline.md

  • Customize with real content

    Adapt the Haze sparkline ui for our product. Replace the demo values of these props with our real content: label, samples, unit, detailsLabel, emptyLabel, class. Keep the layout, the heading level rules and these accessibility details: The SVG is decorative. The latest value and the full list of samples are available as text. Samples are spaced evenly. Aggregate at a regular interval when the horizontal spacing carries meaning. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using sparkline, check it fits: use it when a small stat card needs recent trend context; readers need exact numeric samples as well as the line. Avoid it when the values correspond to unrelated categories. use bar-list.; multiple series or axes need detailed comparison.. Alternatives: @haze/stat, @haze/bar-list, @haze/uptime-tracker.

Dependencies

  • npm: @lucide/astro
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog