@beydesign/storybook 0.0.77 → 0.0.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,18 +5,13 @@ import { Typography, TypographySize, TypographyWeight } from '../Typography';
|
|
|
5
5
|
export const ProgressIndicator = ({ mode = ProgressIndicatorMode.Value, currentValue = 40, maxValue = 100, fillColor = 'var(--colors-light-background-bg-brand)', backgroundColor = 'var(--colors-light-background-bg-white)', text = 'used', textColor = 'var(--colors-light-text-text-primary)', style, }) => {
|
|
6
6
|
let errorText = '';
|
|
7
7
|
const calculateFill = () => {
|
|
8
|
-
|
|
9
|
-
return (currentValue / maxValue) * 100;
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
return currentValue;
|
|
13
|
-
}
|
|
8
|
+
return (currentValue / maxValue) * 100;
|
|
14
9
|
};
|
|
15
|
-
if (!
|
|
16
|
-
errorText = 'Current value must be
|
|
10
|
+
if (isNaN(currentValue) || !isFinite(currentValue)) {
|
|
11
|
+
errorText = 'Current value must be a valid number';
|
|
17
12
|
}
|
|
18
|
-
else if (!
|
|
19
|
-
errorText = 'Max value must be
|
|
13
|
+
else if (isNaN(maxValue) || !isFinite(maxValue)) {
|
|
14
|
+
errorText = 'Max value must be a valid number';
|
|
20
15
|
}
|
|
21
16
|
else if (currentValue < 0) {
|
|
22
17
|
errorText = 'Invalid current value';
|
|
@@ -32,5 +27,5 @@ export const ProgressIndicator = ({ mode = ProgressIndicatorMode.Value, currentV
|
|
|
32
27
|
if (errorText) {
|
|
33
28
|
return (_jsx(Typography, { text: errorText, size: TypographySize.TextXS, weight: TypographyWeight.Regular }));
|
|
34
29
|
}
|
|
35
|
-
return (_jsxs(Box, { display: "flex", flexDirection: mode === ProgressIndicatorMode.Value ? 'column' : 'row', justifyContent: 'space-between', alignItems: mode === ProgressIndicatorMode.Value ? 'flex-end' : 'center', gap: 'var(--spacing-tokens-size-in-px-spacing-spacing-md)', sx: style, minWidth: 200, children: [mode === ProgressIndicatorMode.Value && (_jsx(Typography, { text: `${currentValue} / ${maxValue} ${text}`, size: TypographySize.TextXS, weight: TypographyWeight.Regular, color: textColor })), _jsx(Box, { display: "flex", flexGrow: 1, flexDirection: "row", alignItems: "center", borderRadius: '4px', sx: { backgroundColor, overflow: 'hidden' }, height: '4px', width: '100%', children: _jsx(Box, { height: '100%', borderRadius: '4px', sx: { backgroundColor: fillColor, width: `${calculateFill()}%` } }) }), mode === ProgressIndicatorMode.Percentage && (_jsx(Typography, { text: `${currentValue}%`, size: TypographySize.TextXS, weight: TypographyWeight.Regular, color: textColor }))] }));
|
|
30
|
+
return (_jsxs(Box, { display: "flex", flexDirection: mode === ProgressIndicatorMode.Value ? 'column' : 'row', justifyContent: 'space-between', alignItems: mode === ProgressIndicatorMode.Value ? 'flex-end' : 'center', gap: 'var(--spacing-tokens-size-in-px-spacing-spacing-md)', sx: style, minWidth: 200, children: [mode === ProgressIndicatorMode.Value && (_jsx(Typography, { text: `${currentValue.toLocaleString(undefined, { maximumFractionDigits: 2 })} / ${maxValue.toLocaleString(undefined, { maximumFractionDigits: 2 })} ${text}`, size: TypographySize.TextXS, weight: TypographyWeight.Regular, color: textColor })), _jsx(Box, { display: "flex", flexGrow: 1, flexDirection: "row", alignItems: "center", borderRadius: '4px', sx: { backgroundColor, overflow: 'hidden' }, height: '4px', width: '100%', children: _jsx(Box, { height: '100%', borderRadius: '4px', sx: { backgroundColor: fillColor, width: `${calculateFill()}%` } }) }), mode === ProgressIndicatorMode.Percentage && (_jsx(Typography, { text: `${currentValue.toLocaleString(undefined, { maximumFractionDigits: 2 })}%`, size: TypographySize.TextXS, weight: TypographyWeight.Regular, color: textColor }))] }));
|
|
36
31
|
};
|