Skip to content
Browse documentation

A period of activity as glass pillars on dark lacquer: point at one and it turns white, switch the range and the new pillars rise in a wave.

Used forProductivityFitnessCreative toolsWallets and usage

Install with the shadcn CLI

$ npx shadcn@latest add https://hairlineui.com/r/pillar-chart.json

Registered the namespace? Then it’s shadcn add @hairline/pillar-chart. Set it up

Templates

Need the whole page?

61 Next.js landing pages, each designed from scratch. Try any of them live; one is $39, all of them $159, and 6 are free.

All 61 templates

Where it’s used

  • Productivity

    Focus or screen time across a week, a month and a year.

  • Fitness

    Distance, workouts or active minutes, with the change against last period.

  • Creative tools

    Hours in the studio, words written, tracks finished.

  • Wallets and usage

    Spend or usage per day, as a stat card on a dashboard.

What it handles for you

A plain bar card snaps when the range changes and gives no feel for which day you’re reading.

Instead of wiring upweekly bar chartstat card chartactivity chartscreen time chartrange toggle chart
  1. Your data

    Ranges of bars in your own units; heights scale to each range’s tallest.

  2. Ranges

    A sliding switch; the pillars sink and rise in a wave the way you moved.

  3. Reading a pillar

    Point, tap or arrow to it: it turns white and the line says what it is.

  4. Rolling figures

    The total and the change roll; the change pill says up or down.

  5. Any colour

    Named lacquer tones or any CSS colour, always a dark finish.

  6. Screen readers

    A hidden table of every pillar, and the pillars as a group of radios.

Overview

Weekly focus time, distance run, hours played: a stat card with a few bars is everywhere, and most of them are flat rounded rectangles that snap when you change the range. Pillar chart is an object with its own finish, a dark lacquered card in your colour with frosted glass capsules for pillars and a fine curve running over their tops. Point at a pillar and it turns solid white while a small lime marker glides above it and the line under the total says what it is. Switch between week, month and year and the pill slides to the choice, the pillars on show sink away, the new ones rise from the floor in a wave from the side you moved toward, the curve draws itself again, and the total and its change roll to their new figures. It looks the same on a light page or a dark one.

States

point
The pillar under a mouse, a tap or the arrow keys crossfades to white over 200ms; the marker glides above it (380ms, slight overshoot) and the line under the total morphs.
range
The switch’s pill slides (420ms). The pillars on show sink 10px and fade over 260ms; the new ones rise from the floor over 720ms, 42ms apart, from the side you moved toward; the curve draws in over 900ms; the total and change roll.
resize
The marker and the curve follow the pillars when the card changes width.
reduced motion
No rise, sink, draw or roll: everything changes in place.

Usage

usage.tsx
import { PillarChart } from "@/components/pillar-chart";<PillarChart  title="Focus time"  unit=" hrs"  ranges={[{ id: "week", label: "W", total: 48.2, change: 12.4, bars: [{ label: "Mon", value: 5.4 }, { label: "Tue", value: 6.8 }] }]}/>

Depends on lucide-react, installed for you by the CLI along with the keyframes it needs.

Works with

Focus time from your API

One request per range, or all three at once; the chart only needs the totals and the bars.

example.tsx
"use client";import { useEffect, useState } from "react";import { PillarChart, type PillarRange } from "@/components/pillar-chart";export function FocusCard() {  const [ranges, setRanges] = useState<PillarRange[] | null>(null);  useEffect(() => {    fetch("/api/focus/ranges").then((r) => r.json()).then(setRanges);  }, []);  if (!ranges) return null;  return <PillarChart title="Focus time" unit=" hrs" ranges={ranges} tone="cobalt" />;}

Props

ranges
{ id, label, name?, total, change?, bars: { label, value, detail? }[], focus? }[]
Each range: the switch label (W), its name for screen readers (Week), the total, the change in percent and the bars.
value / defaultValue= the first range
string
The range on show, by id; controlled or not.
onValueChange
(id: string) => void
Called when the range changes.
title / icon= "Activity"
string / ReactNode
Top left.
unit
string
After every figure: " hrs", " km".
format= { maximumFractionDigits: 1 }
Intl.NumberFormatOptions
How totals and bars read.
locales
string | string[]
For number formatting.
tone= "cobalt"
"cobalt" | "ember" | "rose" | "emerald" | "midnight" | "violet" | string
The lacquer’s colour.
accent= "#dcfc4e"
string
The marker and the up pill.

