@alfalab/core-components-circular-progress-bar 3.6.7 → 3.7.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.
Files changed (104) hide show
  1. package/@alfalab/core-components-shared/package.json +26 -0
  2. package/Component.d.ts +36 -5
  3. package/Component.js +42 -7
  4. package/consts.d.ts +9 -1
  5. package/consts.js +11 -0
  6. package/cssm/Component.d.ts +36 -5
  7. package/cssm/Component.js +41 -6
  8. package/cssm/consts.d.ts +9 -1
  9. package/cssm/consts.js +11 -0
  10. package/cssm/index.d.ts +1 -0
  11. package/cssm/index.module.css +14 -1
  12. package/cssm/shared/index.d.ts +1 -0
  13. package/cssm/shared/index.js +9 -0
  14. package/cssm/types/component-size.d.ts +2 -0
  15. package/cssm/types/component-size.js +2 -0
  16. package/cssm/types/typography-color.d.ts +2 -0
  17. package/cssm/types/typography-color.js +2 -0
  18. package/cssm/use-timer.d.ts +2 -0
  19. package/cssm/use-timer.js +31 -0
  20. package/cssm/utils/get-circular-progress-bar-test-ids.d.ts +8 -0
  21. package/cssm/utils/get-circular-progress-bar-test-ids.js +17 -0
  22. package/cssm/utils/is-typography-color.d.ts +3 -0
  23. package/cssm/utils/is-typography-color.js +11 -0
  24. package/esm/Component.d.ts +36 -5
  25. package/esm/Component.js +43 -8
  26. package/esm/consts.d.ts +9 -1
  27. package/esm/consts.js +9 -1
  28. package/esm/index.css +63 -50
  29. package/esm/index.d.ts +1 -0
  30. package/esm/shared/index.d.ts +1 -0
  31. package/esm/shared/index.js +1 -0
  32. package/esm/types/component-size.d.ts +2 -0
  33. package/esm/types/component-size.js +1 -0
  34. package/esm/types/typography-color.d.ts +2 -0
  35. package/esm/types/typography-color.js +1 -0
  36. package/esm/use-timer.d.ts +2 -0
  37. package/esm/use-timer.js +27 -0
  38. package/esm/utils/get-circular-progress-bar-test-ids.d.ts +8 -0
  39. package/esm/utils/get-circular-progress-bar-test-ids.js +13 -0
  40. package/esm/utils/is-typography-color.d.ts +3 -0
  41. package/esm/utils/is-typography-color.js +7 -0
  42. package/index.css +63 -50
  43. package/index.d.ts +1 -0
  44. package/modern/Component.d.ts +36 -5
  45. package/modern/Component.js +49 -12
  46. package/modern/consts.d.ts +9 -1
  47. package/modern/consts.js +9 -1
  48. package/modern/index.css +63 -50
  49. package/modern/index.d.ts +1 -0
  50. package/modern/shared/index.d.ts +1 -0
  51. package/modern/shared/index.js +1 -0
  52. package/modern/types/component-size.d.ts +2 -0
  53. package/modern/types/component-size.js +1 -0
  54. package/modern/types/typography-color.d.ts +2 -0
  55. package/modern/types/typography-color.js +1 -0
  56. package/modern/use-timer.d.ts +2 -0
  57. package/modern/use-timer.js +24 -0
  58. package/modern/utils/get-circular-progress-bar-test-ids.d.ts +8 -0
  59. package/modern/utils/get-circular-progress-bar-test-ids.js +13 -0
  60. package/modern/utils/is-typography-color.d.ts +3 -0
  61. package/modern/utils/is-typography-color.js +5 -0
  62. package/moderncssm/Component.d.ts +36 -5
  63. package/moderncssm/Component.js +48 -11
  64. package/moderncssm/consts.d.ts +9 -1
  65. package/moderncssm/consts.js +9 -1
  66. package/moderncssm/index.d.ts +1 -0
  67. package/moderncssm/index.module.css +18 -0
  68. package/moderncssm/shared/index.d.ts +1 -0
  69. package/moderncssm/shared/index.js +1 -0
  70. package/moderncssm/types/component-size.d.ts +2 -0
  71. package/moderncssm/types/component-size.js +1 -0
  72. package/moderncssm/types/typography-color.d.ts +2 -0
  73. package/moderncssm/types/typography-color.js +1 -0
  74. package/moderncssm/use-timer.d.ts +2 -0
  75. package/moderncssm/use-timer.js +24 -0
  76. package/moderncssm/utils/get-circular-progress-bar-test-ids.d.ts +8 -0
  77. package/moderncssm/utils/get-circular-progress-bar-test-ids.js +13 -0
  78. package/moderncssm/utils/is-typography-color.d.ts +3 -0
  79. package/moderncssm/utils/is-typography-color.js +5 -0
  80. package/package.json +5 -4
  81. package/shared/index.d.ts +1 -0
  82. package/shared/index.js +9 -0
  83. package/shared/package.json +3 -0
  84. package/src/Component.tsx +111 -14
  85. package/src/consts.ts +10 -0
  86. package/src/index.module.css +18 -0
  87. package/src/index.ts +1 -0
  88. package/src/shared/index.ts +1 -0
  89. package/src/shared/package.json +3 -0
  90. package/src/types/component-size.ts +1 -0
  91. package/src/types/typography-color.ts +1 -0
  92. package/src/use-timer.ts +35 -0
  93. package/src/utils/get-circular-progress-bar-test-ids.ts +11 -0
  94. package/src/utils/is-typography-color.ts +5 -0
  95. package/types/component-size.d.ts +2 -0
  96. package/types/component-size.js +2 -0
  97. package/types/typography-color.d.ts +2 -0
  98. package/types/typography-color.js +2 -0
  99. package/use-timer.d.ts +2 -0
  100. package/use-timer.js +31 -0
  101. package/utils/get-circular-progress-bar-test-ids.d.ts +8 -0
  102. package/utils/get-circular-progress-bar-test-ids.js +17 -0
  103. package/utils/is-typography-color.d.ts +3 -0
  104. package/utils/is-typography-color.js +11 -0
