Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions src/components/ProgressViewer/ProgressViewer.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@import '../../styles/mixins.scss';

.progress-viewer {
$block: &;

position: relative;
z-index: 0;

Expand All @@ -16,37 +18,51 @@
font-size: var(--g-text-body-2-font-size);
white-space: nowrap;

color: var(--g-color-text-light-primary);
color: var(--g-color-text-complementary);
border-radius: 2px;
background: var(--g-color-base-generic);

&_theme_dark {
color: var(--g-color-text-light-primary);

// Ensure better contrast with text
#{$block}__line {
opacity: 0.75;
}
}

&_status {
&_good {
background-color: var(--g-color-base-positive-light);
#{$block}__line {
background-color: var(--ydb-color-status-green);
}
}
&_warning {
background-color: var(--g-color-base-yellow-light);
#{$block}__line {
background-color: var(--ydb-color-status-yellow);
}
}
&_danger {
background-color: var(--g-color-base-danger-light);
#{$block}__line {
background-color: var(--ydb-color-status-red);
}
}
}

&__line {
position: absolute;
top: 0;
left: 0;

height: 100%;

&_bg_scarlet {
background: var(--ydb-color-status-red);
}
&_bg_apple {
background: var(--ydb-color-status-green);
}
&_bg_saffron {
background: var(--ydb-color-status-yellow);
}
}

&__text {
position: relative;
z-index: 1;
&_text_contrast0 {
color: var(--g-color-text-light-primary);
}
&_text_contrast70 {
color: var(--g-color-text-complementary);
}
}

&_size_xs {
Expand Down
17 changes: 9 additions & 8 deletions src/components/ProgressViewer/ProgressViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cn from 'bem-cn-lite';
import {useTheme} from '@gravity-ui/uikit';

import type {ValueOf} from '../../types/common';
import {isNumeric} from '../../utils/utils';
Expand Down Expand Up @@ -66,6 +67,8 @@ export function ProgressViewer({
warningThreshold = 60,
dangerThreshold = 80,
}: ProgressViewerProps) {
const theme = useTheme();

let fillWidth =
Math.round((parseFloat(String(value)) / parseFloat(String(capacity))) * 100) || 0;
fillWidth = fillWidth > 100 ? 100 : fillWidth;
Expand All @@ -80,21 +83,19 @@ export function ProgressViewer({
[valueText, capacityText] = formatValues(Number(value), Number(capacity));
}

let bg = inverseColorize ? 'scarlet' : 'apple';
let status = inverseColorize ? 'danger' : 'good';
if (colorizeProgress) {
if (fillWidth > warningThreshold && fillWidth <= dangerThreshold) {
bg = 'saffron';
status = 'warning';
} else if (fillWidth > dangerThreshold) {
bg = inverseColorize ? 'apple' : 'scarlet';
status = inverseColorize ? 'good' : 'danger';
}
}

const lineStyle = {
width: fillWidth + '%',
};

const text = fillWidth > 60 ? 'contrast0' : 'contrast70';

const renderContent = () => {
if (isNumeric(capacity)) {
return `${valueText} ${divider} ${capacityText}`;
Expand All @@ -105,9 +106,9 @@ export function ProgressViewer({

if (isNumeric(value)) {
return (
<div className={b({size}, className)}>
<div className={b('line', {bg})} style={lineStyle}></div>
<span className={b('text', {text})}>{renderContent()}</span>
<div className={b({size, theme, status}, className)}>
<div className={b('line')} style={lineStyle}></div>
<span className={b('text')}>{renderContent()}</span>
</div>
);
}
Expand Down