Size Context

Explains a file size with a comparison, transfer time and the GB/GiB equivalent, and checks it against an upload limit.

StopsUpload fails on GB vs GiB

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/size-context.json

The files land in your project. They're yours to edit.

Usage

size-context-usage.tsx
import { SizeContext } from "@/components/ui/size-context"

<SizeContext bytes={picked.bytes} limit="4 GB" bitsPerSecond={100e6} />

What it catches

  • Files over the limit
  • The ambiguous zone where a decimal-GB limit fits only if it means GiB
  • What Windows will display (1,024-based units labelled GB)
  • Estimated transfer time at a given speed
  • A relatable comparison for the size

Props

SizeContext props
PropTypeDefault
bytes* (required)

Exact size in bytes.

number—
system

Unit system for the headline. The other system is one tap away.

UnitSystem"si"
limit

Upload limit: bytes, or text like "4 GB" (treated as ambiguous) or "4 GiB" (exact).

number | string—
bitsPerSecond

Connection speed in bits per second. Without it, the browser's own estimate is used where available.

number—
platform

Override platform detection, which decides whether to say what Windows Explorer will show.

"windows" | "other"—
comparisons

Typical item sizes used for the comparison.

SizeComparison[]—
locale

Locale for number formatting.

string—
transferText

Templates: `{size}`, `{alt}`, `{limit}`, `{over}`, `{left}`, `{time}`, `{speed}`, `{binary}`, `{limitBinary}`, `{exact}` are filled in.

string"~{time} at {speed}"
windowsText

Says what Windows will show.

string"Windows shows this as {binary}."
explainText

Explanation of GB versus GiB.

string"Both mean the same {exact} bytes. GB counts in 1,000s (m…
overText

Shown when the file is over the limit.

string"Over the {limit} limit by {over}. Compress or split it b…
ambiguousText

Shown when it fits only if the limit means GiB.

string"Over {limit} if the limit counts in 1,000s, under it if …
fitsText

Shown when the file fits.

string"Fits: {left} under the {limit} limit."

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Exact byte count in a title tooltip
  • Explain toggle uses aria-expanded and aria-controls
  • Fit status in a polite live region; over-limit uses role=alert
  • Bar visual is aria-hidden

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

  • Transfer time is an estimate from bitsPerSecond
  • Cannot know which unit a third-party service really uses

What it stops

Upload fails on GB vs GiB

Also known as

file size · gb · gib · upload limit · bytes · storage · transfer time · mb

Field type

Dependencies

Pairs well with