@cloud-ru/ds-uikit-product-load-status 1.0.0
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.
- package/CHANGELOG.md +8 -0
- package/LICENSE +201 -0
- package/README.md +155 -0
- package/dist/cjs/components/LoadStatus/LoadStatus.d.ts +41 -0
- package/dist/cjs/components/LoadStatus/LoadStatus.js +24 -0
- package/dist/cjs/components/LoadStatus/index.d.ts +1 -0
- package/dist/cjs/components/LoadStatus/index.js +17 -0
- package/dist/cjs/components/LoadStatus/styles.module.css +63 -0
- package/dist/cjs/components/index.d.ts +3 -0
- package/dist/cjs/components/index.js +19 -0
- package/dist/cjs/components/types.d.ts +16 -0
- package/dist/cjs/components/types.js +2 -0
- package/dist/cjs/components/utils/getProgressBarColor.d.ts +3 -0
- package/dist/cjs/components/utils/getProgressBarColor.js +24 -0
- package/dist/cjs/components/utils/index.d.ts +1 -0
- package/dist/cjs/components/utils/index.js +17 -0
- package/dist/cjs/constants.d.ts +30 -0
- package/dist/cjs/constants.js +25 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +10 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/style.css +63 -0
- package/dist/esm/components/LoadStatus/LoadStatus.d.ts +41 -0
- package/dist/esm/components/LoadStatus/LoadStatus.js +18 -0
- package/dist/esm/components/LoadStatus/index.d.ts +1 -0
- package/dist/esm/components/LoadStatus/index.js +1 -0
- package/dist/esm/components/LoadStatus/styles.module.css +63 -0
- package/dist/esm/components/index.d.ts +3 -0
- package/dist/esm/components/index.js +3 -0
- package/dist/esm/components/types.d.ts +16 -0
- package/dist/esm/components/types.js +1 -0
- package/dist/esm/components/utils/getProgressBarColor.d.ts +3 -0
- package/dist/esm/components/utils/getProgressBarColor.js +20 -0
- package/dist/esm/components/utils/index.d.ts +1 -0
- package/dist/esm/components/utils/index.js +1 -0
- package/dist/esm/constants.d.ts +30 -0
- package/dist/esm/constants.js +22 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/style.css +63 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +45 -0
- package/src/components/LoadStatus/LoadStatus.tsx +94 -0
- package/src/components/LoadStatus/index.ts +1 -0
- package/src/components/LoadStatus/styles.module.scss +53 -0
- package/src/components/index.ts +3 -0
- package/src/components/types.ts +20 -0
- package/src/components/utils/getProgressBarColor.ts +28 -0
- package/src/components/utils/index.ts +1 -0
- package/src/constants.ts +27 -0
- package/src/index.ts +4 -0
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cloud-ru/ds-uikit-product-load-status",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Строка статуса загрузки с линейным progress bar, заголовком и подсказкой — по макету Figma loadStatus.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/cloud-ru-tech/snack-v2.git",
|
|
8
|
+
"directory": "packages/uikit-product-load-status"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/cloud-ru-tech/snack-v2/tree/master/packages/uikit-product-load-status",
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"author": "Артемий Зимин <aazimin@cloud.ru>",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "./dist/cjs/index.js",
|
|
15
|
+
"module": "./dist/esm/index.js",
|
|
16
|
+
"types": "./dist/esm/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"source": "./src/index.ts",
|
|
20
|
+
"types": "./dist/esm/index.d.ts",
|
|
21
|
+
"import": "./dist/esm/index.js",
|
|
22
|
+
"require": "./dist/cjs/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"src",
|
|
28
|
+
"./CHANGELOG.md",
|
|
29
|
+
"./LICENSE"
|
|
30
|
+
],
|
|
31
|
+
"sideEffects": [
|
|
32
|
+
"*.css",
|
|
33
|
+
"**/*.css"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"classnames": "^2.5.1",
|
|
37
|
+
"@cloud-ru/ds-icons": "^1.0.0",
|
|
38
|
+
"@cloud-ru/ds-typography": "^1.0.0",
|
|
39
|
+
"@cloud-ru/ds-utils": "^1.0.0",
|
|
40
|
+
"@cloud-ru/ds-progress-bar": "^1.0.0"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { NotifierCriticalFilledSVG } from '@cloud-ru/ds-icons/interface/system';
|
|
2
|
+
import { APPEARANCE, PROGRESS_BAR_SIZE, ProgressBar, ProgressBarProps } from '@cloud-ru/ds-progress-bar';
|
|
3
|
+
import { SIZE, Typography, VARIANT, WEIGHT } from '@cloud-ru/ds-typography';
|
|
4
|
+
import { extractSupportProps, WithSupportProps } from '@cloud-ru/ds-utils';
|
|
5
|
+
import cn from 'classnames';
|
|
6
|
+
import { forwardRef } from 'react';
|
|
7
|
+
|
|
8
|
+
import { DEFAULT_APPEARANCE_BY_PROGRESS, SYMBOL_BY_TYPE, TEST_IDS } from '../../constants';
|
|
9
|
+
import { LoadValueType, ProgressLimitList } from '../types';
|
|
10
|
+
import { getProgressBarColor } from '../utils';
|
|
11
|
+
import styles from './styles.module.scss';
|
|
12
|
+
|
|
13
|
+
export type LoadStatusProps = WithSupportProps<
|
|
14
|
+
{
|
|
15
|
+
/** Заголовок строки загрузки */
|
|
16
|
+
label?: string;
|
|
17
|
+
/** Дополнительный текст в заголовке (рядом с label) */
|
|
18
|
+
value?: string;
|
|
19
|
+
/** Подсказка под полосой прогресса */
|
|
20
|
+
hint?: string;
|
|
21
|
+
/** Формат значения в заголовке: без процента (`none`) или с процентом (`percent`) */
|
|
22
|
+
valueType?: LoadValueType;
|
|
23
|
+
/** Правила смены цвета полосы в зависимости от `progress`; при `showError` игнорируются */
|
|
24
|
+
appearanceByProgress?: ProgressLimitList;
|
|
25
|
+
/** Ошибка: полоса `red` */
|
|
26
|
+
showError?: boolean;
|
|
27
|
+
/** Иконка в hint; показывается при `hint` и вместе с `showError` */
|
|
28
|
+
showErrorIcon?: boolean;
|
|
29
|
+
/** CSS-класс корневого элемента */
|
|
30
|
+
className?: string;
|
|
31
|
+
} & Pick<ProgressBarProps, 'progress' | 'size'>
|
|
32
|
+
>;
|
|
33
|
+
|
|
34
|
+
export const LoadStatus = forwardRef<HTMLDivElement, LoadStatusProps>(function LoadStatus(
|
|
35
|
+
{
|
|
36
|
+
label,
|
|
37
|
+
value,
|
|
38
|
+
hint,
|
|
39
|
+
valueType = 'none',
|
|
40
|
+
progress,
|
|
41
|
+
size = PROGRESS_BAR_SIZE.S,
|
|
42
|
+
appearanceByProgress = DEFAULT_APPEARANCE_BY_PROGRESS,
|
|
43
|
+
showError,
|
|
44
|
+
showErrorIcon,
|
|
45
|
+
className,
|
|
46
|
+
...props
|
|
47
|
+
},
|
|
48
|
+
ref,
|
|
49
|
+
) {
|
|
50
|
+
const progressAppearance = showError ? APPEARANCE.Red : getProgressBarColor(progress, appearanceByProgress);
|
|
51
|
+
const isShowHeader = Boolean(label || value || valueType !== 'none');
|
|
52
|
+
const resolvedValueType: LoadValueType = valueType;
|
|
53
|
+
const symbol = SYMBOL_BY_TYPE[resolvedValueType];
|
|
54
|
+
|
|
55
|
+
const progressSymbolValue = !symbol ? progress : `${progress}${symbol}`;
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<div
|
|
59
|
+
className={cn(styles.loadStatus, className)}
|
|
60
|
+
ref={ref}
|
|
61
|
+
data-test-id={TEST_IDS.root}
|
|
62
|
+
{...extractSupportProps(props)}
|
|
63
|
+
>
|
|
64
|
+
{isShowHeader && (
|
|
65
|
+
<div className={styles.header} data-test-id={TEST_IDS.header}>
|
|
66
|
+
<Typography className={styles.labelRow} variant={VARIANT.body} size={SIZE.m} weight={WEIGHT.regular}>
|
|
67
|
+
{label}
|
|
68
|
+
|
|
69
|
+
{value && <span className={styles.labelValue}>{value}</span>}
|
|
70
|
+
</Typography>
|
|
71
|
+
|
|
72
|
+
{symbol && (
|
|
73
|
+
<Typography className={styles.valueSymbol} variant={VARIANT.body} size={SIZE.m} weight={WEIGHT.regular}>
|
|
74
|
+
{progressSymbolValue}
|
|
75
|
+
</Typography>
|
|
76
|
+
)}
|
|
77
|
+
</div>
|
|
78
|
+
)}
|
|
79
|
+
<ProgressBar progress={progress} size={size} appearance={progressAppearance} />
|
|
80
|
+
|
|
81
|
+
{hint && (
|
|
82
|
+
<div className={styles.hintWrapper} data-test-id={TEST_IDS.hint}>
|
|
83
|
+
{showErrorIcon && (
|
|
84
|
+
<NotifierCriticalFilledSVG className={styles.errorIcon} size={16} data-test-id={TEST_IDS.errorIcon} />
|
|
85
|
+
)}
|
|
86
|
+
|
|
87
|
+
<Typography className={styles.hint} variant={VARIANT.body} size={SIZE.m} weight={WEIGHT.regular}>
|
|
88
|
+
{hint}
|
|
89
|
+
</Typography>
|
|
90
|
+
</div>
|
|
91
|
+
)}
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './LoadStatus';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
@use '@cloud-ru/ds-figma-variables/build/scss/styles/styles.module' as base;
|
|
2
|
+
|
|
3
|
+
.loadStatus {
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
gap: base.$sn-primitive-dimension-4;
|
|
7
|
+
width: 100%;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.header {
|
|
11
|
+
display: flex;
|
|
12
|
+
gap: base.$sn-primitive-dimension-4;
|
|
13
|
+
align-items: flex-start;
|
|
14
|
+
justify-content: space-between;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.labelRow {
|
|
18
|
+
@include base.composite-var(base.$sn-regular-body-m);
|
|
19
|
+
|
|
20
|
+
margin: 0;
|
|
21
|
+
color: base.$sn-theme-color-available-version-textMain;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.labelValue {
|
|
25
|
+
margin-left: base.$sn-primitive-dimension-4;
|
|
26
|
+
color: base.$sn-theme-color-available-version-textTertiary;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.valueSymbol {
|
|
30
|
+
@include base.composite-var(base.$sn-regular-body-m);
|
|
31
|
+
|
|
32
|
+
flex-shrink: 0;
|
|
33
|
+
margin: 0;
|
|
34
|
+
color: base.$sn-theme-color-available-version-textTertiary;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.hintWrapper {
|
|
38
|
+
display: flex;
|
|
39
|
+
gap: base.$sn-primitive-dimension-2;
|
|
40
|
+
align-items: center;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.errorIcon {
|
|
44
|
+
flex-shrink: 0;
|
|
45
|
+
color: base.$sn-theme-color-red-accent;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.hint {
|
|
49
|
+
@include base.composite-var(base.$sn-regular-body-m);
|
|
50
|
+
|
|
51
|
+
margin: 0;
|
|
52
|
+
color: base.$sn-theme-color-available-version-textTertiary;
|
|
53
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Appearance } from '@cloud-ru/ds-progress-bar';
|
|
2
|
+
import { ValueOf } from '@cloud-ru/ds-utils';
|
|
3
|
+
|
|
4
|
+
import { PROGRESS_LIMIT_CONDITION } from '../constants';
|
|
5
|
+
|
|
6
|
+
export type LoadValueType = 'none' | 'percent';
|
|
7
|
+
|
|
8
|
+
export type ProgressLimitCondition = ValueOf<typeof PROGRESS_LIMIT_CONDITION>;
|
|
9
|
+
|
|
10
|
+
/** Порог смены цвета полосы прогресса */
|
|
11
|
+
type ProgressLimit = {
|
|
12
|
+
/** Условие сравнения `progress` с `limit` */
|
|
13
|
+
condition: ProgressLimitCondition;
|
|
14
|
+
/** Пороговое значение progress (обычно 0–100) */
|
|
15
|
+
limit: number;
|
|
16
|
+
/** Цвет полосы при выполнении условия */
|
|
17
|
+
appearance: Appearance;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type ProgressLimitList = ProgressLimit[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { APPEARANCE, Appearance } from '@cloud-ru/ds-progress-bar';
|
|
2
|
+
|
|
3
|
+
import { PROGRESS_LIMIT_CONDITION } from '../../constants';
|
|
4
|
+
import { ProgressLimitCondition, ProgressLimitList } from '../types';
|
|
5
|
+
|
|
6
|
+
type ProgressLimitMatcher = (progress: number, limit: number) => boolean;
|
|
7
|
+
|
|
8
|
+
const PROGRESS_LIMIT_MATCHERS = {
|
|
9
|
+
[PROGRESS_LIMIT_CONDITION.Eq]: (progress, limit) => progress === limit,
|
|
10
|
+
[PROGRESS_LIMIT_CONDITION.Gt]: (progress, limit) => progress > limit,
|
|
11
|
+
[PROGRESS_LIMIT_CONDITION.Gte]: (progress, limit) => progress >= limit,
|
|
12
|
+
[PROGRESS_LIMIT_CONDITION.Lt]: (progress, limit) => progress < limit,
|
|
13
|
+
[PROGRESS_LIMIT_CONDITION.Lte]: (progress, limit) => progress <= limit,
|
|
14
|
+
} satisfies Record<ProgressLimitCondition, ProgressLimitMatcher>;
|
|
15
|
+
|
|
16
|
+
export const getProgressBarColor = (progress: number, limits: ProgressLimitList): Appearance => {
|
|
17
|
+
for (const limit of limits) {
|
|
18
|
+
if (!(limit.condition in PROGRESS_LIMIT_MATCHERS)) {
|
|
19
|
+
return APPEARANCE.Neutral;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (PROGRESS_LIMIT_MATCHERS[limit.condition](progress, limit.limit)) {
|
|
23
|
+
return limit.appearance;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return APPEARANCE.Neutral;
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './getProgressBarColor';
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ProgressLimitList } from './components/types';
|
|
2
|
+
|
|
3
|
+
export const PROGRESS_LIMIT_CONDITION = {
|
|
4
|
+
Eq: 'eq',
|
|
5
|
+
Gt: 'gt',
|
|
6
|
+
Gte: 'gte',
|
|
7
|
+
Lt: 'lt',
|
|
8
|
+
Lte: 'lte',
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
export const DEFAULT_APPEARANCE_BY_PROGRESS = [
|
|
12
|
+
{ appearance: 'green', condition: PROGRESS_LIMIT_CONDITION.Lte, limit: 70 },
|
|
13
|
+
{ appearance: 'yellow', condition: PROGRESS_LIMIT_CONDITION.Lte, limit: 90 },
|
|
14
|
+
{ appearance: 'red', condition: PROGRESS_LIMIT_CONDITION.Lte, limit: 100 },
|
|
15
|
+
] satisfies ProgressLimitList;
|
|
16
|
+
|
|
17
|
+
export const SYMBOL_BY_TYPE = {
|
|
18
|
+
none: '',
|
|
19
|
+
percent: '%',
|
|
20
|
+
} as const;
|
|
21
|
+
|
|
22
|
+
export const TEST_IDS = {
|
|
23
|
+
root: 'load-status',
|
|
24
|
+
header: 'load-status__header',
|
|
25
|
+
hint: 'load-status__hint',
|
|
26
|
+
errorIcon: 'load-status__error-icon',
|
|
27
|
+
} as const;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { LoadStatus } from './components/LoadStatus';
|
|
2
|
+
export type { LoadStatusProps } from './components/LoadStatus';
|
|
3
|
+
export type { LoadValueType, ProgressLimitCondition, ProgressLimitList } from './components/types';
|
|
4
|
+
export { DEFAULT_APPEARANCE_BY_PROGRESS, PROGRESS_LIMIT_CONDITION, SYMBOL_BY_TYPE, TEST_IDS } from './constants';
|