Accessibility and motion

  • Always dark: the lacquer is the card’s own finish (colour pooled from two corners over near black, a fine light on the top edge, no drop shadow), so it reads the same on any page and needs no light version.
  • Pillars move with transforms inside rounded clips, never by height, so a range change never relays out the card; the marker and curve are measured from the pillars once, and again on resize.
  • The pillars are a radio group (one tab stop, arrows, Home and End); a hidden table lists every pillar with its value.
  • Reduced motion drops the rise, sink, draw and roll.

Requirements

React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

The CLI also installs Number roll, Text morph.

Source

"use client";import * as React from "react";import { ArrowDownRight, ArrowUpRight } from "lucide-react";import { lacquer, type LacquerTone } from "./lacquer";import { NumberRoll } from "./number-roll";import { TextMorph } from "./text-morph";import { EASE_OUT, EASE_THROW, useInteractionReducedMotion } from "./ui-interaction-motion";/* ───────────────────────────────────────────────────────── * PILLAR CHART: a period of activity as glass pillars * *   pillars  each day (or week, or month) is a frosted glass *            capsule; the one you point at turns solid white and *            a small marker glides above it; the line under the *            total says what it is *   range    the switch slides to the new range; the pillars on *            show sink away and the new ones rise in a wave from *            the side you moved toward, the curve over them draws *            itself again, and the total and the change roll * * An object with its own dark lacquer finish: the same on a light * page or a dark one. * * Reduced motion: no rise, sink or roll; everything changes in place. * ───────────────────────────────────────────────────────── */export interface PillarBar {  label: string;  value: number;  /** The line under the total for this pillar; by default its label and value. */  detail?: string;}export interface PillarRange {  id: string;  /** On the switch: W, M, Y. */  label: string;  /** Read out for the switch, "Week". */  name?: string;  total: number;  /** Percent against the previous period: 12.4 for +12.4%. */  change?: number;  bars: PillarBar[];  /** Which pillar is picked when the range opens; the tallest by default. */  focus?: number;}export interface PillarChartProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "title" | "defaultValue" | "onChange"> {  ranges: PillarRange[];  value?: string;  defaultValue?: string;  onValueChange?: (id: string) => void;  title?: string;  icon?: React.ReactNode;  /** After every figure: " hrs", " km". */  unit?: string;  format?: Intl.NumberFormatOptions;  locales?: string | string[];  /** The lacquer: a named tone or any CSS colour. */  tone?: LacquerTone | (string & {});  /** The marker and the change pill. */  accent?: string;}const AREA = 108;const subscribeNothing = () => () => {};/** False while hydrating: text formatted with the visitor's locale waits for it, so the server's HTML matches. */const useHydrated = () => React.useSyncExternalStore(subscribeNothing, () => true, () => false);const FORMAT: Intl.NumberFormatOptions = { maximumFractionDigits: 1 };type Column = { x: number; top: number };function Pillars({  range,  selected,  onSelect,  enter,  leaving,  reduced,  accent,}: {  range: PillarRange;  selected: number;  onSelect: (i: number) => void;  enter: number;  leaving: boolean;  reduced: boolean;  accent: string;}) {  const row = React.useRef<HTMLDivElement>(null);  const pillars = React.useRef<(HTMLSpanElement | null)[]>([]);  const curve = React.useRef<SVGPathElement>(null);  const marker = React.useRef<HTMLSpanElement>(null);  const [cols, setCols] = React.useState<Column[]>([]);  const [size, setSize] = React.useState({ w: 0, h: 0 });  const max = Math.max(...range.bars.map((b) => b.value), 1);  const heights = range.bars.map((b) => Math.max(0.18, b.value / max) * 0.96);  // Where each pillar's middle and top sit, for the marker and the curve: measured, and again when the card resizes.  React.useLayoutEffect(() => {    const el = row.current;    if (!el) return;    const measure = () => {      const next = Array.from(el.children)        .filter((c): c is HTMLElement => c instanceof HTMLElement && c.dataset.col !== undefined)        .map((c, i) => ({ x: c.offsetLeft + c.offsetWidth / 2, top: c.offsetTop + c.offsetHeight - 22 - AREA * heights[i] }));      setCols((p) => (p.length === next.length && p.every((c, i) => c.x === next[i].x && c.top === next[i].top) ? p : next));      setSize((p) => (p.w === el.offsetWidth && p.h === el.offsetHeight ? p : { w: el.offsetWidth, h: el.offsetHeight }));    };    measure();    const ro = new ResizeObserver(measure);    ro.observe(el);    return () => ro.disconnect();    // eslint-disable-next-line react-hooks/exhaustive-deps  }, [range]);  // The new pillars rise from the floor in a wave from the side you moved toward, and the curve draws itself.  React.useLayoutEffect(() => {    if (reduced || !enter) return;    const n = pillars.current.length;    pillars.current.forEach((el, i) => {      const order = enter > 0 ? i : n - 1 - i;      el?.animate([{ transform: "translateY(100%)" }, { transform: `translateY(${(1 - heights[i]) * 100}%)` }], {        duration: 720,        delay: 60 + order * 42,        easing: EASE_OUT,        fill: "backwards",      });    });    // eslint-disable-next-line react-hooks/exhaustive-deps  }, []);  React.useEffect(() => {    if (reduced || !cols.length) return;    curve.current?.animate([{ strokeDashoffset: 1 }, { strokeDashoffset: 0 }], { duration: 900, delay: 120, easing: EASE_OUT, fill: "backwards" });    // On a new range the marker settles in once its pillar has risen, rather than waiting in the air.    if (enter) marker.current?.animate([{ opacity: 0, translate: "0 6px" }, { opacity: 1, translate: "0 0" }], { duration: 320, delay: 560, easing: EASE_OUT, fill: "backwards" });    // eslint-disable-next-line react-hooks/exhaustive-deps  }, [cols.length > 0]);  const path = React.useMemo(() => {    if (cols.length < 2) return "";    const pts = cols.map((c) => ({ x: c.x, y: c.top - 16 }));    let d = `M ${pts[0].x.toFixed(1)} ${pts[0].y.toFixed(1)}`;    for (let i = 0; i < pts.length - 1; i++) {      const a = pts[i];      const b = pts[i + 1];      const mx = ((a.x + b.x) / 2).toFixed(1);      d += ` C ${mx} ${a.y.toFixed(1)}, ${mx} ${b.y.toFixed(1)}, ${b.x.toFixed(1)} ${b.y.toFixed(1)}`;    }    return d;  }, [cols]);  const mark = cols[selected];  return (    <div      className="absolute inset-0"      style={{        opacity: leaving ? 0 : 1,        transform: leaving ? "translateY(10px)" : "none",        filter: leaving ? "blur(4px)" : "none",        transition: reduced ? "none" : `opacity 260ms ease-out, transform 320ms ${EASE_OUT}, filter 260ms ease-out`,        pointerEvents: leaving ? "none" : undefined,      }}      aria-hidden={leaving || undefined}    >      {size.w > 0 && path && (        <svg aria-hidden className="pointer-events-none absolute inset-0 overflow-visible" width={size.w} height={size.h} viewBox={`0 0 ${size.w} ${size.h}`}>          <path ref={curve} d={path} pathLength={1} strokeDasharray="1 1" fill="none" stroke="rgb(255 255 255 / 0.42)" strokeWidth="1.2" strokeLinecap="round" />        </svg>      )}      {mark && (        <span          ref={marker}          aria-hidden          className="pointer-events-none absolute left-0 top-0 size-1.5 rounded-full"          style={{            background: accent,            transform: `translate(${mark.x - 3}px, ${mark.top - 12}px)`,            transition: reduced ? "none" : `transform 380ms ${EASE_THROW}`,          }}        />      )}      <div ref={row} role="radiogroup" aria-label="Pick a bar" className="relative flex h-full items-end justify-between gap-2.5">        {range.bars.map((bar, i) => {          const on = i === selected;          return (            <button              key={bar.label}              data-col=""              type="button"              role="radio"              aria-checked={on}              tabIndex={on ? 0 : -1}              aria-label={bar.detail ?? bar.label}              onClick={() => onSelect(i)}              onPointerMove={(e) => e.pointerType === "mouse" && !on && onSelect(i)}              onKeyDown={(e) => {                const step = { ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1 }[e.key];                const to = step ? Math.max(0, Math.min(range.bars.length - 1, i + step)) : e.key === "Home" ? 0 : e.key === "End" ? range.bars.length - 1 : -1;                if (to < 0) return;                e.preventDefault();                onSelect(to);                (e.currentTarget.parentElement?.children[to] as HTMLElement | undefined)?.focus();              }}              className="group flex h-full min-w-0 flex-1 cursor-pointer flex-col items-center justify-end gap-2 rounded-xl outline-none focus-visible:ring-2 focus-visible:ring-white/60"            >              <span className="relative block w-full max-w-[26px] overflow-clip rounded-full" style={{ height: AREA }}>                <span                  ref={(el) => {                    pillars.current[i] = el;                  }}                  className="absolute inset-0 rounded-full"                  style={{ transform: `translateY(${(1 - heights[i]) * 100}%)`, transition: reduced ? "none" : `transform 640ms ${EASE_OUT}`, willChange: "transform" }}                >                  <span                    className="absolute inset-0 rounded-full"                    style={{                      background: "linear-gradient(180deg, rgb(255 255 255 / 0.3) 0%, rgb(255 255 255 / 0.12) 62%, rgb(255 255 255 / 0.04) 100%)",                      boxShadow: "inset 0 1px 0 rgb(255 255 255 / 0.22)",                    }}                  />                  <span                    className="absolute inset-0 rounded-full transition-opacity duration-200"                    style={{ opacity: on ? 1 : 0, background: "linear-gradient(180deg, #fff 0%, rgb(255 255 255 / 0.94) 78%, rgb(255 255 255 / 0.82) 100%)" }}                  />                </span>              </span>              <span className={`text-[10.5px] font-medium transition-colors duration-150 ${on ? "text-white" : "text-white/50 group-hover:text-white/80"}`}>{bar.label}</span>            </button>          );        })}      </div>    </div>  );}export function PillarChart({  ranges,  value,  defaultValue,  onValueChange,  title = "Activity",  icon,  unit = "",  format = FORMAT,  locales,  tone = "cobalt",  accent = "#dcfc4e",  className = "",  style,  ...props}: PillarChartProps) {  const reduced = useInteractionReducedMotion();  const [own, setOwn] = React.useState(defaultValue ?? ranges[0]?.id);  const current = ranges.find((r) => r.id === (value ?? own)) ?? ranges[0];  const tallest = (r: PillarRange) => r.focus ?? r.bars.reduce((best, b, i, all) => (b.value > all[best].value ? i : best), 0);  const [picked, setPicked] = React.useState<{ range: string; index: number }>({ range: current.id, index: tallest(current) });  const selected = picked.range === current.id ? Math.min(picked.index, current.bars.length - 1) : tallest(current);  const bar = current.bars[selected];  const hydrated = useHydrated();  const lang = hydrated ? locales : (locales ?? "en-US");  const nf = React.useMemo(() => new Intl.NumberFormat(lang, format), [lang, format]);  // The range on show and the one sinking away; a change is spotted while rendering, so both draw in the same frame.  const [shown, setShown] = React.useState({ id: current.id, enter: 0, key: 0 });  const [leaving, setLeaving] = React.useState<{ id: string; key: number } | null>(null);  if (shown.id !== current.id) {    const from = ranges.findIndex((r) => r.id === shown.id);    const to = ranges.findIndex((r) => r.id === current.id);    setLeaving({ id: shown.id, key: shown.key });    setShown({ id: current.id, enter: to >= from ? 1 : -1, key: shown.key + 1 });  }  React.useEffect(() => {    if (!leaving) return;    const t = window.setTimeout(() => setLeaving(null), 340);    return () => window.clearTimeout(t);  }, [leaving]);  const choose = (id: string) => {    if (id === current.id) return;    if (value === undefined) setOwn(id);    onValueChange?.(id);  };  // The switch's pill slides to the choice; placed without a transition the first time.  const switchRef = React.useRef<HTMLDivElement>(null);  const [pill, setPill] = React.useState<{ x: number; w: number; ready: boolean } | null>(null);  React.useLayoutEffect(() => {    const el = switchRef.current?.querySelector<HTMLElement>(`[data-range="${CSS.escape(current.id)}"]`);    if (!el) return;    setPill((p) => (p && p.x === el.offsetLeft && p.w === el.offsetWidth ? p : { x: el.offsetLeft, w: el.offsetWidth, ready: !!p }));  }, [current.id]);  const up = (current.change ?? 0) >= 0;  const leavingRange = leaving ? ranges.find((r) => r.id === leaving.id) : undefined;  return (    <div      className={`relative flex w-full flex-col overflow-clip rounded-[22px] p-5 select-none ${className}`}      style={{ ...lacquer(tone), ...style }}      {...props}    >      <div className="flex items-center justify-between gap-3">        <div className="flex items-center gap-1.5 text-[12.5px] font-medium text-white/85">          {icon}          <span>{title}</span>        </div>        {ranges.length > 1 && (          <div            ref={switchRef}            role="radiogroup"            aria-label="Range"            className="relative inline-flex items-center gap-0.5 rounded-full p-0.5"            style={{ background: "rgb(0 0 0 / 0.25)", boxShadow: "inset 0 0 0 1px rgb(255 255 255 / 0.14)" }}          >            {pill && (              <span                aria-hidden                className="absolute left-0 top-0.5 h-6 rounded-full bg-white"                style={{ width: pill.w, transform: `translateX(${pill.x}px)`, transition: pill.ready && !reduced ? `transform 420ms ${EASE_THROW}, width 300ms ${EASE_OUT}` : "none" }}              />            )}            {ranges.map((r) => {              const on = r.id === current.id;              return (                <button                  key={r.id}                  data-range={r.id}                  type="button"                  role="radio"                  aria-checked={on}                  aria-label={r.name ?? r.label}                  tabIndex={on ? 0 : -1}                  onClick={() => choose(r.id)}                  onKeyDown={(e) => {                    const i = ranges.indexOf(r);                    const step = { ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1 }[e.key];                    if (!step) return;                    e.preventDefault();                    const next = ranges[(i + step + ranges.length) % ranges.length];                    choose(next.id);                    (switchRef.current?.querySelector(`[data-range="${CSS.escape(next.id)}"]`) as HTMLElement | null)?.focus();                  }}                  className={`relative z-10 grid h-6 min-w-6 cursor-pointer place-items-center rounded-full px-1.5 text-[11px] font-semibold outline-none transition-colors duration-200 focus-visible:ring-2 focus-visible:ring-white/70 ${                    on ? "text-[#0b0b10]" : "text-white/65 hover:text-white"                  }`}                >                  {r.label}                </button>              );            })}          </div>        )}      </div>      <div className="mt-3">        <div className="flex items-center gap-2.5">          <span className="text-[34px] font-normal leading-none tracking-[-0.03em] tabular-nums text-white">            <NumberRoll value={current.total} format={format} locales={lang} suffix={unit} />          </span>          {current.change !== undefined && (            <span              className="inline-flex items-center gap-0.5 rounded-full px-2 py-0.5 text-[11px] font-semibold leading-tight tabular-nums"              style={up ? { background: accent, color: "#11140a" } : { background: "rgb(255 255 255 / 0.14)", color: "#fff" }}            >              {up ? <ArrowUpRight className="size-3" strokeWidth={2.6} aria-hidden /> : <ArrowDownRight className="size-3" strokeWidth={2.6} aria-hidden />}              <NumberRoll value={Math.abs(current.change)} format={{ maximumFractionDigits: 1 }} locales={lang} suffix="%" />            </span>          )}        </div>        <p className="mt-1.5 h-[18px] text-[12px] tabular-nums text-white/65">          <TextMorph>{bar ? (bar.detail ?? `${bar.label} · ${nf.format(bar.value)}${unit}`) : ""}</TextMorph>        </p>      </div>      <div className="relative mt-4 h-[148px]">        {leavingRange && (          <Pillars key={`out-${leaving!.key}`} range={leavingRange} selected={-1} onSelect={() => {}} enter={0} leaving reduced={reduced} accent={accent} />        )}        <Pillars          key={`in-${shown.key}`}          range={current}          selected={selected}          onSelect={(i) => setPicked({ range: current.id, index: i })}          enter={shown.enter}          leaving={false}          reduced={reduced}          accent={accent}        />      </div>      <table className="sr-only">        <caption>          {title}, {current.name ?? current.label}: {nf.format(current.total)}          {unit}        </caption>        <tbody>          {current.bars.map((b) => (            <tr key={b.label}>              <th scope="row">{b.label}</th>              <td>                {nf.format(b.value)}                {unit}              </td>            </tr>          ))}        </tbody>      </table>    </div>  );}

Registry item: /r/pillar-chart.json