A stats section that proves itself: numbers, people and live clocks

Build a proof section as a bento in React: a counted headline number with a bar per year, the team with live local times, one quote, the tools used and client names drifting past.

6 min read

The real component. Click the picture to open it live and try it before you read how it was built.

A row of four big numbers is the most skipped section on a landing page. This bento gives each proof its own tile and makes the tiles answer the pointer.

People in their own time

The team tile shows each person with their city and a live clock. Pointing at a person lights up their city's clock; pointing at a clock lights up everyone who works there. A remote team reads as real.

src/registry/stats/proof-bento/team-card.tsx

"use client";

import { useState } from "react";
import { cn } from "@/lib/utils";
import { CityClocks, type TeamCity } from "./city-clocks";
import { Monogram } from "./monogram";
import { ProofCard } from "./proof-card";
import { formatCityTime, useClock } from "./use-clock";

export interface TeamMember {
  name: string;
  role: string;
  // One of the cities' names.
  city: string;
}

export interface TeamCardProps {
  label: string;
  // Shown top right until someone is pointed at, such as "9 people · 3 cities".
  summary: string;
  people: TeamMember[];
  cities: TeamCity[];
}

const focusRing = "outline-none focus-visible:ring-3 focus-visible:ring-ring/50";

// The team as monograms with each person's city and local time. Pointing at a person lights up their city's
// clock; pointing at a clock lights up everyone who works there.
export function TeamCard({ label, summary, people, cities }: TeamCardProps) {
  const time = useClock();
  const [activePerson, setActivePerson] = useState<TeamMember | null>(null);
  const [hoveredCity, setHoveredCity] = useState<string | null>(null);
  const activeCity = activePerson?.city ?? hoveredCity;
  const zoneOf = (city: string) => cities.find((entry) => entry.name === city)?.timeZone ?? "UTC";

  return (
    <ProofCard label={label} aside={activePerson ? `${activePerson.name} · ${activePerson.role}` : summary}>
      <ul className="grid flex-1 grid-cols-3 gap-1">
        {people.map((person, index) => {
          const isDimmed = activeCity !== null && person.city !== activeCity;
          return (
            <li key={person.name}>
              <button
                type="button"
                aria-label={`${person.name}, ${person.role}, ${person.city}`}
                onPointerEnter={() => setActivePerson(person)}
                onPointerLeave={() => setActivePerson(null)}
                onFocus={() => setActivePerson(person)}
                onBlur={() => setActivePerson(null)}
                className={cn(
                  "flex w-full flex-col items-start gap-2 rounded-2xl p-2 text-left transition duration-300 hover:bg-muted",
                  focusRing,
                  isDimmed && "opacity-40",
                )}
              >
                <Monogram name={person.name} index={index} className="size-12 rounded-xl text-base" />
                <span className="flex w-full min-w-0 flex-col">
                  <span className="truncate text-sm font-medium">{person.name.split(" ")[0]}</span>
                  <span className="truncate font-mono text-2xs text-muted-foreground">
                    {person.city}
                    {time !== null && ` · ${formatCityTime(time, zoneOf(person.city), false).clock}`}
                  </span>
                </span>
              </button>
            </li>
          );
        })}
      </ul>
      <CityClocks cities={cities} time={time} activeCity={activeCity} onHoverCity={setHoveredCity} />
    </ProofCard>
  );
}
The team and their cities

Clocks that hydrate cleanly

The server can't know the visitor's time, so it renders no clock and the browser fills it in after hydration, ticking once a second.

src/registry/stats/proof-bento/use-clock.ts

"use client";

import { useSyncExternalStore } from "react";

const SECOND_MS = 1000;

function subscribe(onTick: () => void) {
  const timer = window.setInterval(onTick, SECOND_MS);
  return () => window.clearInterval(timer);
}

// Whole seconds, so the value only changes once a second.
const getSnapshot = () => Math.floor(Date.now() / SECOND_MS) * SECOND_MS;
// The server can't know the visitor's time, so it renders no clock and the browser fills it in.
const getServerSnapshot = () => null;

// The current time in milliseconds, ticking every second, or null until the page has hydrated.
export function useClock(): number | null {
  return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
}

const formatters = new Map<string, Intl.DateTimeFormat>();

// The time in a city as "14:05:09" (or "14:05" without seconds), with its UTC offset as "GMT+5:30".
export function formatCityTime(time: number, timeZone: string, hasSeconds = true): { clock: string; offset: string } {
  const key = `${timeZone}-${hasSeconds}`;
  let formatter = formatters.get(key);
  if (!formatter) {
    const options: Intl.DateTimeFormatOptions = {
      timeZone,
      hour: "2-digit",
      minute: "2-digit",
      hourCycle: "h23",
      timeZoneName: "shortOffset",
    };
    formatter = new Intl.DateTimeFormat("en-GB", hasSeconds ? { ...options, second: "2-digit" } : options);
    formatters.set(key, formatter);
  }
  const parts = formatter.formatToParts(time);
  const clock = parts
    .filter((part) => ["hour", "minute", "second", "literal"].includes(part.type))
    .map((part) => part.value)
    .join("")
    .trim();
  return { clock, offset: parts.find((part) => part.type === "timeZoneName")?.value ?? "" };
}
The clock hook

The number earns its place

The headline number counts up the first time it is seen, beside a bar per year; pointing at a bar reads out that year.

More articles