import { fmtBytes } from '../lib/api'; interface Props { label: string; used: number; total: number; // Optional split: a portion of `used` that's "pinned" (won't be // evicted). Rendered green; the rest of used is amber. pinned?: number | null; } /// Big horizontal storage bar. Read-only. Renders green (pinned, /// safe) + amber (used, evictable) + slate (free). Health color /// on the label based on fill %. export function StorageBar({ label, used, total, pinned }: Props) { const safeTotal = Math.max(total, 1); const pct = Math.min(100, Math.round((used / safeTotal) * 100)); const pinnedPct = pinned ? Math.min(100, Math.round((pinned / safeTotal) * 100)) : 0; const evictablePct = Math.max(0, pct - pinnedPct); const bar = pct < 60 ? 'ok' : pct < 85 ? 'warn' : 'err'; const barText = { ok: 'text-emerald-300', warn: 'text-amber-300', err: 'text-red-300', }[bar]; return (
{label} {fmtBytes(used)} / {fmtBytes(total)} ยท {pct}%
{pinnedPct > 0 && (
)} {evictablePct > 0 && (
)}
); }