Skip to content
← Components

Heatmap

Heatmap with readable values and an accessible data representation.

Open ↗

Make it yours.

Install the editable source and its dependencies into your React + Tailwind project.

Scroll horizontally for long lines
pnpm dlx shadcn@4.0.8 add http://localhost:3000/r/heatmap.json

Use it

Scroll horizontally for long lines
"use client";
import { Heatmap } from "@/components/jez-ui/ui/heatmap";

export default function Example() {
  return (
    <>
      <div className="w-full max-w-2xl">
        <div className="mb-8 flex flex-wrap items-end justify-between gap-4">
          <div>
            <h3 className="text-3xl tracking-tight">Keep showing up.</h3>
            <p className="mt-2 text-sm text-muted-foreground">
              A year of small, consistent steps
            </p>
          </div>
          <span className="rounded-full border border-border px-3 py-1 text-xs text-muted-foreground">
            Demo data
          </span>
        </div>
        <Heatmap />
      </div>
    </>
  );
}

Props & types

Scroll horizontally for long lines
Omit<
  React.ComponentProps<"figure">,
  keyof {
    values?: number[];
    label?: string;
    className?: string;
  }
> & {
  values?: number[];
  label?: string;
  className?: string;
}

Source

View 2 source files

registry/ui/heatmap.tsx

Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
export function Heatmap({
  children,
  values = Array.from({ length: 84 }, (_, i) => (i * 7 + (i % 3)) % 5),
  label = "Activity over 12 weeks",
  className,
  ...rootProps
}: Omit<
  React.ComponentProps<"figure">,
  keyof {
    values?: number[];
    label?: string;
    className?: string;
  }
> & {
  values?: number[];
  label?: string;
  className?: string;
}) {
  return (
    <figure {...rootProps} className={cn("m-0", className)}>
      {children !== undefined ? (
        children
      ) : (
        <>
          <figcaption className="mb-5 text-sm font-medium">{label}</figcaption>
          <div className="grid grid-flow-col grid-rows-7 gap-1.5 overflow-x-auto">
            {values.map((v, i) => (
              <div
                key={i}
                title={`Day ${i + 1}: ${v} contributions`}
                role="img"
                aria-label={`Day ${i + 1}: ${v} contributions`}
                className="size-4 rounded-sm"
                style={{
                  background: `color-mix(in srgb,var(--primary) ${Math.max(0, Math.min(v, 4)) * 23 + 8}%,var(--background))`,
                }}
              />
            ))}
          </div>
          <p className="mt-4 text-xs text-muted-foreground">
            Lighter: less activity · Darker: more activity
          </p>
        </>
      )}
    </figure>
  );
}

registry/ui/utils.ts

Scroll horizontally for long lines
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...values: ClassValue[]) {
  return twMerge(clsx(values));
}

Dependencies

clsx@2.1.1 · tailwind-merge@3.5.0

Accessibility & behaviour

Provide meaningful labels and preserve keyboard focus styles. Check contrast when customising theme colours.

Read the accessibility and performance guide →