Size Context

Size Context is a copy-paste React component that stops upload fails on gb vs gib before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/size-context
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 1 extra npm package
  • A11y guidance in docs

StopsUpload fails on GB vs GiB

Was this component page useful?

How do I install Size Context?

pnpm dlx shadcn@latest add @bollard/size-context

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

How do I use Size Context in React?

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

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

What input mistakes does Size Context catch?

  • 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

What props does Size Context accept?

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.

How is Size Context accessible?

  • 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.

What are the limitations and server boundaries?

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

What expensive mistakes does Size Context stop?

Upload fails on GB vs GiB

Also known as

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

Field type

What dependencies does Size Context require?

Size Context facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameSize Context
Registry identifier@bollard/size-context
Install commandnpx shadcn@latest add @bollard/size-context
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-10-16
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about Size Context

What form validation mistake does Size Context catch?

Size Context prevents upload fails on GB vs GiB. Explains a file size with a comparison, transfer time and the GB/GiB equivalent, and checks it against an upload limit. 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. Limitation: validate size-context schemas on backend.

How do I install size-context with shadcn?

Run `npx shadcn@latest add @bollard/size-context`. Sources added: registry/default/size-context/size-context.tsx. Package requirements: lucide-react.

What props customize Size Context?

Size Context accepts `bytes`, `system`, `limit`, `bitsPerSecond`, `platform`. Configures file size, gb, gib behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of size-context?

Transfer time is an estimate from bitsPerSecond. Cannot know which unit a third-party service really uses Server requirement: backend verification for size-context.

How does Size Context meet accessibility guidelines?

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. Minimizes errors: file too large upload, gb vs gib.

Which components pair with Size Context?