Data display
UsageMeter
How much of a limit is in use. Above the limit line, the value shows in the warning color. hideLabel keeps the label for screen readers only, for a meter that is the value of a summary fact with its own visible label.
import { UsageMeter, type UsagePart } from "@percentsa/ui";Examples
CPU42 %
- Alert at 90 %
MemoryAbove limit93 %
- Alert at 90 %
Disk160 GB
- Used 120 GB
- Held 40 GB
Network61 %
From the last report
Storage
Storage35 %
Code
export function UsageMeterExample() {
const t = useT();
const ar = useLang() === "ar";
// The number with its unit is isolated, so it keeps its order inside an Arabic sentence.
const limit = { value: 90, label: ar ? <>تنبيه عند <bdi dir="ltr">90 %</bdi></> : "Alert at 90 %" };
return (
<div className="grid w-full max-w-md gap-5">
<UsageMeter label={t("CPU", "المعالج")} value={42} limit={limit} />
<UsageMeter label={t("Memory", "الذاكرة")} value={93} limit={limit} />
<UsageMeter
label={t("Disk", "القرص")}
value={null}
max={200}
format={(n) => `${n} GB`}
parts={[
{ label: t("Used", "مستخدم"), value: 120, tone: "used" },
{ label: t("Held", "محجوز"), value: 40, tone: "held" },
]}
/>
<UsageMeter label={t("Network", "الشبكة")} value={61} at={new Date(Date.now() - 3 * 3600_000)} stale />
{/* The fact has its own visible label, so the meter's label is for screen readers only. */}
<div className="grid grid-cols-[6rem_1fr] items-center gap-3 text-sm">
<span className="text-fg-3">{t("Storage", "التخزين")}</span>
<UsageMeter label={t("Storage", "التخزين")} value={35} hideLabel />
</div>
</div>
);
}