Engineering
React Contribution Heatmap and Time-Range Charts for shadcn/ui
Build a React contribution heatmap and interactive chart brush for shadcn/ui with an optical hover loupe, zero-shift readout, keyboard grid nav, and no d3.
Most React contribution heatmap libraries either pull in a heavy charting
runtime or bolt floating tooltips onto hundreds of <div> squares that flicker
across gaps, shift layout when hovered, and trap keyboard users in 365
individual Tab stops.
TentUI's Contribution Heat is a free and
source-available React calendar heatmap for shadcn/ui with zero charting
dependencies beyond motion. It pairs a deterministic UTC calendar grid with a
spring-driven optical hover loupe, a zero-layout-shift day readout bar,
click-to-pin inspection, interactive intensity filtering, and single-Tab-stop
keyboard navigation. When you also need to inspect totals or deltas across a
continuous time window, it pairs cleanly with Chart Brush.
Sweep across the weeks to watch the optical loupe glide over neighboring cells,
click or drag to pin a day, hover or click a Less–More legend swatch to
isolate one intensity level, or switch tones (emerald, graphite, amber,
cobalt) and sizes (sm, md, lg).
Quick start
Configure the @tentui registry in components.json (see the
installation guide), then install Contribution Heat:
pnpm dlx shadcn@latest add @tentui/contribution-heat
The CLI copies contribution-heat.tsx into your project and installs only
motion. Pass an array of ISO YYYY-MM-DD records—any missing dates in the
range are backfilled automatically as zero-count cells:
"use client";
import { ContributionHeat } from "@/components/contribution-heat";
export function DeployHeatmap({
activity,
}: {
activity: Array<{ date: string; count: number; label?: string }>;
}) {
return (
<ContributionHeat
data={activity}
weeks={26}
unit={["deploy", "deploys"]}
summaryLabel="Last 26 weeks"
tone="emerald"
/>
);
}Deterministic UTC grids and automatic quantile thresholds
Calendar heatmaps frequently suffer from hydration mismatches when a server
renders dates in UTC and a client browser parses new Date("2026-11-12") or
offsets week boundaries in local time. ContributionHeat parses every record
with a strict YYYY-MM-DD regex into Date.UTC(...), aligns the start
backward to weekStartsOn (0 for Sunday or 1 for Monday) and the end
forward to finish the last week column, and marks padding days as outside: true.
If your records omit an explicit level (0–4), computeThresholds derives
four cutoffs directly from the positive counts in your dataset using the 40th,
72nd, and 90th percentiles (falling back to [1, 2, 3, 4] when the maximum
count is 4 or lower):
// Auto-derived from positive counts when `thresholds` is omitted:
const t1 = 1;
const t2 = Math.max(t1 + 1, Math.round(q(0.4)));
const t3 = Math.max(t2 + 1, Math.round(q(0.72)));
const t4 = Math.max(t3 + 1, Math.round(q(0.9)));That prevents a single 40-commit release day from flattening every normal
workday into level 1. When you want fixed semantics across users or months,
pass an explicit four-number thresholds tuple such as [1, 4, 8, 15] or set
level per day.
Zero-layout-shift readout bar instead of jittery tooltips
Floating tooltips over a 12 px cell grid create two UX problems: they cover the cells directly above the pointer, and they blink in and out every time the pointer crosses a 3 px grid gap.
Contribution Heat splits inspection into two calm layers:
- A fixed-height readout bar above the grid. At rest, it displays the
total count,
summaryLabel(or date span), and longest streak. As soon as you hover, focus, drag-scrub, or pin a cell, the same slot switches immediately to that day's exact count, formatted date, and optional milestonelabel—withtabular-numsand zero vertical layout shift. - A spring-driven optical hover loupe. Rather than showing a text box next
to the cursor, a circular glass lens glides on
motion/reactMotionValues (useSpringwithstiffness: 440, damping: 36, mass: 0.62anduseMotionTemplatetranslate3d(...)), magnifying the surrounding 5×5 cell neighborhood and printing the focal day's numeric count right inside the magnified square.
Because coordinates map through frameOffsetX/frameOffsetY in unzoomed grid
pixels, the loupe stays aligned even inside horizontally scrolled viewports on
mobile or pages with CSS zoom, and never clips at the edges of the card.
Click-to-pin, drag scrubbing, and intensity filtering
Hover-only heatmaps fail on touch screens and make it hard to compare a specific release day against surrounding data. Contribution Heat supports three direct inspection interactions:
- Click or tap to pin. Clicking any day pins it in the readout bar (and
calls
onValueChangewith{ date, count, level, label }). Clicking it again—or pressingEscape—unpins it. UsevalueandonValueChangeto sync the pinned day with React state, URL search params, or an activity log below the calendar. - Pointer drag scrubbing. Pressing and dragging across the grid scrubs continuously through days and pins whichever day you release on.
- Interactive intensity legend. Hovering or clicking any of the five
Less–Morelegend swatches isolates cells at that intensity level (0–4) and dims the rest, while exposingaria-pressedand the day count for each level.
You can also replace the default header readout using renderReadout, which
receives { activeDay, selectedDay, isPinned, filteredLevel, summary }.
Keyboard grid navigation and accessibility
A 26-week heatmap has 182 cells; a full year has 365. Giving every cell
tabIndex={0} makes keyboard navigation unusable. Contribution Heat uses a
role="grid" matrix of role="gridcell" buttons with a single roving
tabIndex:
| Key | Behavior |
|---|---|
Tab | Enters or leaves the heatmap at the pinned or latest in-range day (one Tab stop) |
ArrowLeft / ArrowRight | Moves to the same weekday in the previous or next week |
ArrowUp / ArrowDown | Moves to the previous or next calendar day |
PageUp / PageDown | Jumps backward or forward by four weeks |
Home / End | Jumps to the first or last in-range day |
Enter / Space | Pins or unpins the focused day |
Escape | Clears the pinned day or active legend filter |
Every cell carries a full aria-label combining formatted date, activity count,
and milestone label, plus aria-selected when pinned. The readout bar uses
aria-live="polite". Under prefers-reduced-motion: reduce, the loupe jumps
directly to the pointer without spring lag and uses an opacity cross-fade
instead of scale motion; under prefers-reduced-transparency: reduce, the
loupe switches to an opaque surface.
Pairing a heatmap with a brushed time-series chart
A calendar heatmap answers consistency and cadence ("which days had activity, and how long was the streak?"). It is less suited for answering change over a range ("how much did signups grow during the two weeks after launch, or how much did p95 latency drop after the cache fix?").
That is the job of Chart Brush—a standalone SVG area
or line chart with two draggable handles, monotone cubic interpolation (so peaks
never overshoot between samples), rolling header deltas via @number-flow/react,
and zero dependency on Recharts, visx, or d3.
Install Chart Brush from the same @tentui registry:
pnpm dlx shadcn@latest add @tentui/chart-brush
In a dashboard, you can connect both components through shared date state:
ChartBrush exposes onValueChange (live while dragging) and onValueCommit
(fires once when a drag or tap lands, ideal for refetching tables or filtering
activity), while ContributionHeat accepts startDate, endDate, and
value/onValueChange for day-level drill-down:
"use client";
import { useState } from "react";
import { ChartBrush, type ChartBrushRange } from "@/components/chart-brush";
import { ContributionHeat } from "@/components/contribution-heat";
export function ActivityDashboard({
dailySeries,
}: {
dailySeries: Array<{ date: string; count: number; value: number }>;
}) {
const [range, setRange] = useState<ChartBrushRange>({
start: Math.max(0, dailySeries.length - 30),
end: dailySeries.length - 1,
});
const [pinnedDate, setPinnedDate] = useState<string | null>(null);
const startIso = dailySeries[range.start]?.date;
const endIso = dailySeries[range.end]?.date;
return (
<div className="grid gap-6">
<ChartBrush
label="Daily throughput"
data={dailySeries.map(({ date, value }) => ({ date, value }))}
value={range}
onValueChange={setRange}
minSpan={6}
/>
<ContributionHeat
data={dailySeries.map(({ date, count }) => ({ date, count }))}
startDate={startIso}
endDate={endIso}
value={pinnedDate}
onValueChange={(day) => setPinnedDate(day?.date ?? null)}
unit={["event", "events"]}
/>
</div>
);
}When you only need a numeric interval filter (such as price or latency bounds) without a plotted curve, Range Span gives you the same two-handle drag, span panning, and auto-merging min/max labels in a compact slider. For a broader tour of TentUI's interactive components by job, see Best Animated shadcn/ui Components in 2026.
FAQ
How do I install a React contribution heatmap in shadcn/ui?
Add "@tentui": "https://tentui.com/r/{name}.json" to components.json and run npx shadcn@latest add @tentui/contribution-heat. The CLI copies contribution-heat.tsx into your project and installs motion with no charting library required.
Do Contribution Heat or Chart Brush require Recharts, visx, or d3?
No. Contribution Heat renders a semantic HTML grid with Tailwind CSS and Motion, and Chart Brush draws its own monotone cubic SVG curve, grid lines, and draggable handles directly. Neither pulls in Recharts, visx, or d3.
How does Contribution Heat assign intensity levels to raw counts?
If a day record does not specify an explicit level (0–4), the component calculates four thresholds from the 40th, 72nd, and 90th percentiles of your dataset's positive counts. You can override that distribution at any time with the thresholds prop or explicit per-day level values.
Is the contribution heatmap accessible with a keyboard and screen reader?
Yes. The grid uses a single roving tabIndex so keyboard users tab into it once, then navigate with arrow keys, PageUp/PageDown (four-week jumps), Home/End, Enter/Space to pin a day, and Escape to clear selection or legend filters. Each cell has a descriptive aria-label and the readout updates inside a polite aria-live region.
Can I pair Contribution Heat with a time-range chart brush?
Yes. Use ChartBrush's controlled value, onValueChange, or onValueCommit callbacks to read the selected { start, end } indices, map them to ISO dates, and pass startDate and endDate into ContributionHeat (or keep ContributionHeat showing the full span while pinning matching days via value).
Are Contribution Heat and Chart Brush free to use?
Yes. Both components are free and source-available under the TentUI License: the shadcn CLI copies their full TypeScript source into your project for unlimited personal and client applications, with redistribution or resale of the components themselves prohibited.
Components in this guide
All componentsChart Brush
An area or line chart with two draggable handles for picking a time range. The selected stretch is inked in while the rest fades back, the change rolls in the header, and every point the handles cross ticks.
npx shadcn@latest add @tentui/chart-brushContribution Heat
A calendar heatmap with a spring-driven optical hover loupe, zero-shift day-by-day readout, click-to-pin inspection, and interactive intensity filtering.
npx shadcn@latest add @tentui/contribution-heatRange Span
A two-handle range control with a stretchy selected fill, draggable span panning, rubber-band limits, and live min and max labels that merge before colliding.
npx shadcn@latest add @tentui/range-span
Related guides
All posts- Best Animated shadcn/ui Components in 2026
A guide to TentUI's animated shadcn/ui components by job, from async buttons and pickers to charts, overlays, text effects, and AI thinking UI.
- How to Add Animations to shadcn Components
Build accessible shadcn animations with source-owned code, shared-layout transitions, async feedback, and reduced-motion support.
- AI Prompt Input UX in React: Chips, Mentions, and Model Pickers
Build a React AI prompt input with @mentions, /commands, and model chips that submits structured values, using TentUI's Prompt Chip Input for shadcn/ui.