@@ -0,0 +1,24 @@
1
+ import { useState, useEffect } from 'react';
2
+ import { noop } from '@alfalab/core-components-shared/moderncssm';
3
+
4
+ const MAX_PERSENT_VALUE = 100;
5
+ function makeTitle(time) {
6
+ return `${Math.trunc(time / 60)}:${`${time % 60}`.padStart(2, '0')}`;
7
+ }
8
+ function useTimer(time, active = true, counting, interval = 1000, step = 1) {
9
+ const [passedTime, setPassedTime] = useState(0);
10
+ const isCompleted = passedTime === time;
11
+ const persentValue = Math.trunc((passedTime / time) * MAX_PERSENT_VALUE);
12
+ useEffect(() => {
13
+ if (!active || isCompleted) {
14
+ return noop;
15
+ }
16
+ const timer = setInterval(() => {
17
+ setPassedTime((prevPassed) => prevPassed + step);
18
+ }, interval);
19
+ return () => clearInterval(timer);
20
+ }, [interval, isCompleted, active, step]);
21
+ return [persentValue, makeTitle(counting === 'backward' ? time - passedTime : passedTime)];
22
+ }
23
+
24
+ export { useTimer };
@@ -0,0 +1,8 @@
1
+ declare function getCircularProgressBarTestIds(dataTestId: string): {
2
+ progressBar: string;
3
+ title: string;
4
+ subtitle: string;
5
+ circleProgressBar: string;
6
+ circleProgressValue: string;
7
+ };
8
+ export { getCircularProgressBarTestIds };
@@ -0,0 +1,13 @@
1
+ import { getDataTestId } from '@alfalab/core-components-shared/moderncssm';
2
+
3
+ function getCircularProgressBarTestIds(dataTestId) {
4
+ return {
5
+ progressBar: dataTestId,
6
+ title: getDataTestId(dataTestId, 'title'),
7
+ subtitle: getDataTestId(dataTestId, 'subtitle'),
8
+ circleProgressBar: getDataTestId(dataTestId, 'circle-progress-bar'),
9
+ circleProgressValue: getDataTestId(dataTestId, 'circle-progress-value'),
10
+ };
11
+ }
12
+
13
+ export { getCircularProgressBarTestIds };
@@ -0,0 +1,3 @@
1
+ import { TypographyColor } from "../types/typography-color";
2
+ declare const isTypographyColor: (color: TypographyColor | string) => color is TypographyColor;
3
+ export { isTypographyColor };
@@ -0,0 +1,5 @@
1
+ import { TYPOGRAPHY_COLOR } from '../consts.js';
2
+
3
+ const isTypographyColor = (color) => TYPOGRAPHY_COLOR.includes(color);
4
+
5
+ export { isTypographyColor };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfalab/core-components-circular-progress-bar",
3
- "version": "3.6.7",
3
+ "version": "3.7.0",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -12,13 +12,14 @@
12
12
  },
