A pricing calculator drawn as a tape measure

Build a website cost calculator in React that measures the project as a tape: ticking pieces pulls the tape out week by week and slides the price along, with transforms only.

6 min read

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

Agency pricing is scope, time and money, and most pricing tables show only money. A tape measure shows all three in one object.

One week per graduation

The tape's hook is held at kick-off on the left. Each ticked piece pulls out more tape, one week per graduation, and the case with the price on its face slides to where the tape stops. Unticking winds it back.

src/registry/pricing/tape-measure/tape-measure.tsx

"use client";

import { motion } from "motion/react";
import { SPRING_SOFT } from "@/lib/motion";
import { usePrefersReducedMotion } from "@/hooks/use-prefers-reduced-motion";
import { PhaseBands } from "./phase-bands";
import type { QuoteSchedule } from "./quote-schedule";
import { TapeCase } from "./tape-case";
import { TapeMarks } from "./tape-marks";
import type { QuoteCopy } from "./types";

const STILL = { duration: 0 };

interface TapeMeasureProps {
  schedule: QuoteSchedule;
  // The tape's full length: every piece ticked.
  scaleWeeks: number;
  activePhase: string | null;
  // "Kick-off Jan 11" under the hook, "Live by Mar 15" under the case.
  kickoffText: string;
  launchText: string;
  copy: QuoteCopy;
  currency: string;
  locale: string;
}

// The project measured out as a tape: its hook held at kick-off on the left, the tape pulled out one week per
// graduation, and the case, with the price on its face, sitting where the tape stops. Ticking a piece pulls more
// tape out and slides the case along; unticking winds it back. Only transforms and a clip move. The dates under
// it are for the eye; the summary under the pieces says the same for screen readers.
export function TapeMeasure({
  schedule,
  scaleWeeks,
  activePhase,
  kickoffText,
  launchText,
  copy,
  currency,
  locale,
}: TapeMeasureProps) {
  const isStill = usePrefersReducedMotion();
  const transition = isStill ? STILL : SPRING_SOFT;
  const reach = (schedule.totalWeeks / scaleWeeks) * 100;

  return (
    // Clipped sideways only: the case's sliding layer reaches past the tape, its shadow may spill above and below.
    <figure aria-label={copy.tapeLabel} className="overflow-x-clip pr-26 sm:pr-34">
      <div className="relative h-36 sm:h-44">
        {/* Graph paper under the tape, one column per week so its lines meet the tape's week marks, fading out
            above, below and toward the far end. */}
        <div
          aria-hidden
          className="absolute inset-x-0 -top-10 -bottom-10 bg-graph mask-t-from-60% mask-r-from-85% mask-b-from-60% text-foreground/10"
          style={{ backgroundSize: `${100 / scaleWeeks}% 1.5rem` }}
        />
        <motion.div
          initial={false}
          animate={{ clipPath: `inset(0 ${100 - reach}% 0 0)` }}
          transition={transition}
          className="absolute inset-x-0 top-7 h-14 bg-primary text-primary-foreground shadow-md sm:top-11"
        >
          <span
            aria-hidden
            className="absolute inset-x-0 top-0 h-1/2 bg-linear-to-b from-primary-foreground/15 to-transparent"
          />
          <TapeMarks weeks={scaleWeeks} />
          <PhaseBands
            spans={schedule.spans}
            scaleWeeks={scaleWeeks}
            activePhase={activePhase}
            transition={transition}
          />
        </motion.div>
        <span aria-hidden className="absolute top-5 -left-1 h-18 w-2 rounded-sm bg-foreground sm:top-9" />
        <p aria-hidden className="absolute bottom-0 left-0 text-sm text-muted-foreground">
          {kickoffText}
        </p>
        <motion.div
          initial={false}
          animate={{ x: `${reach}%` }}
          transition={transition}
          className="pointer-events-none absolute inset-0"
        >
          <div className="absolute top-0 -left-2 flex flex-col items-center gap-2">
            <TapeCase
              totalPrice={schedule.totalPrice}
              totalWeeks={schedule.totalWeeks}
              label={copy.totalLabel}
              note={copy.priceNote}
              currency={currency}
              locale={locale}
              transition={transition}
            />
            <p aria-hidden className="text-sm font-medium whitespace-nowrap">
              {launchText}
            </p>
          </div>
        </motion.div>
      </div>
    </figure>
  );
}
The tape: only transforms and a clip move

The quote is real

Under the tape, the pieces sit in columns by phase. The total, the dates and a button that emails the quote exactly as built update together. Dates are worked out from the kick-off day in UTC, so the server and every visitor print the same thing.

