tobogganSe connecter

starfleet-ui

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

37 lignes · 1154 octetsBrut · Historique
1<script lang="ts">
2 interface Props {
3 label: string;
4 value: number;
5 max: number;
6 tone?: 'cyan' | 'amber' | 'health';
7 /** Compact bar without the numbers row. */
8 bare?: boolean;
9 }
10
11 let { label, value, max, tone = 'cyan', bare = false }: Props = $props();
12
13 const pct = $derived(max > 0 ? Math.max(0, Math.min(100, (value / max) * 100)) : 0);
14 const bar = $derived(
15 tone === 'cyan'
16 ? 'bg-cyan-400'
17 : tone === 'amber'
18 ? 'bg-amber-400'
19 : pct > 50
20 ? 'bg-emerald-400'
21 : pct > 25
22 ? 'bg-amber-400'
23 : 'bg-red-500'
24 );
25</script>
26
27<div role="meter" aria-label={label} aria-valuenow={value} aria-valuemin={0} aria-valuemax={max}>
28 {#if !bare}
29 <div class="mb-1 flex items-baseline justify-between text-[11px]">
30 <span class="tracking-wider text-slate-400 uppercase">{label}</span>
31 <span class="font-mono text-slate-200 tabular-nums">{value}<span class="text-slate-500">/{max}</span></span>
32 </div>
33 {/if}
34 <div class="overflow-hidden rounded-full bg-slate-800/80 {bare ? 'h-1' : 'h-1.5'}">
35 <div class="h-full rounded-full transition-[width] duration-500 {bar}" style="width: {pct}%"></div>
36 </div>
37</div>