-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress.ts
More file actions
82 lines (73 loc) · 1.99 KB
/
Copy pathprogress.ts
File metadata and controls
82 lines (73 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
export type ProgressColorState = 'success' | 'warning' | 'danger';
/**
* Get color state based on remaining percentage
* @param value Used percentage
* @returns Color state
*/
export function getProgressColorState(value: number): ProgressColorState {
const remaining = 100 - value;
if (remaining <= 10) return 'danger';
if (remaining <= 30) return 'warning';
return 'success';
}
/**
* Get stroke color class based on color state
*/
export function getStrokeColorClass(state: ProgressColorState): string {
switch (state) {
case 'danger':
return 'stroke-rose-500';
case 'warning':
return 'stroke-amber-500';
case 'success':
return 'stroke-emerald-500';
}
}
/**
* Get text color class based on color state
*/
export function getTextColorClass(state: ProgressColorState): string {
switch (state) {
case 'danger':
return 'text-rose-400';
case 'warning':
return 'text-amber-400';
case 'success':
return 'text-emerald-400';
}
}
/**
* Get background color class based on color state
*/
export function getBgColorClass(state: ProgressColorState): string {
switch (state) {
case 'danger':
return 'bg-rose-500';
case 'warning':
return 'bg-amber-500';
case 'success':
return 'bg-emerald-500';
}
}
/**
* Format relative time (e.g., "in 2h 15m" or "in 3d")
*/
export function formatRelativeTime(timestamp: number | null | undefined, nowMs = Date.now()): string {
if (!timestamp) return '';
const diffMs = (timestamp * 1000) - nowMs; // resets_at is usually in seconds
if (diffMs <= 0) return 'Resetting...';
const diffSec = Math.floor(diffMs / 1000);
const diffMin = Math.floor(diffSec / 60);
const diffHour = Math.floor(diffMin / 60);
const diffDay = Math.floor(diffHour / 24);
if (diffDay > 0) {
return `in ${diffDay}d ${diffHour % 24}h`;
}
if (diffHour > 0) {
return `in ${diffHour}h ${diffMin % 60}m`;
}
if (diffMin > 0) {
return `in ${diffMin}m`;
}
return 'in < 1m';
}