Skip to content

Commit 3553065

Browse files
authored
feat(ProgressViewer): add custom threasholds to ProgressViewer (#540)
1 parent e7fa8fe commit 3553065

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/components/ProgressViewer/ProgressViewer.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Props description:
2727
4) percents - display progress in percents
2828
5) colorizeProgress - change the color of the progress bar depending on its value
2929
6) inverseColorize - invert the colors of the progress bar
30+
7) warningThreshold - the percentage of fullness at which the color of the progress bar changes to yellow
31+
8) dangerThreshold - the percentage of fullness at which the color of the progress bar changes to red
3032
*/
3133

3234
interface ProgressViewerProps {
@@ -38,6 +40,8 @@ interface ProgressViewerProps {
3840
size?: ProgressViewerSize;
3941
colorizeProgress?: boolean;
4042
inverseColorize?: boolean;
43+
warningThreshold?: number;
44+
dangerThreshold?: number;
4145
}
4246

4347
export function ProgressViewer({
@@ -49,10 +53,11 @@ export function ProgressViewer({
4953
size = PROGRESS_VIEWER_SIZE_IDS.xs,
5054
colorizeProgress,
5155
inverseColorize,
56+
warningThreshold = 60,
57+
dangerThreshold = 80,
5258
}: ProgressViewerProps) {
5359
let fillWidth = Math.round((parseFloat(String(value)) / parseFloat(String(capacity))) * 100);
5460
fillWidth = fillWidth > 100 ? 100 : fillWidth;
55-
5661
let valueText: number | string | undefined = Math.round(Number(value)),
5762
capacityText: number | string | undefined = capacity,
5863
divider = '/';
@@ -66,9 +71,9 @@ export function ProgressViewer({
6671

6772
let bg = inverseColorize ? 'scarlet' : 'apple';
6873
if (colorizeProgress) {
69-
if (fillWidth > 60 && fillWidth <= 80) {
74+
if (fillWidth > warningThreshold && fillWidth <= dangerThreshold) {
7075
bg = 'saffron';
71-
} else if (fillWidth > 80) {
76+
} else if (fillWidth > dangerThreshold) {
7277
bg = inverseColorize ? 'apple' : 'scarlet';
7378
}
7479
}

0 commit comments

Comments
 (0)