13
13
  "sideEffects": false,
14
14
  "dependencies": {
15
- "@alfalab/core-components-typography": "^4.11.3",
15
+ "@alfalab/core-components-typography": "^4.11.4",
16
+ "@alfalab/core-components-shared": "^0.14.1",
16
17
  "classnames": "^2.5.1",
17
18
  "tslib": "^2.4.0"
18
19
  },
19
20
  "peerDependencies": {
20
21
  "react": "^16.9.0 || ^17.0.1 || ^18.0.0"
21
22
  },
22
- "themesVersion": "13.7.0",
23
- "varsVersion": "9.16.0"
23
+ "themesVersion": "13.7.1",
24
+ "varsVersion": "9.18.0"
24
25
  }
@@ -0,0 +1 @@
1
+ export { getCircularProgressBarTestIds } from "../utils/get-circular-progress-bar-test-ids";
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var utils_getCircularProgressBarTestIds = require('../utils/get-circular-progress-bar-test-ids.js');
6
+
7
+
8
+
9
+ exports.getCircularProgressBarTestIds = utils_getCircularProgressBarTestIds.getCircularProgressBarTestIds;
@@ -0,0 +1,3 @@
1
+ {
2
+ "module": "../esm/shared/index.js"
3
+ }
package/src/Component.tsx CHANGED
@@ -1,9 +1,17 @@
1
+ /* eslint-disable complexity */
1
2
  import React, { ElementType, ReactNode, useMemo } from 'react';
2
3
  import cn from 'classnames';
3
4
 
5
+ import { getDataTestId, isObject } from '@alfalab/core-components-shared';
4
6
  import { Text, TitleMobile } from '@alfalab/core-components-typography';
5
7
 
