2026-04-09 21:56:33 +02:00
|
|
|
import styles from '../styles/platform.module.css';
|
|
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
used: number;
|
|
|
|
|
limit: number;
|
|
|
|
|
label: string;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-26 22:12:33 +02:00
|
|
|
function barColor(pct: number): string {
|
|
|
|
|
if (pct >= 100) return 'var(--error)';
|
|
|
|
|
if (pct >= 75) return 'var(--warning)';
|
|
|
|
|
return 'var(--success)';
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-09 21:56:33 +02:00
|
|
|
export function UsageIndicator({ used, limit, label }: Props) {
|
|
|
|
|
const unlimited = limit < 0;
|
2026-04-26 22:12:33 +02:00
|
|
|
const pct = unlimited ? 0 : limit === 0 ? 100 : Math.min((used / limit) * 100, 100);
|
2026-04-09 21:56:33 +02:00
|
|
|
|
|
|
|
|
return (
|
2026-04-26 22:12:33 +02:00
|
|
|
<div className={styles.usageRow}>
|
|
|
|
|
<div className={styles.usageHeader}>
|
|
|
|
|
<span className={styles.usageLabel}>{label}</span>
|
|
|
|
|
<span className={styles.usageValue} style={pct >= 100 ? { color: 'var(--error)', fontWeight: 600 } : undefined}>
|
|
|
|
|
{used.toLocaleString()}{' / '}{unlimited ? '\u221e' : limit.toLocaleString()}
|
|
|
|
|
</span>
|
2026-04-09 21:56:33 +02:00
|
|
|
</div>
|
|
|
|
|
{!unlimited && (
|
2026-04-26 22:12:33 +02:00
|
|
|
<div className={styles.usageBarTrack}>
|
|
|
|
|
<div
|
|
|
|
|
className={styles.usageBarFill}
|
|
|
|
|
style={{ width: `${Math.max(pct, 2)}%`, background: barColor(pct) }}
|
|
|
|
|
/>
|
2026-04-09 21:56:33 +02:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|