How much of a fixed amount is used, such as disk space. It turns amber, then red, near full.
- 1.7 kB JS 2.7 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Right-to-left
- 9 tests
CPU
Memory
Getting full. Restart the queue worker or move to a larger machine.
Disk
Almost full. Writes fail when it's full. Rotate the logs in /var/log.
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Meter } from "./ui/uicontext/components/Meter.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ wrap: { display: "grid", gap: space.xl, inlineSize: "min(100%, 26rem)" } })// a server's resources on its detail page: plenty left, getting full, almost outexport const ServerResources = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.wrap)).children( Meter(h, { key: "cpu", label: "CPU", value: 38 }), Meter(h, { key: "memory", label: "Memory", value: 13.1, max: 16, valueText: "13.1 of 16 GB", advice: "Restart the queue worker or move to a larger machine." }), Meter(h, { key: "disk", label: "Disk", value: 487, max: 500, valueText: "487 of 500 GB", advice: "Writes fail when it's full. Rotate the logs in /var/log." }), )When to use
How much of a fixed amount is used, such as disk space. It turns amber, then red, near full. Use Progress instead when the bar shows a task's progress.
Usage
import { Meter } from "./ui/uicontext/components/Meter.ts"export const Seats = <M>(h: Html.H<M>) => Meter(h, { label: "Seats", value: 31, max: 50, valueText: "31 of 50" })Examples
What uses it
MeterBreakdown splits the bar by part, with a legend that names each and what's free.
Storage
- Videos84.6 GB
- Photos41.3 GB
- Documents12.8 GB
- Other6.1 GB
- Free55.2 GB
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { MeterBreakdown } from "./ui/uicontext/components/Meter.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ wrap: { inlineSize: "min(100%, 30rem)" } })// a drive's storage by kind of fileexport const StorageBreakdown = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.wrap)).children( MeterBreakdown(h, { label: "Storage", max: 200, unit: "GB", parts: [ { label: "Videos", value: 84.6 }, { label: "Photos", value: 41.3 }, { label: "Documents", value: 12.8 }, { label: "Other", value: 6.1 }, ], }), )API reference
MeterView function
Options
| Name | Type | Default | Description |
|---|---|---|---|
key | string | — | Names the meter among others in the same view; needed for more than one. |
labelrequired | string | — | What's measured: "Disk", "Memory", "Battery". |
valuerequired | number | — | — |
max | number | 100 | 100 by default. |
valueText | string | — | The words beside the label and read out with it: "41.2 of 50 GB". A percentage by default. |
warn | number | 0.8 | The share, 0 to 1, where it turns amber; 0.8 by default. |
critical | number | 0.95 | The share where it turns red; 0.95 by default. |
advice | string | — | What to do about it, under the bar once it's past warn: "Delete old recordings or upgrade." |
thin | boolean | — | A thinner bar, for a row in a list. |
style | Style | — | — |
MeterBreakdownView function
Options
| Name | Type | Description |
|---|---|---|
key | string | Names the meter among others in the same view; needed for more than one. |
labelrequired | string | — |
partsrequired | MeterPart[] | What each part uses, largest first reads best; up to six. |
maxrequired | number | — |
unit | string | "GB", "seats": written after each number. |
locale | string | — |
style | Style | — |
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/meter