src/registry/pricing/tape-measure/quote-builder.tsx

"use client";

import { useState } from "react";
import { Mail } from "lucide-react";
import { Button } from "@/components/ui/button";
import { formatDay, fromIsoDay } from "../shared/format";
import { AnimatedPrice } from "./animated-price";
import { PhaseColumn } from "./phase-column";
import {
  formatWeeks,
  getLaunchDay,
  getLongestWeeks,
  getQuoteEmailHref,
  getStartingPicks,
  scheduleQuote,
} from "./quote-schedule";
import { TapeMeasure } from "./tape-measure";
import type { QuoteBooking, QuoteCopy, QuotePhase, QuotePiece } from "./types";

interface QuoteBuilderProps {
  phases: QuotePhase[];
  pieces: QuotePiece[];
  kickoff: string;
  booking: QuoteBooking;
  note?: string;
  copy: QuoteCopy;
  currency: string;
  locale: string;
}

// The live quote: the tape on top, the pieces in one column per phase under it, and the dates, the total and the
// button that emails the quote exactly as built.
export function QuoteBuilder({ phases, pieces, kickoff, booking, note, copy, currency, locale }: QuoteBuilderProps) {
  const [picked, setPicked] = useState(() => getStartingPicks(pieces));
  const [activePhase, setActivePhase] = useState<string | null>(null);
  const schedule = scheduleQuote(phases, pieces, picked);
  const kickoffText = `${copy.kickoffLabel} ${formatDay(fromIsoDay(kickoff), locale)}`;
  const launchText = `${copy.launchLabel} ${getLaunchDay(kickoff, schedule.totalWeeks, locale)}`;
  const dates = `${kickoffText} · ${launchText}`;
  const href = getQuoteEmailHref({
    booking,
    pieces: pieces.filter((piece) => picked.has(piece.id)),
    totalPrice: schedule.totalPrice,
    dates,
    currency,
    locale,
  });

  const toggle = (id: string) =>
    setPicked((current) => {
      const next = new Set(current);
      if (next.has(id)) next.delete(id);
      else next.add(id);
      return next;
    });

  return (
    <div className="overflow-hidden rounded-2xl border bg-card text-card-foreground shadow-xl">
      {/* The bench the tape lies on: a soft paper band with a little grain, set off from the pieces by a hairline. */}
      <div className="relative isolate border-b bg-muted/60 px-5 pt-10 pb-8 sm:px-8 sm:pt-12">
        <div aria-hidden className="absolute inset-0 -z-10 bg-grain opacity-5" />
        <TapeMeasure
          schedule={schedule}
          scaleWeeks={getLongestWeeks(phases, pieces)}
          activePhase={activePhase}
          kickoffText={kickoffText}
          launchText={launchText}
          copy={copy}
          currency={currency}
          locale={locale}
        />
      </div>
      <div className="flex flex-col gap-8 p-5 sm:p-8">
        <div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-4 lg:gap-4">
          {phases.map((phase) => (
            <PhaseColumn
              key={phase.id}
              phase={phase}
              pieces={pieces.filter((piece) => piece.phase === phase.id)}
              picked={picked}
              weeks={schedule.spans.find((span) => span.id === phase.id)?.weeks ?? 0}
              onToggle={toggle}
              onPoint={setActivePhase}
              copy={copy}
              currency={currency}
              locale={locale}
            />
          ))}
        </div>
        <div className="flex flex-col gap-6 border-t pt-6 lg:flex-row lg:items-end lg:justify-between">
          <div className="flex flex-col gap-1">
            <p aria-live="polite" className="text-base font-semibold">
              {dates} · {formatWeeks(schedule.totalWeeks, copy)}
            </p>
            {note && <p className="text-sm text-muted-foreground">{note}</p>}
          </div>
          <div className="flex flex-wrap items-end gap-x-8 gap-y-4">
            <p className="flex flex-col gap-1.5">
              <span className="text-sm text-muted-foreground">
                {copy.totalLabel} · {copy.priceNote}
              </span>
              <AnimatedPrice
                amount={schedule.totalPrice}
                currency={currency}
                locale={locale}
                className="text-4xl leading-none font-semibold tracking-tight tabular-nums"
              />
            </p>
            <Button asChild size="lg" className="shrink-0">
              <a href={href}>
                <Mail aria-hidden className="size-4" />
                {booking.label}
              </a>
            </Button>
          </div>
        </div>
      </div>
    </div>
  );
}
The live quote

Accessible by default

The tape is for the eye; a plain summary under the pieces says the same for screen readers, and every piece is a real checkbox.

More articles