Skip to content
Browse documentation

A storage meter with a raccoon and his suitcase: near the limit the case bulges and Pack sits on it to shut it; clean up and he hops down, upgrade and a roomy trunk arrives.

Used forStorage settingsPlan limitsClean-up promptsBilling pages

Install with the shadcn CLI

$ npx shadcn@latest add @hairline/storage

Older shadcn CLI, or a network that blocks ui.shadcn.com? Install by URL: shadcn add https://hairlineui.com/r/storage.json. More

Templates

Need the whole page?

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

Where it’s used

  • Storage settings

    The usage card in a file, photo or backup app.

  • Plan limits

    Any metered limit near its cap, with the upgrade right there.

  • Clean-up prompts

    Empty the trash or drop old versions before paying for more.

  • Billing pages

    Usage beside the plan, so the upgrade makes sense.

What it handles for you

A usage bar alone doesn’t say what to do about it. This block shows what the space is used by, makes being nearly full feel like it, and puts the two ways out side by side.

Instead of wiring upa usage metera breakdown bar and legendbyte formattingclean-up and upgrade buttons
  1. Nearly full, plainly

    From 90% the case bulges, Pack sits on it and the numbers turn amber.

  2. What it’s used by

    kinds split one bar by type with a legend and the free space.

  3. Numbers that roll

    Used, limit and every size roll to their new values, in B, KB, MB, GB or TB.

  4. Two ways out

    onCleanUp and onUpgrade sit side by side with Pending, Done and Try again states.

  5. Room to spare

    roomy swaps in the trunk for plans with plenty of space.

  6. A real meter

    The bar is a meter with the used and allowed bytes and a readable value.

Overview

Storage limits usually show up as a thin bar turning red. This one packs a suitcase. A teal case stands shut on the lit stage and Pack, an animated raccoon, leans on it at his ease. From 90% of the limit the case bulges, a sock and a holiday photo poking out of the zip, and Pack scrambles up and sits on top, pushing down with all he’s got as the case squashes under him. Empty the trash and the clothes slide back in, the case shrinks and he climbs back down; upgrade and a roomy leather trunk takes its place while he cheers. Under the stage is the real meter: what’s used of the limit with every number rolling, one bar split by what the space is used by, a legend with the free space, and Clean up and Upgrade wired to your functions.

States

roomy
Under 75%: the case stands shut and Pack leans on it; “Plenty of room”.
snug
75% to 90%: the same, with “Getting snug in there”.
full
Crossing 90%: the case bulges, a sock and a photo pop out of the zip and Pack climbs on top (a 1.6s clip), then loops pushing down on it, cheeks puffed, as it squashes under him; the used figure turns amber; “Pack can’t get it shut”.
clean up
Clean up → Cleaning up → Cleaned up; when used drops under 90% the case shuts and he hops down; the bar and the sizes roll down.
upgrade
Upgrade → Upgrading → Upgraded; with roomy the trunk takes the case’s place and Pack cheers beside it; “Room to spare”.

Usage

usage.tsx
import { Storage } from "@/components/storage";<Storage  used={usage.bytes}  limit={plan.bytes}  kinds={[{ id: "photos", label: "Photos", bytes: usage.photos }]}/>

Works with

With clean-up and upgrade

Both actions call your API and then refresh the numbers; roomy is your call for plans with plenty of space.

