Components
Sparkline
A tiny trend line with no axes, for use inside text and tables.
Free
pnpm dlx shadcn@latest add @caliper/sparklineWhen to use
Use it for
- Showing direction of travel beside a value.
- Table rows with a trend column.
Skip it when
- Readers need exact values; use a chart with axes.
Installation
terminal
pnpm dlx shadcn@latest add @caliper/sparkline
Adds its 2 files to components/ui/, each with its own stylesheet, and installs their packages. No account needed. The first part also adds Caliper UI’s tokens; import them once as in Installation.
Usage
This is the code behind the preview above.
example.tsx
import { type ReactNode } from "react" import { Sparkline } from "@/components/ui/sparkline" import { cn } from "@/components/ui/lib/cn" function Panel({ title, context, action, className, children }: { title: string; context: string; action?: ReactNode; className?: string; children: ReactNode }) { return ( <section className={cn("grid w-full max-w-md min-w-0 gap-5 rounded-overlay border border-border bg-background p-6 shadow-resting", className)}> <div className="flex flex-wrap items-start justify-between gap-3"> <div className="grid min-w-0 gap-1"> <p className="font-medium">{title}</p> <p className="text-sm text-muted-foreground">{context}</p> </div> {action} </div> {children} </section> ); } const channels = [ { name: "Organic search", values: [4, 6, 5, 9, 8, 12, 14], total: 58 }, { name: "Referrals", values: [3, 3, 4, 3, 5, 4, 6], total: 28 }, { name: "Paid social", values: [9, 7, 6, 6, 4, 4, 3], total: 39 }, ]; export function TrendLine() { return ( <Panel title="Signups this week" context="125 new workspaces · 14–20 October"> <ul className="grid divide-y divide-border"> {channels.map((channel) => ( <li key={channel.name} className="flex items-center gap-4 py-3 text-sm first:pt-0 last:pb-0"> <span className="min-w-0 flex-1">{channel.name}</span> <span className="w-24"><Sparkline label={`${channel.name} signups, last 7 days`} values={channel.values} /></span> <span className="w-8 text-end font-medium tabular-nums">{channel.total}</span> </li> ))} </ul> </Panel> ); }
API reference
Sparkline
component
Also accepts the native props of its root element and a ref.
PropTypeDefault
values *readonly number[]—
label *string—
Accessibility
It exposes img semantics, with aria-label kept in step with state.
No custom key handling; Tab and the native activation keys do the work.
Motion
It declares no animation in its component source. Any transition comes from its stylesheet, which uses the duration tokens that collapse to instant under prefers-reduced-motion.