Storage Usage

A quota and what is filling it. The bar is scaled to the quota, not to what is used, so free space reads as free space — a bar normalised to the total consumed is always full, which is backwards for a component answering “how much room is left”.

src/components/ui/storage-usage.tsx

About

From the component's own source, where it was written.

A quota and what is filling it.

The bar is scaled to the **quota**, not to what is used, so free space reads as free space. A bar normalised to the total consumed is always full, which is exactly backwards for a component whose job is "how much room is left".

Segments below a pixel still get a sliver, for the reason every stacked bar in this kit does: "logs are tiny" and "there are no logs" must not render identically.

Over quota is a real state, not a clamped bar. Object stores keep accepting writes and bill for them, so a component that silently pins at 100% hides the one number someone is about to be charged for.

Install

npx astralyx-ui add storage-usage

Usage

import { StorageUsage } from '@/components/ui/storage-usage'

<StorageUsage segments={segments} quota={200 * 1024 ** 3} />

Composer

Change the props and the source below follows.

Storage

172 GB / 200 GB

  • Images39.1 GB
  • Video110 GB
  • Database backups22.4 GB
  • Logs858 MB
  • Free27.8 GB
Props
tsx
<StorageUsage segments={segments} quota={200 * 1024 ** 3} />

Examples

Comfortable, and over quota

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

StorageUsage

A quota and what is filling it.

Extends Omit<ComponentProps<'div'>, 'children'>.

PropTypeDefaultDescription
segmentsStorageSegment[]required{ id, label, bytes, color? }. Omit the quota for an unmetered store and the bar scales to the total instead.
quotanumber—An object store keeps accepting writes and billing for them; pinning the bar at 100% hides the one number someone is about to be charged for.
warnAtnumber0.85Warn past this fraction of the quota.
labelReactNode'Storage'—
freeLabelstring'Free'—
overLabel(over: string) => ReactNode(over) => `${over} over quota`—
format(bytes: number) => stringformatBytes—

Functions

FunctionSignatureDescription
formatBytes(bytes: number) => string—

Types

StorageSegment

FieldTypeDescription
idstring—
labelReactNode—
bytesnumber—
color?string—

Behaviour

TopicDetailDescription
minimum segment2px“Logs are tiny” and “there are no logs” must not render identically.