example.tsx
"use client";import useSWR from "swr";import { Storage } from "@/components/storage";export function StorageCard() {  const { data, mutate } = useSWR("/api/storage", (u) => fetch(u).then((r) => r.json()));  if (!data) return null;  return (    <Storage      used={data.used}      limit={data.limit}      roomy={data.limit >= 1e12}      kinds={data.kinds} // [{ id, label, bytes }]      cleanUpLabel={`Empty trash · ${(data.trash / 1e9).toFixed(1)} GB`}      onCleanUp={async () => {        await fetch("/api/storage/trash", { method: "DELETE" });        await mutate();      }}      upgradeLabel="Upgrade to 1 TB"      onUpgrade={async () => {        window.location.href = "/billing/upgrade?plan=1tb";      }}    />  );}

Props

used / limit
number
Bytes used and bytes allowed.
kinds= []
StorageKind[]
{ id, label, bytes, color? } for the bar and its legend; colours default to --chart-1…5.
onCleanUp / cleanUpLabel= — / "Clean up"
() => Promise<unknown> / string
Free some space; update used afterwards. Throw to show Try again.
onUpgrade / upgradeLabel= — / "Upgrade"
() => Promise<unknown> / string
Move to a bigger plan; update limit (and roomy) afterwards.
roomy= false
boolean
Show the roomy trunk and hide Upgrade.
name= "Pack"
string
What the raccoon is called in his lines.

Accessibility and motion

  • The bar is a meter with aria-valuenow, aria-valuemax and a readable value text; the legend lists every kind with its size and the free space.
  • Pack is decoration (aria-hidden) and animated: his idle, the climb onto the case, the push and the cheer are frames cut from generated animations, shipped inside pack-art.ts as WebP strips (158KB), so the install is complete. Cleaning up plays the climb backwards, so he lands exactly on his idle.
  • Every loop is one Web Animation of the strip (no frame loop, no React renders).
  • With reduced motion he shows each state’s first frame and nothing plays.
  • Built from Number roll, Status button and Text morph, which the CLI installs with it. No animation library.

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, Status button, Text morph.

Source

"use client";import * as React from "react";import { NumberRoll } from "./number-roll";import { playStrip, preloadStrips } from "./cast-sprite";import { PACK_ART as ART, PACK_FRAMES as F } from "./pack-art";import { StatusButton, type ActionStatus } from "./status-button";import { TextMorph } from "./text-morph";import { EASE_OUT, useInteractionReducedMotion } from "./ui-interaction-motion";/* ───────────────────────────────────────────────────────── * STORAGE: Pack and his suitcase * *   roomy    an animated raccoon, Pack, leans on his case at *            his ease *   full     crossing 90% the case bulges, a sock and a photo *            pop out of the zip, and he climbs on top and keeps *            pushing it down *   clean up the same clip backwards: the clothes go back in and *            he climbs down to lean on it again *   upgrade  a roomy trunk, and he cheers beside it * * Under the stage: what's used of the limit (rolling), a bar of * what it's used by, and the two actions. * ───────────────────────────────────────────────────────── */export interface StorageKind {  id: string;  label: string;  bytes: number;  /** Any CSS colour; defaults to the theme's --chart-1…5. */  color?: string;}export interface StorageProps {  /** Bytes used. */  used: number;  /** Bytes allowed on the plan. */  limit: number;  /** What the space is used by, for the bar and its legend. */  kinds?: StorageKind[];  /** Free some space (empty the trash, old versions…); update `used` afterwards. */  onCleanUp?: () => Promise<unknown>;  cleanUpLabel?: string;  /** Move to a bigger plan; update `limit` afterwards. */  onUpgrade?: () => Promise<unknown>;  upgradeLabel?: string;  /** Show the roomy trunk (a plan with plenty of space). */  roomy?: boolean;  /** What the raccoon is called in his lines. */  name?: string;  className?: string;}const mix = (color: string, amount: number, into = "transparent") => `color-mix(in oklab, ${color} ${amount}%, ${into})`;const PF = "var(--primary-foreground)";const CARD: React.CSSProperties = {  backgroundImage: `linear-gradient(180deg, var(--card), ${mix("var(--card)", 95, "var(--foreground)")})`,  boxShadow: `0 0 0 1px var(--border), inset 0 1px 0 ${mix("var(--background)", 85)}`,};/* The one lit surface: a baggage carousel's slats under everything. */const STAGE: React.CSSProperties = {  backgroundColor: "var(--primary)",  backgroundImage: [    `radial-gradient(55% 80% at 55% 100%, ${mix(PF, 22)} 0%, transparent 70%)`,    `linear-gradient(175deg, transparent 40%, ${mix("black", 20)} 100%)`,    `repeating-linear-gradient(90deg, ${mix(PF, 14)} 0 1px, transparent 1px 22px)`,  ].join(", "),  backgroundSize: "auto, auto, 100% 14px",  backgroundRepeat: "no-repeat, no-repeat, no-repeat",  backgroundPosition: "0 0, 0 0, 0 100%",  boxShadow: `inset 0 1px 0 ${mix(PF, 36)}, inset 0 0 0 1px ${mix(PF, 12)}`,};const LIT: React.CSSProperties = {  backgroundImage: `linear-gradient(180deg, ${mix(PF, 16)}, transparent 60%)`,  boxShadow: `inset 0 1px 0 ${mix(PF, 32)}, inset 0 0 0 1px ${mix("black", 10)}`,};const CHART = ["var(--chart-1, var(--primary))", "var(--chart-2, #10b981)", "var(--chart-3, #f59e0b)", "var(--chart-4, #8b5cf6)", "var(--chart-5, #ef4444)"];/* the scene, drawn at 364 × 168 and scaled to the stage */const W = 364;const H = 168;/** One animation frame on the stage: he and his luggage stand in it. */const FRAME_H = 152;const FRAME_W = (F.w / F.h) * FRAME_H;type Mode = "lean" | "full" | "roomy";/** Pack, animated: each mode is a loop of frames, and the changes between them are clips. */function PackSprite({ mode, reduced }: { mode: Mode; reduced: boolean }) {  const sprite = React.useRef<HTMLDivElement>(null);  const was = React.useRef<Mode | null>(null);  React.useEffect(() => {    preloadStrips(Object.values(ART));  }, []);  React.useEffect(() => {    const el = sprite.current;    if (!el) return;    const prev = was.current;    was.current = mode;    const loop = (clip: "lean" | "push" | "cheer") =>      playStrip(el, { src: ART[clip], frames: F.clips[clip].frames, fps: F.clips[clip].fps, size: FRAME_W, height: FRAME_H, reduced });    const idle = { lean: () => loop("lean"), full: () => loop("push"), roomy: () => loop("cheer") }[mode];    if (prev === null || prev === mode || reduced) return void idle();    if (prev === "lean" && mode === "full") {      // the case bulges and he climbs on top to hold it shut      playStrip(el, { src: ART.fill, frames: F.clips.fill.frames, fps: F.clips.fill.fps, size: FRAME_W, height: FRAME_H, loop: false, onEnd: idle });      return;    }    if (prev === "full" && mode === "lean") {      // the same, backwards: the clothes go back in and he climbs down      playStrip(el, { src: ART.fill, frames: F.clips.fill.frames, fps: F.clips.fill.fps, size: FRAME_W, height: FRAME_H, loop: false, reverse: true, onEnd: idle });      return;    }    // a different case altogether: a quick pop between them    idle();    el.parentElement?.animate(      [        { opacity: 0, transform: "translateY(6px) scale(0.94)", filter: "blur(3px)" },        { opacity: 1, transform: "none", filter: "blur(0px)" },      ],      { duration: 420, easing: "cubic-bezier(0.34,1.36,0.64,1)" },    );  }, [mode, reduced]);  return (    <div className="absolute" style={{ left: W / 2 - FRAME_W / 2 + 26, top: H - FRAME_H - 4, width: FRAME_W, height: FRAME_H, transformOrigin: "50% 100%" }}>      <div ref={sprite} className="size-full" />    </div>  );}function bytes(n: number) {  const units = ["B", "KB", "MB", "GB", "TB"];  let v = Math.max(0, n);  let i = 0;  while (v >= 1000 && i < units.length - 1) {    v /= 1000;    i++;  }  return { value: v, unit: units[i], digits: v < 10 && i > 0 ? 1 : 0 };}function Size({ n }: { n: number }) {  const b = bytes(n);  return (    <span className="whitespace-nowrap tabular-nums">      <NumberRoll value={b.value} format={{ maximumFractionDigits: b.digits, minimumFractionDigits: b.digits }} /> {b.unit}    </span>  );}export function Storage({  used,  limit,  kinds = [],  onCleanUp,  cleanUpLabel = "Clean up",  onUpgrade,  upgradeLabel = "Upgrade",  roomy = false,  name = "Pack",  className = "",}: StorageProps) {  const reduced = useInteractionReducedMotion();  const baseId = React.useId();  const [clean, setClean] = React.useState<ActionStatus>("idle");  const [upgrade, setUpgrade] = React.useState<ActionStatus>("idle");  const ratio = limit > 0 ? used / limit : 1;  const full = !roomy && ratio >= 0.9;  const mode: Mode = roomy ? "roomy" : full ? "full" : "lean";  const run = async (fn: (() => Promise<unknown>) | undefined, set: (s: ActionStatus) => void) => {    if (!fn) return;    set("pending");    try {      await fn();      set("success");      window.setTimeout(() => set("idle"), 1600);    } catch {      set("error");    }  };  const mood = roomy    ? "Room to spare"    : full      ? `${name} can’t get it shut`      : ratio >= 0.75        ? "Getting snug in there"        : clean === "success"          ? "Phew. Room again"          : "Plenty of room";  const total = kinds.reduce((s, k) => s + k.bytes, 0);  const left = Math.max(0, limit - used);  return (    <section aria-labelledby={`${baseId}-title`} className={`relative w-full max-w-[380px] rounded-[28px] p-2 text-card-foreground ${className}`} style={CARD}>      {/* Its natural width where the parent sizes to its content, without forcing it on narrow screens. */}      <div aria-hidden="true" data-natural-width className="grid h-0" style={{ gridTemplateColumns: "minmax(0, 380px)" }} />      <div className="@container w-full">        <div className="relative overflow-clip rounded-[22px] text-primary-foreground" style={STAGE}>          <Scene>            <PackSprite mode={mode} reduced={reduced} />          </Scene>          <p className="absolute left-3.5 top-3 z-10 text-[12.5px] font-medium text-primary-foreground/85">            <TextMorph>{mood}</TextMorph>          </p>        </div>        <div className="px-3 pb-1 pt-3">          <div className="flex items-baseline justify-between gap-3">            <h2 id={`${baseId}-title`} className="text-[15px] font-medium tracking-[-0.01em]">              Storage            </h2>            <p className={`text-[12.5px] ${full ? "text-amber-700 dark:text-amber-400" : "text-muted-foreground"}`}>              <span className="font-medium text-foreground">                <Size n={used} />              </span>{" "}              of <Size n={limit} />            </p>          </div>          {/* what it's used by: one bar, one segment per kind, and the space left */}          <div            className="mt-2.5 flex h-2.5 w-full gap-[2px] overflow-clip rounded-full"            role="meter"            aria-label="Storage used"            aria-valuemin={0}            aria-valuemax={limit}            aria-valuenow={used}            aria-valuetext={`${bytes(used).value.toFixed(bytes(used).digits)} ${bytes(used).unit} of ${bytes(limit).value.toFixed(bytes(limit).digits)} ${bytes(limit).unit} used`}            style={{ background: mix("var(--foreground)", 7) }}          >            {(kinds.length ? kinds : [{ id: "used", label: "Used", bytes: used }]).map((k, i) => (              <span                key={k.id}                className="h-full shrink-0 first:rounded-l-full"                style={{                  width: `${(Math.min(k.bytes, limit) / Math.max(1, limit)) * 100 * (kinds.length && total > used ? used / total : 1)}%`,                  background: k.color ?? CHART[i % CHART.length],                  transition: reduced ? "none" : `width 700ms ${EASE_OUT}`,                }}              />            ))}          </div>          {kinds.length > 0 && (            <ul className="mt-2 flex flex-wrap gap-x-3 gap-y-1 text-[12px] text-muted-foreground">              {kinds.map((k, i) => (                <li key={k.id} className="flex items-center gap-1.5">                  <span className="size-2 rounded-full" style={{ background: k.color ?? CHART[i % CHART.length] }} />                  {k.label}                  <span className="text-foreground">                    <Size n={k.bytes} />                  </span>                </li>              ))}              <li className="flex items-center gap-1.5">                <span className="size-2 rounded-full" style={{ background: mix("var(--foreground)", 12) }} />                Free                <span className="text-foreground">                  <Size n={left} />                </span>              </li>            </ul>          )}        </div>        {(onCleanUp || onUpgrade) && (          <div className="flex gap-2 px-2 pb-1 pt-3">            {onCleanUp && (              <StatusButton                variant="outline"                status={clean}                labels={{ idle: cleanUpLabel, pending: "Cleaning up", success: "Cleaned up", error: "Try again" }}                onClick={() => run(onCleanUp, setClean)}                className="h-10 flex-1 text-[13.5px]"              />            )}            {onUpgrade && !roomy && (              <StatusButton                status={upgrade}                labels={{ idle: upgradeLabel, pending: "Upgrading", success: "Upgraded", error: "Try again" }}                onClick={() => run(onUpgrade, setUpgrade)}                className="h-10 flex-1 text-[13.5px]"                style={upgrade === "error" ? undefined : LIT}              />            )}          </div>        )}      </div>    </section>  );}/** The stage's scene, drawn at 364 × 168 and scaled to fit. */function Scene({ children }: { children: React.ReactNode }) {  const host = React.useRef<HTMLDivElement>(null);  const scene = React.useRef<HTMLDivElement>(null);  React.useLayoutEffect(() => {    const h = host.current;    const s = scene.current;    if (!h || !s) return;    const fit = () => s.style.setProperty("transform", `scale(${h.clientWidth / W})`);    fit();    const ro = new ResizeObserver(fit);    ro.observe(h);    return () => ro.disconnect();  }, []);  return (    <div ref={host} aria-hidden="true" className="relative w-full" style={{ aspectRatio: `${W} / ${H}` }}>      <div ref={scene} className="absolute left-0 top-0 origin-top-left" style={{ width: W, height: H }}>        {children}      </div>    </div>  );}export default Storage;

Registry item: /r/storage.json