-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathprogress.ts
29 lines (26 loc) · 918 Bytes
/
progress.ts
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
import {DEFAULT_DANGER_THRESHOLD, DEFAULT_WARNING_THRESHOLD} from './constants';
export type ProgressStatus = 'good' | 'warning' | 'danger';
interface CalculateProgressStatusProps {
inverseColorize?: boolean;
dangerThreshold?: number;
warningThreshold?: number;
colorizeProgress?: boolean;
fillWidth: number;
}
export function calculateProgressStatus({
inverseColorize,
warningThreshold = DEFAULT_WARNING_THRESHOLD,
dangerThreshold = DEFAULT_DANGER_THRESHOLD,
colorizeProgress,
fillWidth,
}: CalculateProgressStatusProps) {
let status: ProgressStatus = inverseColorize ? 'danger' : 'good';
if (colorizeProgress) {
if (fillWidth > warningThreshold && fillWidth <= dangerThreshold) {
status = 'warning';
} else if (fillWidth > dangerThreshold) {
status = inverseColorize ? 'good' : 'danger';
}
}
return status;
}