8
+ import { ComponentSize } from './types/component-size';
9
+ import { TypographyColor } from './types/typography-color';
10
+ import { isTypographyColor } from './utils/is-typography-color';
6
11
  import {
12
+ MAX_PROGRESS_VALUE,
13
+ MAX_TIMER_VALUE,
14
+ MIN_TIMER_VALUE,
7
15
  SIZE_TO_CLASSNAME_MAP,
8
16
  SIZES,
9
17
  STROKE,
@@ -11,16 +19,32 @@ import {
11
19
  VIEW_TEXT,
12
20
  VIEW_TITLE,
13
21
  } from './consts';
22
+ import { useTimer } from './use-timer';
14
23
 
15
24
  import styles from './index.module.css';
16
25
 
17
- export type TypographyColor = 'primary' | 'secondary' | 'tertiary' | 'positive' | 'negative';
18
-
19
26
  export type CircularProgressBarProps = {
20
27
  /**
21
28
  * Уровень прогресса, %
22
29
  */
23
- value: number;
30
+
31
+ value:
32
+ | number
33
+ | {
34
+ /**
35
+ * Время таймера в секундах
36
+ * Минимальное значение 0
37
+ * Максимальное значение 3600
38
+ */
39
+ timer: number;
40
+ /**
41
+ * Направлние отсчета таймера
42
+ * forward: считаем от 0 до указанного значения
43
+ * backward: считаем от указанного значения до 0
44
+ * @default backward
45
+ */
46
+ counting?: 'forward' | 'backward';
47
+ };
24
48
 
25
49
  /**
26
50
  * Дополнительный класс
@@ -37,6 +61,18 @@ export type CircularProgressBarProps = {
37
61
  */
38
62
  contentColor?: TypographyColor | string;
39
63
 
64
+ /**
65
+ * Цвет заголовка
66
+ * Приоритет выше чем у `contentColor`
67
+ */
68
+ titleColor?: TypographyColor | string;
69
+
70
+ /**
71
+ * Цвет подзаголовка
72
+ * Приоритет выше чем у `contentColor`
73
+ */
74
+ subtitleColor?: TypographyColor | string;
75
+
40
76
  /**
41
77
  * Дополнительный текст
42
78
  */
@@ -59,9 +95,10 @@ export type CircularProgressBarProps = {
59
95
 
60
96
  /**
61
97
  * Размер (xxl — 144×144px, xl — 128×128px, l — 80×80px, m — 64×64px, s — 48×48px, xs — 24×24px)
62
- * @description xs, s, m, l, xl, xxl deprecated, используйте вместо них 24, 48, 64 , 80, 128, 144 соответственно
98
+ * @description xs, s, m, l, xl, xxl deprecated, используйте вместо них 24, 48, 64, 80, 128, 144 соответственно
99
+ * @default 64
63
100
  */
64
- size?: 'xxl' | 'xl' | 'l' | 'm' | 's' | 'xs' | 24 | 48 | 64 | 80 | 128 | 144;
101
+ size?: ComponentSize;
65
102
 
66
103
  /**
67
104
  * Наличие желоба
@@ -134,18 +171,24 @@ export type CircularProgressBarProps = {
134
171
  * Цвет желоба
135
172
  */
136
173
  strokeColor?: string;
174
+
175
+ /**
176
+ * Направление заполнения круга
177
+ * @default desc
178
+ */
179
+ directionType?: 'asc' | 'desc';
137
180
  };
138
181
 
139
182
  /**
140
183
  * Компонент круглого прогресс бара.
141
184
  */
142
185
  export const CircularProgressBar: React.FC<CircularProgressBarProps> = ({
143
- value,
186
+ value: valueFromProps,
144
187
  view = 'positive',
145
188
  size = 64,
146
189
  className,
147
190
  dataTestId,
148
- title = value ? value.toString() : '0',
191
+ title: titleFromProps = isObject(valueFromProps) ? null : `${valueFromProps}`,
149
192
  titleComplete,
150
193
  subtitle,
151
194
  contentColor = 'secondary',
@@ -162,7 +205,29 @@ export const CircularProgressBar: React.FC<CircularProgressBarProps> = ({
162
205
  progressStrokeColor,
163
206
  circleColor,
164
207
  strokeColor,
208
+ directionType = 'asc',
209
+ titleColor,
210
+ subtitleColor,
165
211
  }) => {
212
+ const isTimer = isObject(valueFromProps);
213
+ const [timerValue, timerTitle] = useTimer(
214
+ isTimer ? Math.min(Math.max(valueFromProps.timer, MIN_TIMER_VALUE), MAX_TIMER_VALUE) : -1,
215
+ isTimer,
216
+ isTimer ? valueFromProps.counting ?? 'backward' : 'backward',
217
+ );
218
+ let value: number;
219
+ let title: React.ReactNode;
220
+
221
+ if (isTimer) {
222
+ value = timerValue;
223
+ title = timerTitle;
224
+ } else {
225
+ value = valueFromProps;
226
+ title = titleFromProps;
227
+ }
228
+
229
+ value = directionType === 'desc' ? MAX_PROGRESS_VALUE - value : value;
230
+
166
231
  const memorized = useMemo(() => {
167
232
  const strokeWidth = STROKE[size];
168
233
  const maxProgress = 100;
@@ -184,41 +249,70 @@ export const CircularProgressBar: React.FC<CircularProgressBarProps> = ({
184
249
  strokeDasharray,
185
250
  strokeDashoffset,
186
251
  };
187
- }, [value, size]);
252
+ }, [size, value]);
188
253
 
189
254
  const isComplete = value === 100;
190
255
  const isCompleteTextColor = isComplete && completeTextColor;
191
256
  const titleContent = titleComplete && isComplete ? titleComplete : title;
192
257
  const subtitleContent = subtitleComplete && isComplete ? subtitleComplete : subtitle;
193
258
  const IconComponent = IconComplete && isComplete ? IconComplete : Icon;
259
+
194
260
  const typographyContentColor = TYPOGRAPHY_COLOR.includes(contentColor)
195
261
  ? (contentColor as TypographyColor)
196
262
  : undefined;
197
263
 
264
+ const getTextColor = (color?: TypographyColor | string) => {
265
+ if (isCompleteTextColor) {
266
+ return completeTextColor;
267
+ }
268
+
269
+ if (color) {
270
+ return isTypographyColor(color) ? color : undefined;
271
+ }
272
+
273
+ return typographyContentColor;
274
+ };
275
+
276
+ const getTextStyleColor = (color?: TypographyColor | string) => {
277
+ if (color) {
278
+ if (!isTypographyColor(color)) {
279
+ return { color };
280
+ }
281
+
282
+ return {};
283
+ }
284
+
285
+ return {
286
+ ...(!typographyContentColor && { color: contentColor }),
287
+ };
288
+ };
289
+
198
290
  const renderTitleString = () =>
199
291
  SIZES[size] > 64 ? (
200
292
  <TitleMobile
201
293
  className={cn(styles.typography, styles.title)}
202
- color={isCompleteTextColor ? completeTextColor : typographyContentColor}
294
+ color={getTextColor(titleColor)}
203
295
  tag='div'
204
296
  font='system'
205
297
  view={VIEW_TITLE[size]}
206
298
  style={{
207
- ...(!typographyContentColor && { color: contentColor }),
299
+ ...getTextStyleColor(titleColor),
208
300
  }}
301
+ dataTestId={getDataTestId(dataTestId, 'title')}
209
302
  >
210
303
  {titleContent}
211
304
  </TitleMobile>
212
305
  ) : (
213
306
  <Text
214
307
  className={styles.title}
215
- color={isCompleteTextColor ? completeTextColor : typographyContentColor}
308
+ color={getTextColor(titleColor)}
216
309
  tag='div'
217
310
  weight='bold'
218
311
  view={VIEW_TEXT[size]}
219
312
  style={{
220
- ...(!typographyContentColor && { color: contentColor }),
313
+ ...getTextStyleColor(titleColor),
221
314
  }}
315
+ dataTestId={getDataTestId(dataTestId, 'title')}
222
316
  >
223
317
  {titleContent}
224
318
  </Text>
@@ -231,10 +325,11 @@ export const CircularProgressBar: React.FC<CircularProgressBarProps> = ({
231
325
  <Text
232
326
  tag='div'
233
327
  className={styles.subtitle}
234
- color={isCompleteTextColor ? completeTextColor : typographyContentColor}
328
+ color={getTextColor(subtitleColor)}
235
329
  view='primary-small'
330
+ dataTestId={getDataTestId(dataTestId, 'subtitle')}
236
331
  style={{
237
- ...(!typographyContentColor && { color: contentColor }),
332
+ ...getTextStyleColor(subtitleColor),
238
333
  }}
239
334
  >
240
335
  {subtitleContent}
@@ -296,6 +391,7 @@ export const CircularProgressBar: React.FC<CircularProgressBarProps> = ({
296
391
  cy={memorized.center}
297
392
  r={memorized.radius}
298
393
  strokeWidth={STROKE[size]}
394
+ data-test-id={getDataTestId(dataTestId, 'circle-progress-bar')}
299
395
  />
300
396
  <circle
301
397
  className={cn(
@@ -317,6 +413,7 @@ export const CircularProgressBar: React.FC<CircularProgressBarProps> = ({
317
413
  : memorized.strokeDashoffset
318
414
  }
319
415
  transform={`rotate(${-90} ${memorized.center} ${memorized.center})`}
416
+ data-test-id={getDataTestId(dataTestId, 'circle-progress-value')}
320
417
  />
321
418
  </svg>
322
419
  <div
package/src/consts.ts CHANGED
@@ -9,6 +9,7 @@ export const SIZES = {
9
9
  48: 48,
10
10
  64: 64,
11
11
  80: 80,
12
+ 96: 96,
12
13
  128: 128,
13
14
  144: 144,
14
15
  };
@@ -24,6 +25,7 @@ export const STROKE = {
24
25
  48: 4,
25
26
  64: 6,
26
27
  80: 8,
28
+ 96: 8,
27
29
  128: 10,
28
30
  144: 12,
29
31
  };
@@ -39,6 +41,7 @@ export const VIEW_TITLE = {
39
41
  48: 'small',
40
42
  64: 'small',
41
43
  80: 'xsmall',
44
+ 96: 'xsmall',
42
45
  128: 'medium',
43
46
  144: 'medium',
44
47
  } as const;
@@ -54,6 +57,7 @@ export const VIEW_TEXT = {
54
57
  48: 'secondary-small',
55
58
  64: 'secondary-large',
56
59
  80: 'secondary-large',
60
+ 96: 'secondary-large',
57
61
  128: 'secondary-large',
58
62
  144: 'secondary-large',
59
63
  } as const;
@@ -71,6 +75,12 @@ export const SIZE_TO_CLASSNAME_MAP = {
71
75
  48: 'size-48',
72
76
  64: 'size-64',
73
77
  80: 'size-80',
78
+ 96: 'size-96',
74
79
  128: 'size-128',
75
80
  144: 'size-144',
76
81
  };
82
+
83
+ export const MAX_PROGRESS_VALUE = 100;
84
+
85
+ export const MIN_TIMER_VALUE = 0;
86
+ export const MAX_TIMER_VALUE = 3599;
@@ -96,6 +96,19 @@
96
96
  }
97
97
  }
98
98
 
99
+ .size-96 {
100
+ width: 96px;
101
+ height: 96px;
102
+
103
+ & .labelWrapper {
104
+ max-width: 64px;
105
+ }
106
+
107
+ & .title {
108
+ max-height: 20px;
109
+ }
110
+ }
111
+
99
112
  .size-80 {
100
113
  width: 80px;
101
114
  height: 80px;
@@ -188,6 +201,11 @@
188
201
  max-height: 64px;
189
202
  }
190
203
 
204
+ &.size-96 {
205
+ max-width: 48px;
206
+ max-height: 48px;
207
+ }
208
+
191
209
  &.size-80 {
192
210
  max-width: 48px;
193
211
  max-height: 48px;
package/src/index.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './Component';
2
+ export * from './types/typography-color';
@@ -0,0 +1 @@
1
+ export { getCircularProgressBarTestIds } from '../utils/get-circular-progress-bar-test-ids';
@@ -0,0 +1,3 @@
1
+ {
2
+ "module": "../esm/shared/index.js"
3
+ }
@@ -0,0 +1 @@
1
+ export type ComponentSize = 'xxl' | 'xl' | 'l' | 'm' | 's' | 'xs' | 24 | 48 | 64 | 80 | 128 | 144;
@@ -0,0 +1 @@
1
+ export type TypographyColor = 'primary' | 'secondary' | 'tertiary' | 'positive' | 'negative';
@@ -0,0 +1,35 @@
1
+ import { useEffect, useState } from 'react';
2
+
3
+ import { noop } from '@alfalab/core-components-shared';
4
+
5
+ const MAX_PERSENT_VALUE = 100;
6
+
7
+ function makeTitle(time: number) {
8
+ return `${Math.trunc(time / 60)}:${`${time % 60}`.padStart(2, '0')}`;
9
+ }
10
+
11
+ export function useTimer(
12
+ time: number,
13
+ active = true,
14
+ counting: 'forward' | 'backward',
15
+ interval = 1000,
16
+ step = 1,
17
+ ): [value: number, title: string] {
18
+ const [passedTime, setPassedTime] = useState(0);
19
+ const isCompleted = passedTime === time;
20
+ const persentValue = Math.trunc((passedTime / time) * MAX_PERSENT_VALUE);
21
+
22
+ useEffect(() => {
23
+ if (!active || isCompleted) {
24
+ return noop;
25
+ }
26
+
27
+ const timer = setInterval(() => {
28
+ setPassedTime((prevPassed) => prevPassed + step);
29
+ }, interval);
30
+
31
+ return () => clearInterval(timer);
32
+ }, [interval, isCompleted, active, step]);
33
+
34
+ return [persentValue, makeTitle(counting === 'backward' ? time - passedTime : passedTime)];
35
+ }
@@ -0,0 +1,11 @@
1
+ import { getDataTestId } from '@alfalab/core-components-shared';
2
+
3
+ export function getCircularProgressBarTestIds(dataTestId: string) {
4
+ return {
5
+ progressBar: dataTestId,
6
+ title: getDataTestId(dataTestId, 'title'),
7
+ subtitle: getDataTestId(dataTestId, 'subtitle'),
8
+ circleProgressBar: getDataTestId(dataTestId, 'circle-progress-bar'),
9
+ circleProgressValue: getDataTestId(dataTestId, 'circle-progress-value'),
10
+ };
11
+ }
@@ -0,0 +1,5 @@
1
+ import { TYPOGRAPHY_COLOR } from '../consts';
2
+ import { TypographyColor } from '../types/typography-color';
3
+
4
+ export const isTypographyColor = (color: TypographyColor | string): color is TypographyColor =>
5
+ TYPOGRAPHY_COLOR.includes(color);
@@ -0,0 +1,2 @@
1
+ type ComponentSize = 'xxl' | 'xl' | 'l' | 'm' | 's' | 'xs' | 24 | 48 | 64 | 80 | 128 | 144;
2
+ export { ComponentSize };
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1,2 @@
1
+ type TypographyColor = 'primary' | 'secondary' | 'tertiary' | 'positive' | 'negative';
2
+ export { TypographyColor };
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
package/use-timer.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare function useTimer(time: number, active: boolean | undefined, counting: 'forward' | 'backward', interval?: number, step?: number): [value: number, title: string];
2
+ export { useTimer };
package/use-timer.js ADDED
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var coreComponentsShared = require('@alfalab/core-components-shared');
7
+
8
+ var MAX_PERSENT_VALUE = 100;
9
+ function makeTitle(time) {
10
+ return "".concat(Math.trunc(time / 60), ":").concat("".concat(time % 60).padStart(2, '0'));
11
+ }
12
+ function useTimer(time, active, counting, interval, step) {
13
+ if (active === void 0) { active = true; }
14
+ if (interval === void 0) { interval = 1000; }
15
+ if (step === void 0) { step = 1; }
16
+ var _a = React.useState(0), passedTime = _a[0], setPassedTime = _a[1];
17
+ var isCompleted = passedTime === time;
18
+ var persentValue = Math.trunc((passedTime / time) * MAX_PERSENT_VALUE);
19
+ React.useEffect(function () {
20
+ if (!active || isCompleted) {
21
+ return coreComponentsShared.noop;
22
+ }
23
+ var timer = setInterval(function () {
24
+ setPassedTime(function (prevPassed) { return prevPassed + step; });
25
+ }, interval);
26
+ return function () { return clearInterval(timer); };
27
+ }, [interval, isCompleted, active, step]);
28
+ return [persentValue, makeTitle(counting === 'backward' ? time - passedTime : passedTime)];
29
+ }
30
+
31
+ exports.useTimer = useTimer;
@@ -0,0 +1,8 @@
1
+ declare function getCircularProgressBarTestIds(dataTestId: string): {
2
+ progressBar: string;
3
+ title: string;
4
+ subtitle: string;
5
+ circleProgressBar: string;
6
+ circleProgressValue: string;
7
+ };
8
+ export { getCircularProgressBarTestIds };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var coreComponentsShared = require('@alfalab/core-components-shared');
6
+
7
+ function getCircularProgressBarTestIds(dataTestId) {
8
+ return {
9
+ progressBar: dataTestId,
10
+ title: coreComponentsShared.getDataTestId(dataTestId, 'title'),
11
+ subtitle: coreComponentsShared.getDataTestId(dataTestId, 'subtitle'),
12
+ circleProgressBar: coreComponentsShared.getDataTestId(dataTestId, 'circle-progress-bar'),
13
+ circleProgressValue: coreComponentsShared.getDataTestId(dataTestId, 'circle-progress-value'),
14
+ };
15
+ }
16
+
17
+ exports.getCircularProgressBarTestIds = getCircularProgressBarTestIds;
@@ -0,0 +1,3 @@
1
+ import { TypographyColor } from "../types/typography-color";
2
+ declare const isTypographyColor: (color: TypographyColor | string) => color is TypographyColor;
3
+ export { isTypographyColor };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var consts = require('../consts.js');
6
+
7
+ var isTypographyColor = function (color) {
8
+ return consts.TYPOGRAPHY_COLOR.includes(color);
9
+ };
10
+
11
+ exports.isTypographyColor = isTypographyColor;