@alfalab/core-components-confirmation 13.6.2 → 13.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.
- package/components/base-confirmation/component.js +1 -1
- package/components/base-confirmation/index.css +2 -2
- package/components/countdown-loader/component.js +1 -1
- package/components/countdown-loader/index.css +2 -2
- package/components/header/component.js +1 -1
- package/components/header/index.css +6 -5
- package/components/screens/fatal-error/component.js +1 -1
- package/components/screens/fatal-error/index.css +8 -7
- package/components/screens/hint/component.js +1 -1
- package/components/screens/hint/index.css +19 -16
- package/components/screens/initial/component.js +1 -1
- package/components/screens/initial/countdown-section.js +1 -1
- package/components/screens/initial/index.css +32 -26
- package/components/screens/temp-block/component.js +1 -1
- package/components/screens/temp-block/index.css +10 -9
- package/{countdown-section-f20056ef.js → countdown-section-17d446a6.js} +1 -1
- package/cssm/components/header/index.module.css +2 -1
- package/cssm/components/screens/fatal-error/index.module.css +2 -1
- package/cssm/components/screens/hint/index.module.css +7 -4
- package/cssm/components/screens/initial/index.module.css +14 -8
- package/cssm/components/screens/temp-block/index.module.css +3 -2
- package/esm/components/base-confirmation/component.js +1 -1
- package/esm/components/base-confirmation/index.css +2 -2
- package/esm/components/countdown-loader/component.js +1 -1
- package/esm/components/countdown-loader/index.css +2 -2
- package/esm/components/header/component.js +1 -1
- package/esm/components/header/index.css +6 -5
- package/esm/components/screens/fatal-error/component.js +1 -1
- package/esm/components/screens/fatal-error/index.css +8 -7
- package/esm/components/screens/hint/component.js +1 -1
- package/esm/components/screens/hint/index.css +19 -16
- package/esm/components/screens/initial/component.js +1 -1
- package/esm/components/screens/initial/countdown-section.js +1 -1
- package/esm/components/screens/initial/index.css +32 -26
- package/esm/components/screens/temp-block/component.js +1 -1
- package/esm/components/screens/temp-block/index.css +10 -9
- package/esm/{countdown-section-7164d11c.js → countdown-section-c5b45e8c.js} +1 -1
- package/esm/mobile/component.mobile.js +1 -1
- package/esm/mobile/mobile.css +2 -2
- package/mobile/component.mobile.js +1 -1
- package/mobile/mobile.css +2 -2
- package/modern/components/base-confirmation/component.js +1 -1
- package/modern/components/base-confirmation/index.css +2 -2
- package/modern/components/countdown-loader/component.js +1 -1
- package/modern/components/countdown-loader/index.css +2 -2
- package/modern/components/header/component.js +1 -1
- package/modern/components/header/index.css +6 -5
- package/modern/components/screens/fatal-error/component.js +1 -1
- package/modern/components/screens/fatal-error/index.css +8 -7
- package/modern/components/screens/hint/component.js +1 -1
- package/modern/components/screens/hint/index.css +19 -16
- package/modern/components/screens/initial/component.js +1 -1
- package/modern/components/screens/initial/countdown-section.js +1 -1
- package/modern/components/screens/initial/index.css +32 -26
- package/modern/components/screens/temp-block/component.js +1 -1
- package/modern/components/screens/temp-block/index.css +10 -9
- package/modern/{countdown-section-37a6acf8.js → countdown-section-b9145aea.js} +1 -1
- package/modern/mobile/component.mobile.js +1 -1
- package/modern/mobile/mobile.css +2 -2
- package/moderncssm/component.responsive.d.ts +15 -0
- package/moderncssm/component.responsive.js +11 -0
- package/moderncssm/components/base-confirmation/component.d.ts +4 -0
- package/moderncssm/components/base-confirmation/component.js +85 -0
- package/moderncssm/components/base-confirmation/index.d.ts +1 -0
- package/moderncssm/components/base-confirmation/index.js +1 -0
- package/moderncssm/components/base-confirmation/index.module.css +8 -0
- package/moderncssm/components/countdown-loader/component.d.ts +7 -0
- package/moderncssm/components/countdown-loader/component.js +18 -0
- package/moderncssm/components/countdown-loader/index.d.ts +1 -0
- package/moderncssm/components/countdown-loader/index.js +1 -0
- package/moderncssm/components/countdown-loader/index.module.css +7 -0
- package/moderncssm/components/header/component.d.ts +13 -0
- package/moderncssm/components/header/component.js +8 -0
- package/moderncssm/components/header/index.d.ts +1 -0
- package/moderncssm/components/header/index.js +1 -0
- package/moderncssm/components/header/index.module.css +40 -0
- package/moderncssm/components/index.d.ts +2 -0
- package/moderncssm/components/index.js +5 -0
- package/moderncssm/components/screens/fatal-error/component.d.ts +9 -0
- package/moderncssm/components/screens/fatal-error/component.js +17 -0
- package/moderncssm/components/screens/fatal-error/index.d.ts +1 -0
- package/moderncssm/components/screens/fatal-error/index.js +1 -0
- package/moderncssm/components/screens/fatal-error/index.module.css +42 -0
- package/moderncssm/components/screens/hint/component.d.ts +9 -0
- package/moderncssm/components/screens/hint/component.js +34 -0
- package/moderncssm/components/screens/hint/index.d.ts +1 -0
- package/moderncssm/components/screens/hint/index.js +1 -0
- package/moderncssm/components/screens/hint/index.module.css +72 -0
- package/moderncssm/components/screens/index.d.ts +4 -0
- package/moderncssm/components/screens/index.js +4 -0
- package/moderncssm/components/screens/initial/component.d.ts +9 -0
- package/moderncssm/components/screens/initial/component.js +102 -0
- package/moderncssm/components/screens/initial/countdown-section.d.ts +10 -0
- package/moderncssm/components/screens/initial/countdown-section.js +34 -0
- package/moderncssm/components/screens/initial/index.d.ts +1 -0
- package/moderncssm/components/screens/initial/index.js +1 -0
- package/moderncssm/components/screens/initial/index.module.css +97 -0
- package/moderncssm/components/screens/temp-block/component.d.ts +9 -0
- package/moderncssm/components/screens/temp-block/component.js +29 -0
- package/moderncssm/components/screens/temp-block/index.d.ts +1 -0
- package/moderncssm/components/screens/temp-block/index.js +1 -0
- package/moderncssm/components/screens/temp-block/index.module.css +47 -0
- package/moderncssm/context.d.ts +4 -0
- package/moderncssm/context.js +26 -0
- package/moderncssm/desktop/component.desktop.d.ts +5 -0
- package/moderncssm/desktop/component.desktop.js +6 -0
- package/moderncssm/desktop/index.d.ts +2 -0
- package/moderncssm/desktop/index.js +2 -0
- package/moderncssm/index.d.ts +2 -0
- package/moderncssm/index.js +2 -0
- package/moderncssm/mobile/component.mobile.d.ts +5 -0
- package/moderncssm/mobile/component.mobile.js +8 -0
- package/moderncssm/mobile/index.d.ts +2 -0
- package/moderncssm/mobile/index.js +2 -0
- package/moderncssm/mobile/mobile.module.css +3 -0
- package/moderncssm/shared/index.d.ts +4 -0
- package/moderncssm/shared/index.js +8 -0
- package/moderncssm/types.d.ts +167 -0
- package/moderncssm/types.js +19 -0
- package/moderncssm/utils.d.ts +30 -0
- package/moderncssm/utils.js +72 -0
- package/moderncssm/vars.css +11 -0
- package/package.json +8 -8
- package/src/components/base-confirmation/index.module.css +1 -1
- package/src/components/countdown-loader/index.module.css +1 -1
- package/src/components/header/index.module.css +1 -1
- package/src/components/screens/fatal-error/index.module.css +1 -1
- package/src/components/screens/hint/index.module.css +4 -4
- package/src/components/screens/initial/index.module.css +8 -8
- package/src/components/screens/temp-block/index.module.css +2 -2
- package/src/vars.css +1 -1
- /package/{countdown-section-f20056ef.d.ts → countdown-section-17d446a6.d.ts} +0 -0
- /package/esm/{countdown-section-7164d11c.d.ts → countdown-section-c5b45e8c.d.ts} +0 -0
- /package/modern/{countdown-section-37a6acf8.d.ts → countdown-section-b9145aea.d.ts} +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
import { ONE_MINUTE, ONE_DAY } from './utils.js';
|
|
3
|
+
|
|
4
|
+
const mockFn = () => undefined;
|
|
5
|
+
const ConfirmationContext = createContext({
|
|
6
|
+
alignContent: 'left',
|
|
7
|
+
texts: {},
|
|
8
|
+
state: 'INITIAL',
|
|
9
|
+
screen: 'INITIAL',
|
|
10
|
+
requiredCharAmount: 5,
|
|
11
|
+
countdownDuration: ONE_MINUTE,
|
|
12
|
+
timeLeft: ONE_MINUTE,
|
|
13
|
+
tempBlockDuration: ONE_DAY,
|
|
14
|
+
phone: '',
|
|
15
|
+
hideCountdownSection: false,
|
|
16
|
+
breakpoint: 1024,
|
|
17
|
+
initialScreenHintSlot: null,
|
|
18
|
+
onTempBlockFinished: mockFn,
|
|
19
|
+
onInputFinished: mockFn,
|
|
20
|
+
onChangeState: mockFn,
|
|
21
|
+
onSmsRetryClick: mockFn,
|
|
22
|
+
onChangeScreen: mockFn,
|
|
23
|
+
onFatalErrorOkButtonClick: mockFn,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export { ConfirmationContext };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { ConfirmationProps } from "../types";
|
|
3
|
+
type DesktopConfirmationProps = Omit<ConfirmationProps, 'mobile' | 'breakpoint'>;
|
|
4
|
+
declare const ConfirmationDesktop: FC<DesktopConfirmationProps>;
|
|
5
|
+
export { DesktopConfirmationProps, ConfirmationDesktop };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { BaseConfirmation } from '../components/base-confirmation/component.js';
|
|
4
|
+
import styles from './mobile.module.css';
|
|
5
|
+
|
|
6
|
+
const ConfirmationMobile = ({ className, ...resProps }) => (React.createElement(BaseConfirmation, { mobile: true, className: cn(className, styles.container), ...resProps }));
|
|
7
|
+
|
|
8
|
+
export { ConfirmationMobile };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Initial } from '../components/screens/initial/component.js';
|
|
2
|
+
export { Hint } from '../components/screens/hint/component.js';
|
|
3
|
+
export { FatalError } from '../components/screens/fatal-error/component.js';
|
|
4
|
+
export { TempBlock } from '../components/screens/temp-block/component.js';
|
|
5
|
+
export { CountdownLoader } from '../components/countdown-loader/component.js';
|
|
6
|
+
export { ConfirmationContext } from '../context.js';
|
|
7
|
+
export { defaultTexts } from '../types.js';
|
|
8
|
+
export { ONE_DAY, ONE_MINUTE, formatMsAsMinutes } from '../utils.js';
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from 'react';
|
|
2
|
+
type ConfirmationProps = {
|
|
3
|
+
/**
|
|
4
|
+
* Экран компонента
|
|
5
|
+
*/
|
|
6
|
+
screen: ConfirmationScreen | string;
|
|
7
|
+
/**
|
|
8
|
+
* Состояние компонента
|
|
9
|
+
*/
|
|
10
|
+
state: ConfirmationState | string;
|
|
11
|
+
/**
|
|
12
|
+
* Мобильная версия компонента для экрана
|
|
13
|
+
*/
|
|
14
|
+
mobile?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Позиционирование контента
|
|
17
|
+
*/
|
|
18
|
+
alignContent?: 'left' | 'center';
|
|
19
|
+
/**
|
|
20
|
+
* Объект с текстами
|
|
21
|
+
*/
|
|
22
|
+
texts?: ConfirmationTexts;
|
|
23
|
+
/**
|
|
24
|
+
* Количество символов, которое можно ввести в поле ввода подписания до того, как произойдет автоотправка
|
|
25
|
+
*/
|
|
26
|
+
requiredCharAmount?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Длительность обратного отсчета на кнопке повторного запроса сообщения, в милисекундах
|
|
29
|
+
*/
|
|
30
|
+
countdownDuration?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Продолжительность блокировки формы (ms)
|
|
33
|
+
*/
|
|
34
|
+
tempBlockDuration?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Номер телефона, на который отправлен код
|
|
37
|
+
*/
|
|
38
|
+
phone?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Не осталось попыток ввода кода
|
|
41
|
+
*/
|
|
42
|
+
blockSmsRetry?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Идентификатор для систем автоматизированного тестирования
|
|
45
|
+
*/
|
|
46
|
+
dataTestId?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Сss класс для стилизации общей обёртки
|
|
49
|
+
*/
|
|
50
|
+
className?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Флаг - нужно ли очищать код при возникновении ошибки
|
|
53
|
+
*/
|
|
54
|
+
clearCodeOnError?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Функция обновления состояния компонента
|
|
57
|
+
*/
|
|
58
|
+
onChangeState: (state: ConfirmationState | string) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Функция обновления состояния компонента
|
|
61
|
+
*/
|
|
62
|
+
onChangeScreen: (state: ConfirmationScreen | string) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Обработчик события завершения ввода кода подписания
|
|
65
|
+
*/
|
|
66
|
+
onInputFinished: (code: string) => void;
|
|
67
|
+
/**
|
|
68
|
+
* Обработчик события нажатия на кнопку "Запросить код"
|
|
69
|
+
*/
|
|
70
|
+
onSmsRetryClick: () => void;
|
|
71
|
+
/**
|
|
72
|
+
* Клик по кнопке "Понятно" на экране фатальной ошибки
|
|
73
|
+
*/
|
|
74
|
+
onFatalErrorOkButtonClick?: () => void;
|
|
75
|
+
/**
|
|
76
|
+
* Временная блокировка формы закончилась
|
|
77
|
+
*/
|
|
78
|
+
onTempBlockFinished?: () => void;
|
|
79
|
+
/**
|
|
80
|
+
* Возввращает объект, где ключ - название экрана (screen), значение - компонент для экрана
|
|
81
|
+
*/
|
|
82
|
+
getScreensMap?: (defaulScreensMap: ScreensMap) => ScreensMap;
|
|
83
|
+
/**
|
|
84
|
+
* Дочерние элементы.
|
|
85
|
+
*/
|
|
86
|
+
children?: ReactNode;
|
|
87
|
+
/**
|
|
88
|
+
* Скрыть секцию с повторной отправкой кода
|
|
89
|
+
* @default false
|
|
90
|
+
*/
|
|
91
|
+
hideCountdownSection?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Слот для контента с подсказкой на главном экране
|
|
94
|
+
*/
|
|
95
|
+
initialScreenHintSlot?: ReactNode;
|
|
96
|
+
/**
|
|
97
|
+
* Контрольная точка для кнопки, с нее начинается desktop версия
|
|
98
|
+
* @default 1024
|
|
99
|
+
*/
|
|
100
|
+
breakpoint?: number;
|
|
101
|
+
/**
|
|
102
|
+
* Продолжительность отображения ошибки
|
|
103
|
+
* @default 1300
|
|
104
|
+
*/
|
|
105
|
+
errorVisibleDuration?: number;
|
|
106
|
+
};
|
|
107
|
+
type TConfirmationContext = Required<Pick<ConfirmationProps, 'alignContent' | 'texts' | 'state' | 'screen' | 'requiredCharAmount' | 'onInputFinished' | 'countdownDuration' | 'onChangeState' | 'onSmsRetryClick' | 'onChangeScreen' | 'onFatalErrorOkButtonClick' | 'tempBlockDuration' | 'hideCountdownSection'>> & Pick<ConfirmationProps, 'phone' | 'blockSmsRetry' | 'onTempBlockFinished' | 'clearCodeOnError' | 'initialScreenHintSlot' | 'errorVisibleDuration'> & {
|
|
108
|
+
timeLeft: number;
|
|
109
|
+
} & {
|
|
110
|
+
/**
|
|
111
|
+
* Контрольная точка для кнопки, с нее начинается desktop версия
|
|
112
|
+
* @default 1024
|
|
113
|
+
*/
|
|
114
|
+
breakpoint?: number;
|
|
115
|
+
};
|
|
116
|
+
type ConfirmationTexts = {
|
|
117
|
+
/**
|
|
118
|
+
* Экран INITIAL
|
|
119
|
+
*/
|
|
120
|
+
title?: ReactNode;
|
|
121
|
+
codeError?: string;
|
|
122
|
+
codeChecking?: string;
|
|
123
|
+
codeSending?: string;
|
|
124
|
+
codeSended?: string;
|
|
125
|
+
buttonRetry?: string;
|
|
126
|
+
linkToHint?: string;
|
|
127
|
+
noAttemptsLeft?: string;
|
|
128
|
+
countdown?: string;
|
|
129
|
+
/**
|
|
130
|
+
* Экран HINT
|
|
131
|
+
*/
|
|
132
|
+
hintButton?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Экран FATAL_ERROR
|
|
135
|
+
*/
|
|
136
|
+
fatalErrorTitle?: ReactNode;
|
|
137
|
+
fatalErrorDescription?: ReactNode;
|
|
138
|
+
fatalErrorButton?: string;
|
|
139
|
+
/**
|
|
140
|
+
* Экран TEMP_BLOCK
|
|
141
|
+
*/
|
|
142
|
+
tempBlockTitle?: ReactNode;
|
|
143
|
+
tempBlockDescription?: ReactNode;
|
|
144
|
+
};
|
|
145
|
+
type ConfirmationScreen = 'INITIAL' | 'HINT' | 'FATAL_ERROR' | 'TEMP_BLOCK';
|
|
146
|
+
type ConfirmationState = 'INITIAL' | 'CODE_CHECKING' | 'CODE_SENDING' | 'CODE_ERROR';
|
|
147
|
+
type ScreensMap = {
|
|
148
|
+
[key: string]: ComponentType;
|
|
149
|
+
};
|
|
150
|
+
declare const defaultTexts: {
|
|
151
|
+
title: string;
|
|
152
|
+
codeError: string;
|
|
153
|
+
codeChecking: string;
|
|
154
|
+
codeSending: string;
|
|
155
|
+
buttonRetry: string;
|
|
156
|
+
linkToHint: string;
|
|
157
|
+
hintButton: string;
|
|
158
|
+
noAttemptsLeft: string;
|
|
159
|
+
fatalErrorTitle: string;
|
|
160
|
+
fatalErrorDescription: string;
|
|
161
|
+
fatalErrorButton: string;
|
|
162
|
+
tempBlockTitle: string;
|
|
163
|
+
tempBlockDescription: string;
|
|
164
|
+
codeSended: string;
|
|
165
|
+
countdown: string;
|
|
166
|
+
};
|
|
167
|
+
export { ConfirmationProps, TConfirmationContext, ConfirmationTexts, ConfirmationScreen, ConfirmationState, ScreensMap, defaultTexts };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const defaultTexts = {
|
|
2
|
+
title: 'Введите код из\xa0сообщения',
|
|
3
|
+
codeError: 'Код введён неверно',
|
|
4
|
+
codeChecking: '',
|
|
5
|
+
codeSending: '',
|
|
6
|
+
buttonRetry: 'Запросить код повторно',
|
|
7
|
+
linkToHint: 'Не\xa0приходит сообщение?',
|
|
8
|
+
hintButton: 'Вернуться к\xa0вводу кода',
|
|
9
|
+
noAttemptsLeft: 'Не\xa0осталось попыток запроса кода',
|
|
10
|
+
fatalErrorTitle: 'Ввести код больше нельзя',
|
|
11
|
+
fatalErrorDescription: 'Вы\xa0ввели код неверно более 5\xa0раз. В\xa0целях безопасности мы\xa0ограничили дальнейший ввод.',
|
|
12
|
+
fatalErrorButton: 'Понятно',
|
|
13
|
+
tempBlockTitle: 'Превышено количество попыток запроса кода',
|
|
14
|
+
tempBlockDescription: 'Повторное подтверждение кодом будет возможно через 24\xa0часа',
|
|
15
|
+
codeSended: 'Код выслан',
|
|
16
|
+
countdown: 'Запросить повторно можно через',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { defaultTexts };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ConfirmationProps } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Форматирование миллисекунд в hh:mm:ss.
|
|
5
|
+
*
|
|
6
|
+
* @param {Number} ms миллисекунды
|
|
7
|
+
* @returns {String} время в формате mm:ss
|
|
8
|
+
*/
|
|
9
|
+
declare function formatMsAsMinutes(ms: number): string;
|
|
10
|
+
type UseCountdown = (countdownDuration: number, tick?: number) => [number, () => void, () => void];
|
|
11
|
+
/**
|
|
12
|
+
* Возвращает время, которое осталось до истечения таймера в ms
|
|
13
|
+
*/
|
|
14
|
+
declare const useCountdown: UseCountdown;
|
|
15
|
+
declare const ONE_DAY: number;
|
|
16
|
+
declare const ONE_MINUTE: number;
|
|
17
|
+
type UseConfirmationParams = {
|
|
18
|
+
state?: ConfirmationProps['state'];
|
|
19
|
+
screen?: ConfirmationProps['screen'];
|
|
20
|
+
blockSmsRetry?: ConfirmationProps['blockSmsRetry'];
|
|
21
|
+
};
|
|
22
|
+
declare const useConfirmation: ({ state, screen, blockSmsRetry }?: UseConfirmationParams) => {
|
|
23
|
+
confirmationState: string;
|
|
24
|
+
confirmationScreen: string;
|
|
25
|
+
confirmationBlockSmsRetry: boolean;
|
|
26
|
+
setConfirmationState: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
27
|
+
setConfirmationScreen: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
28
|
+
setConfirmationBlockSmsRetry: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
29
|
+
};
|
|
30
|
+
export { formatMsAsMinutes, useCountdown, ONE_DAY, ONE_MINUTE, useConfirmation };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { useRef, useState, useCallback, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Форматирование миллисекунд в hh:mm:ss.
|
|
5
|
+
*
|
|
6
|
+
* @param {Number} ms миллисекунды
|
|
7
|
+
* @returns {String} время в формате mm:ss
|
|
8
|
+
*/
|
|
9
|
+
function formatMsAsMinutes(ms) {
|
|
10
|
+
const totalSeconds = Math.ceil(ms / 1000);
|
|
11
|
+
const totalMinutes = Math.floor(totalSeconds / 60);
|
|
12
|
+
const totalHours = Math.floor(totalMinutes / 60);
|
|
13
|
+
const seconds = totalSeconds % 60;
|
|
14
|
+
const paddedSeconds = `00${seconds}`.slice(-2);
|
|
15
|
+
if (totalHours > 0) {
|
|
16
|
+
const minutes = totalMinutes % 60;
|
|
17
|
+
const paddedMinutes = `00${minutes}`.slice(-2);
|
|
18
|
+
const paddedHours = `00${totalHours}`.slice(-2);
|
|
19
|
+
return `${paddedHours}:${paddedMinutes}:${paddedSeconds}`;
|
|
20
|
+
}
|
|
21
|
+
const paddedMinutes = `00${totalMinutes}`.slice(-2);
|
|
22
|
+
return `${paddedMinutes}:${paddedSeconds}`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Возвращает время, которое осталось до истечения таймера в ms
|
|
26
|
+
*/
|
|
27
|
+
const useCountdown = (countdownDuration, tick = 1000) => {
|
|
28
|
+
const timerId = useRef(0);
|
|
29
|
+
const start = useRef(0);
|
|
30
|
+
const [timePassed, setTimePassed] = useState(0);
|
|
31
|
+
const stopTimer = useCallback(() => {
|
|
32
|
+
window.clearInterval(timerId.current);
|
|
33
|
+
}, []);
|
|
34
|
+
const updateProgress = useCallback(() => {
|
|
35
|
+
const passed = Date.now() - start.current;
|
|
36
|
+
if (passed >= countdownDuration) {
|
|
37
|
+
stopTimer();
|
|
38
|
+
setTimePassed(countdownDuration);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
setTimePassed(passed);
|
|
42
|
+
}
|
|
43
|
+
}, [countdownDuration, stopTimer]);
|
|
44
|
+
const startTimer = useCallback(() => {
|
|
45
|
+
stopTimer();
|
|
46
|
+
start.current = Date.now();
|
|
47
|
+
updateProgress();
|
|
48
|
+
timerId.current = window.setInterval(updateProgress, tick);
|
|
49
|
+
}, [stopTimer, updateProgress, tick]);
|
|
50
|
+
const timeLeft = countdownDuration - timePassed;
|
|
51
|
+
useEffect(() => () => {
|
|
52
|
+
stopTimer();
|
|
53
|
+
}, [stopTimer]);
|
|
54
|
+
return [timeLeft, startTimer, stopTimer];
|
|
55
|
+
};
|
|
56
|
+
const ONE_DAY = 24 * 60 * 60 * 1000;
|
|
57
|
+
const ONE_MINUTE = 60 * 1000;
|
|
58
|
+
const useConfirmation = ({ state, screen, blockSmsRetry } = {}) => {
|
|
59
|
+
const [confirmationState, setConfirmationState] = useState(state ?? 'INITIAL');
|
|
60
|
+
const [confirmationScreen, setConfirmationScreen] = useState(screen ?? 'INITIAL');
|
|
61
|
+
const [confirmationBlockSmsRetry, setConfirmationBlockSmsRetry] = useState(blockSmsRetry ?? false);
|
|
62
|
+
return {
|
|
63
|
+
confirmationState,
|
|
64
|
+
confirmationScreen,
|
|
65
|
+
confirmationBlockSmsRetry,
|
|
66
|
+
setConfirmationState,
|
|
67
|
+
setConfirmationScreen,
|
|
68
|
+
setConfirmationBlockSmsRetry,
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { ONE_DAY, ONE_MINUTE, formatMsAsMinutes, useConfirmation, useCountdown };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alfalab/core-components-confirmation",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.7.0",
|
|
4
4
|
"description": "Sms confirmation component",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
"directory": "dist"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@alfalab/core-components-button": "^11.
|
|
15
|
-
"@alfalab/core-components-code-input": "^3.
|
|
16
|
-
"@alfalab/core-components-link": "^5.
|
|
17
|
-
"@alfalab/core-components-spinner": "^3.
|
|
18
|
-
"@alfalab/core-components-typography": "^4.
|
|
14
|
+
"@alfalab/core-components-button": "^11.6.0",
|
|
15
|
+
"@alfalab/core-components-code-input": "^3.5.0",
|
|
16
|
+
"@alfalab/core-components-link": "^5.3.0",
|
|
17
|
+
"@alfalab/core-components-spinner": "^3.5.0",
|
|
18
|
+
"@alfalab/core-components-typography": "^4.10.0",
|
|
19
19
|
"@alfalab/core-components-mq": "^4.3.0",
|
|
20
20
|
"@alfalab/hooks": "^1.13.0",
|
|
21
21
|
"classnames": "^2.3.1",
|
|
@@ -24,6 +24,6 @@
|
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"react": "^16.9.0 || ^17.0.1 || ^18.0.0"
|
|
26
26
|
},
|
|
27
|
-
"themesVersion": "13.0
|
|
28
|
-
"varsVersion": "9.
|
|
27
|
+
"themesVersion": "13.1.0",
|
|
28
|
+
"varsVersion": "9.12.0"
|
|
29
29
|
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
.text.text {
|
|
18
|
-
margin-bottom: var(--gap-
|
|
18
|
+
margin-bottom: var(--gap-24);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
.typographyTheme.typographyTheme {
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
.phonesWrap {
|
|
26
26
|
display: flex;
|
|
27
27
|
flex-direction: column;
|
|
28
|
-
margin-bottom: var(--gap-
|
|
28
|
+
margin-bottom: var(--gap-24);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
.phoneWrap {
|
|
32
|
-
margin-bottom: var(--gap-
|
|
32
|
+
margin-bottom: var(--gap-8);
|
|
33
33
|
|
|
34
34
|
&:last-child {
|
|
35
35
|
margin-bottom: 0;
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
.hintButton {
|
|
44
|
-
margin-top: var(--gap-
|
|
44
|
+
margin-top: var(--gap-32);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
.phoneContentMobile {
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
|
|
12
12
|
.phone.phone {
|
|
13
13
|
color: var(--color-light-text-primary);
|
|
14
|
-
margin-bottom: var(--gap-
|
|
14
|
+
margin-bottom: var(--gap-32);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
.compact {
|
|
18
|
-
margin-bottom: var(--gap-
|
|
18
|
+
margin-bottom: var(--gap-24);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
.loaderWrap {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
.codeInput {
|
|
40
|
-
margin-bottom: var(--gap-
|
|
40
|
+
margin-bottom: var(--gap-12);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
.smsBtn.smsBtn {
|
|
@@ -50,20 +50,20 @@
|
|
|
50
50
|
|
|
51
51
|
.countdownContainer.countdownContainer {
|
|
52
52
|
color: var(--color-light-text-secondary);
|
|
53
|
-
margin-bottom: var(--gap-
|
|
53
|
+
margin-bottom: var(--gap-24);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
.countdownMobile.countdownMobile {
|
|
57
|
-
margin-bottom: var(--gap-
|
|
57
|
+
margin-bottom: var(--gap-20);
|
|
58
58
|
}
|
|
59
59
|
.countdownLoaderMobile.countdownLoaderMobile {
|
|
60
|
-
margin-bottom: var(--gap-
|
|
60
|
+
margin-bottom: var(--gap-16);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
.getCodeButton {
|
|
64
64
|
position: relative;
|
|
65
|
-
top: var(--gap-
|
|
66
|
-
margin-bottom: var(--gap-
|
|
65
|
+
top: var(--gap-4-neg);
|
|
66
|
+
margin-bottom: var(--gap-16);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
.getCodeButtonMobile {
|
package/src/vars.css
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|