Louis Studios

Waffle Chart

Cards 11

About

A waffle chart stat card. Pick a tab and its hundred cells fly, shrink and recolour to the new data set while the legend percentages count; hover a legend row or a cell to dim the rest and read a tooltip. Your own categories, data sets and colours as props. More like this, plus a designer your coding agent can use, at studios.lou15.com/?ref=21st

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Waffle Chart to your project and fits it to your theme.

Code

How Waffle Chart is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import * as React from "react";
import { WaffleChart, type WaffleCategory, type WaffleDataset } from "@/components/ui/waffle-chart";

/** True while the page (or any ancestor) carries the `dark` class. */
function useDarkClass(ref: React.RefObject<HTMLElement | null>) {
  const [dark, setDark] = React.useState(false);
  React.useEffect(() => {
    const read = () => setDark(!!ref.current?.closest(".dark"));
    read();
    const mo = new MutationObserver(read);
    mo.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });
    mo.observe(document.body, { attributes: true, attributeFilter: ["class"] });
    return () => mo.disconnect();
  }, [ref]);
  return dark;
}

/* Two made-up data sets with their own shapes and colours. */
const HOURS: WaffleDataset[] = [
  { id: "q1", tab: "Q1", name: "Q1 2026", total: 1240, values: [38, 18, 9, 14, 13, 8] },
  { id: "q2", tab: "Q2", name: "Q2 2026", total: 1312, values: [34, 24, 11, 12, 11, 8] },
  { id: "q3", tab: "Q3", name: "Q3 2026", total: 1096, values: [29, 21, 8, 10, 10, 22] },
  { id: "q4", tab: "Q4", name: "Q4 2026", total: 1288, values: [41, 15, 12, 13, 12, 7] },
];
const hoursCats = (dark: boolean): WaffleCategory[] => [
  { label: "Client work", color: dark ? "#5b7cf0" : "#3b5bdb", shape: "square" },
  { label: "Product", color: dark ? "#9b6cf6" : "#7c3aed", shape: "square" },
  { label: "Research", color: dark ? "#2cc3c1" : "#0ea5a4", shape: "circle" },
  { label: "Meetings", color: dark ? "#f5b02e" : "#f59f00", shape: "ring" },
  { label: "Admin", color: dark ? "#7c8698" : "#94a3b8", shape: "square" },
  { label: "Time off", color: dark ? "#4a4f5a" : "#d3d9e2", shape: "circle" },
];

const TRIPS: WaffleDataset[] = [
  { id: "win", tab: "Win", name: "Winter", total: 1860, values: [12, 14, 38, 22, 14] },
  { id: "spr", tab: "Spr", name: "Spring", total: 2040, values: [28, 18, 30, 14, 10] },
  { id: "sum", tab: "Sum", name: "Summer", total: 1980, values: [41, 20, 22, 9, 8] },
  { id: "aut", tab: "Aut", name: "Autumn", total: 2110, values: [26, 17, 32, 15, 10] },
];
const tripCats = (dark: boolean): WaffleCategory[] => [
  { label: "Bike", color: dark ? "#2fb865" : "#16a34a", shape: "circle" },
  { label: "Walk", color: dark ? "#9bd93a" : "#7cc015", shape: "circle" },
  { label: "Train", color: dark ? "#2a9fe0" : "#0284c7", shape: "square" },
  { label: "Bus", color: dark ? "#fb8a3c" : "#f97316", shape: "square" },
  { label: "Car", color: dark ? "#8f8a85" : "#a8a29e", shape: "ring" },
];

const LIGHT = { cardColor: "#ffffff", borderColor: "#e9e9ec", textColor: "#0a0a0a", mutedColor: "#71717a", trackColor: "#f1f1f3" };
const DARK = { cardColor: "#161618", borderColor: "#29292d", textColor: "#f4f4f5", mutedColor: "#a1a1aa", trackColor: "#2e2e33" };

/**
 * Two waffle cards, each set up through props: its own categories (colour and cell shape), data
 * sets and autoplay cycle. Pick a tab and the hundred cells fly to the new data; hover a legend row
 * or a cell to read its share. Autoplay pauses while the pointer is on a card.
 */
export default function WaffleChartDemo() {
  const ref = React.useRef<HTMLElement>(null);
  const dark = useDarkClass(ref);
  const theme = dark ? DARK : LIGHT;

  return (
    <main ref={ref} className="relative flex h-screen min-h-[340px] w-full items-center justify-center overflow-hidden bg-background p-3">
      <div className="grid w-full max-w-[1040px] grid-cols-1 items-center gap-2 md:grid-cols-2">
        <WaffleChart
          title="Studio hours by quarter"
          unit="hours"
          categories={hoursCats(dark)}
          datasets={HOURS}
          autoplay
          cycle={10}
          size={520}
          {...theme}
          style={{ height: "auto", minHeight: 0 }}
        />
        <div className="hidden md:block">
        <WaffleChart
          title="How the team gets to work"
          unit="trips"
          categories={tripCats(dark)}
          datasets={TRIPS}
          defaultValue="sum"
          autoplay
          cycle={12.5}
          stagger={2.6}
          size={520}
          {...theme}
          style={{ height: "auto", minHeight: 0 }}
        />
        </div>
      </div>
    </main>
  );
}

More by Louis Studios

View all
  • Warp Carousel

    Warp Carousel

    1.4K
  • Peak Chart

    Peak Chart

    1.2K
  • Dot Tiles

    Dot Tiles

    197
  • Glow Rocker

    Glow Rocker

    188
  • Chrome Arcs

    Chrome Arcs

    180
  • Cover Flow

    Cover Flow

    177
  • Market Card

    Market Card

    146
  • Chapter Player

    Chapter Player

    140

More in Cards

View all
  • Course Design Cards

    Course Design Cards

    1.3K
  • Photo Deck

    Photo Deck

    47
  • Folded Card

    Folded Card

    45
  • Statistics Card 10

    Statistics Card 10

    304
  • Statistics Card 2

    Statistics Card 2

    309
  • Statistics Card 7

    Statistics Card 7

    336
  • CTA Section

    CTA Section

    6
  • Liquid Glass Card

    Liquid Glass Card

    198