Components
Donut chart
Parts of a whole as a ring, with the total in the centre.
Free
pnpm dlx shadcn@latest add @caliper/donut-chartWhen to use
Use it for
- Three to six parts that add up to something meaningful.
- A quick sense of composition.
Skip it when
- Many small parts; use a treemap or bar chart.
Installation
terminal
pnpm dlx shadcn@latest add @caliper/donut-chart
Adds its 5 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 { useState, type ReactNode } from "react" import { DonutChart } from "@/components/ui/donut-chart" import { SegmentedControl } from "@/components/ui/segmented-control" 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 periods = [ { value: "week", label: "Week" }, { value: "month", label: "Month" }, { value: "year", label: "Year" }, ]; type Period = "week" | "month" | "year"; function ChartHead({ title, period, onPeriod }: { title?: string; period: Period; onPeriod: (period: Period) => void }) { const control = <SegmentedControl label="Period" value={period} onValueChange={(value) => onPeriod(value as Period)} options={periods} />; // Beside the chart's own title where there is room; above it on phones, so the two never overlap. if (!title) return <div className="mb-3 flex justify-end sm:absolute sm:-top-2 sm:right-0 sm:z-10 sm:mb-0">{control}</div>; return ( <div className="mb-4 flex items-center justify-between gap-3"> <p className="text-sm font-medium">{title}</p> {control} </div> ); } const seats: Record<Period, number[]> = { week: [1262, 851, 498, 362, 94], month: [1284, 860, 512, 340, 96], year: [1310, 902, 548, 214, 104] }; function PlanMix() { const [period, setPeriod] = useState<Period>("month"); const [team, starter, business, trial, enterprise] = seats[period]; return ( <div className="relative w-full max-w-sm"> <ChartHead period={period} onPeriod={setPeriod} /> <DonutChart label="Seats by plan" unit="seats" data={[ { id: "team", label: "Team", value: team! }, { id: "starter", label: "Starter", value: starter! }, { id: "business", label: "Business", value: business! }, { id: "trial", label: "On trial", value: trial! }, { id: "enterprise", label: "Enterprise", value: enterprise! }, ]} /> </div> ); } export function PlanMixCard() { return ( <Panel title="Seat mix" context="Paid and trial seats across 380 workspaces"> <PlanMix /> </Panel> ); }
API reference
DonutChart
component
PropTypeDefault
label *string—
data *readonly ChartPart[]—
unitstring""
classNamestring—
loadingboolean—
errorstring—
Accessibility
It exposes group and status semantics, with aria-label, aria-busy, aria-hidden and aria-pressed kept in step with state. Changes that matter are announced through a live region.
KeyBehaviour
EscapeCloses or cancels, then returns focus to where it came from.
Motion
Transitions use the shared duration and easing tokens. Under prefers-reduced-motion those tokens collapse to instant and travel distances go to zero, so state changes still happen without movement.