@cloud-ru/uikit-product-fields-predefined 3.0.3-preview-7cd1981e.0 → 3.0.3
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 +12 -0
- package/README.md +0 -28
- package/dist/cjs/components/index.d.ts +0 -1
- package/dist/cjs/components/index.js +0 -1
- package/dist/esm/components/index.d.ts +0 -1
- package/dist/esm/components/index.js +0 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +7 -10
- package/src/components/index.ts +0 -1
- package/dist/cjs/components/FieldCode/FieldCode.d.ts +0 -32
- package/dist/cjs/components/FieldCode/FieldCode.js +0 -45
- package/dist/cjs/components/FieldCode/components/Cell/Cell.d.ts +0 -7
- package/dist/cjs/components/FieldCode/components/Cell/Cell.js +0 -27
- package/dist/cjs/components/FieldCode/components/Cell/index.d.ts +0 -1
- package/dist/cjs/components/FieldCode/components/Cell/index.js +0 -17
- package/dist/cjs/components/FieldCode/components/Cell/styles.module.css +0 -19
- package/dist/cjs/components/FieldCode/components/ResendCode/ResendCode.d.ts +0 -8
- package/dist/cjs/components/FieldCode/components/ResendCode/ResendCode.js +0 -29
- package/dist/cjs/components/FieldCode/components/ResendCode/index.d.ts +0 -1
- package/dist/cjs/components/FieldCode/components/ResendCode/index.js +0 -17
- package/dist/cjs/components/FieldCode/components/ResendCode/utils.d.ts +0 -1
- package/dist/cjs/components/FieldCode/components/ResendCode/utils.js +0 -8
- package/dist/cjs/components/FieldCode/components/index.d.ts +0 -2
- package/dist/cjs/components/FieldCode/components/index.js +0 -18
- package/dist/cjs/components/FieldCode/constants.d.ts +0 -1
- package/dist/cjs/components/FieldCode/constants.js +0 -4
- package/dist/cjs/components/FieldCode/hooks/index.d.ts +0 -4
- package/dist/cjs/components/FieldCode/hooks/index.js +0 -20
- package/dist/cjs/components/FieldCode/hooks/useCodeInput.d.ts +0 -22
- package/dist/cjs/components/FieldCode/hooks/useCodeInput.js +0 -98
- package/dist/cjs/components/FieldCode/hooks/useFieldCodeValidate.d.ts +0 -8
- package/dist/cjs/components/FieldCode/hooks/useFieldCodeValidate.js +0 -24
- package/dist/cjs/components/FieldCode/hooks/useFieldHelpers.d.ts +0 -12
- package/dist/cjs/components/FieldCode/hooks/useFieldHelpers.js +0 -30
- package/dist/cjs/components/FieldCode/hooks/useFocusCell.d.ts +0 -5
- package/dist/cjs/components/FieldCode/hooks/useFocusCell.js +0 -22
- package/dist/cjs/components/FieldCode/index.d.ts +0 -2
- package/dist/cjs/components/FieldCode/index.js +0 -20
- package/dist/cjs/components/FieldCode/styles.module.css +0 -37
- package/dist/cjs/components/FieldCode/utils.d.ts +0 -6
- package/dist/cjs/components/FieldCode/utils.js +0 -21
- package/dist/esm/components/FieldCode/FieldCode.d.ts +0 -32
- package/dist/esm/components/FieldCode/FieldCode.js +0 -39
- package/dist/esm/components/FieldCode/components/Cell/Cell.d.ts +0 -7
- package/dist/esm/components/FieldCode/components/Cell/Cell.js +0 -21
- package/dist/esm/components/FieldCode/components/Cell/index.d.ts +0 -1
- package/dist/esm/components/FieldCode/components/Cell/index.js +0 -1
- package/dist/esm/components/FieldCode/components/Cell/styles.module.css +0 -19
- package/dist/esm/components/FieldCode/components/ResendCode/ResendCode.d.ts +0 -8
- package/dist/esm/components/FieldCode/components/ResendCode/ResendCode.js +0 -26
- package/dist/esm/components/FieldCode/components/ResendCode/index.d.ts +0 -1
- package/dist/esm/components/FieldCode/components/ResendCode/index.js +0 -1
- package/dist/esm/components/FieldCode/components/ResendCode/utils.d.ts +0 -1
- package/dist/esm/components/FieldCode/components/ResendCode/utils.js +0 -5
- package/dist/esm/components/FieldCode/components/index.d.ts +0 -2
- package/dist/esm/components/FieldCode/components/index.js +0 -2
- package/dist/esm/components/FieldCode/constants.d.ts +0 -1
- package/dist/esm/components/FieldCode/constants.js +0 -1
- package/dist/esm/components/FieldCode/hooks/index.d.ts +0 -4
- package/dist/esm/components/FieldCode/hooks/index.js +0 -4
- package/dist/esm/components/FieldCode/hooks/useCodeInput.d.ts +0 -22
- package/dist/esm/components/FieldCode/hooks/useCodeInput.js +0 -95
- package/dist/esm/components/FieldCode/hooks/useFieldCodeValidate.d.ts +0 -8
- package/dist/esm/components/FieldCode/hooks/useFieldCodeValidate.js +0 -21
- package/dist/esm/components/FieldCode/hooks/useFieldHelpers.d.ts +0 -12
- package/dist/esm/components/FieldCode/hooks/useFieldHelpers.js +0 -27
- package/dist/esm/components/FieldCode/hooks/useFocusCell.d.ts +0 -5
- package/dist/esm/components/FieldCode/hooks/useFocusCell.js +0 -19
- package/dist/esm/components/FieldCode/index.d.ts +0 -2
- package/dist/esm/components/FieldCode/index.js +0 -2
- package/dist/esm/components/FieldCode/styles.module.css +0 -37
- package/dist/esm/components/FieldCode/utils.d.ts +0 -6
- package/dist/esm/components/FieldCode/utils.js +0 -13
- package/src/components/FieldCode/FieldCode.tsx +0 -129
- package/src/components/FieldCode/components/Cell/Cell.tsx +0 -35
- package/src/components/FieldCode/components/Cell/index.ts +0 -1
- package/src/components/FieldCode/components/Cell/styles.module.scss +0 -24
- package/src/components/FieldCode/components/ResendCode/ResendCode.tsx +0 -36
- package/src/components/FieldCode/components/ResendCode/index.ts +0 -1
- package/src/components/FieldCode/components/ResendCode/utils.ts +0 -5
- package/src/components/FieldCode/components/index.ts +0 -2
- package/src/components/FieldCode/constants.ts +0 -1
- package/src/components/FieldCode/hooks/index.ts +0 -4
- package/src/components/FieldCode/hooks/useCodeInput.ts +0 -147
- package/src/components/FieldCode/hooks/useFieldCodeValidate.ts +0 -35
- package/src/components/FieldCode/hooks/useFieldHelpers.ts +0 -44
- package/src/components/FieldCode/hooks/useFocusCell.ts +0 -29
- package/src/components/FieldCode/index.ts +0 -2
- package/src/components/FieldCode/styles.module.scss +0 -42
- package/src/components/FieldCode/utils.ts +0 -23
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-ru/uikit-product-fields-predefined",
|
|
3
3
|
"title": "Fields Predefined",
|
|
4
|
-
"version": "3.0.3
|
|
4
|
+
"version": "3.0.3",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"*.css",
|
|
7
7
|
"*.woff",
|
|
@@ -32,16 +32,14 @@
|
|
|
32
32
|
},
|
|
33
33
|
"scripts": {},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@cloud-ru/uikit-product-icons": "17.
|
|
36
|
-
"@cloud-ru/uikit-product-mobile-dropdown": "2.1.
|
|
37
|
-
"@cloud-ru/uikit-product-mobile-fields": "2.1.
|
|
38
|
-
"@cloud-ru/uikit-product-mobile-modal": "2.1.
|
|
35
|
+
"@cloud-ru/uikit-product-icons": "17.4.0",
|
|
36
|
+
"@cloud-ru/uikit-product-mobile-dropdown": "2.1.15",
|
|
37
|
+
"@cloud-ru/uikit-product-mobile-fields": "2.1.4",
|
|
38
|
+
"@cloud-ru/uikit-product-mobile-modal": "2.1.5",
|
|
39
39
|
"@cloud-ru/uikit-product-utils": "9.1.0",
|
|
40
|
-
"@siberiacancode/reactuse": "0.3.22",
|
|
41
40
|
"@snack-uikit/attachment": "0.4.40",
|
|
42
41
|
"@snack-uikit/button": "0.19.16",
|
|
43
42
|
"@snack-uikit/drop-zone": "0.9.6",
|
|
44
|
-
"@snack-uikit/fields": "0.51.15",
|
|
45
43
|
"@snack-uikit/icon-predefined": "0.7.3",
|
|
46
44
|
"@snack-uikit/input-private": "4.8.8",
|
|
47
45
|
"@snack-uikit/scroll": "0.11.0",
|
|
@@ -50,8 +48,7 @@
|
|
|
50
48
|
"awesome-phonenumber": "7.5.0",
|
|
51
49
|
"classnames": "2.5.1",
|
|
52
50
|
"merge-refs": "1.2.2",
|
|
53
|
-
"react-imask": "7.6.1"
|
|
54
|
-
"sass": "1.80.4"
|
|
51
|
+
"react-imask": "7.6.1"
|
|
55
52
|
},
|
|
56
53
|
"devDependencies": {
|
|
57
54
|
"@types/merge-refs": "1.0.0",
|
|
@@ -62,5 +59,5 @@
|
|
|
62
59
|
"react-hook-form": ">=7.51.0",
|
|
63
60
|
"yup": ">=0.32.0"
|
|
64
61
|
},
|
|
65
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "447f780b5e9b4f1f4c57fdc2eef2a96858754c75"
|
|
66
63
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { FieldDecoratorProps } from '@snack-uikit/fields';
|
|
2
|
-
import { type ResendCodeProps } from './components';
|
|
3
|
-
import { UseCodeInputParams } from './hooks';
|
|
4
|
-
export type FieldCodeRef = {
|
|
5
|
-
/** Перенести фокус на ячейку с индексом `index` */
|
|
6
|
-
moveFocus: (index: number) => void;
|
|
7
|
-
/** Убрать фокус со всех ячеек кода */
|
|
8
|
-
blurFields: () => void;
|
|
9
|
-
/** Сбросить значение кода */
|
|
10
|
-
resetCode: () => void;
|
|
11
|
-
};
|
|
12
|
-
/** Собственные пропсы `FieldCode` */
|
|
13
|
-
export type FieldCodeOwnProps = {
|
|
14
|
-
/** CSS-класс компонента */
|
|
15
|
-
className?: string;
|
|
16
|
-
/** CSS-класс ячейки кода */
|
|
17
|
-
cellClassName?: string;
|
|
18
|
-
/** Позиции, после которых нужно вставить пробел (индексы символов, после которых будет пробел) */
|
|
19
|
-
spacing?: number[];
|
|
20
|
-
/** Подсветить пустые символы кода */
|
|
21
|
-
showEmptyChars?: boolean;
|
|
22
|
-
/** Компонент отправки нового кода */
|
|
23
|
-
resendCode?: ResendCodeProps;
|
|
24
|
-
/** Отключить автофокус (при монтировании, сбросе и при ошибке валидации) */
|
|
25
|
-
isMobile: boolean;
|
|
26
|
-
/** Сообщение при неверном коде, если не передан свой `error` */
|
|
27
|
-
invalidCode?: string;
|
|
28
|
-
/** Растягивать ячейки на всю доступную ширину; иначе фиксированная ширина по `size` */
|
|
29
|
-
stretchCells?: boolean;
|
|
30
|
-
};
|
|
31
|
-
export type FieldCodeProps = FieldCodeOwnProps & Omit<UseCodeInputParams, 'moveFocus'> & Pick<FieldDecoratorProps, 'size' | 'disabled' | 'label' | 'error' | 'data-test-id'>;
|
|
32
|
-
export declare const FieldCode: import("react").ForwardRefExoticComponent<FieldCodeOwnProps & Omit<UseCodeInputParams, "moveFocus"> & Pick<FieldDecoratorProps, "size" | "label" | "error" | "disabled" | "data-test-id"> & import("react").RefAttributes<FieldCodeRef>>;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.FieldCode = void 0;
|
|
7
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
-
const classnames_1 = __importDefault(require("classnames"));
|
|
9
|
-
const react_1 = require("react");
|
|
10
|
-
const fields_1 = require("@snack-uikit/fields");
|
|
11
|
-
const components_1 = require("./components");
|
|
12
|
-
const hooks_1 = require("./hooks");
|
|
13
|
-
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
14
|
-
const utils_1 = require("./utils");
|
|
15
|
-
exports.FieldCode = (0, react_1.forwardRef)(function FieldCode(props, ref) {
|
|
16
|
-
var _a;
|
|
17
|
-
const { codeLength, className, cellClassName, value, onChange, spacing, onComplete, size, disabled, label, error, invalidCode, showEmptyChars, resendCode, isMobile, stretchCells = false, 'data-test-id': dataTestId, } = props;
|
|
18
|
-
const { inputsRef, moveFocus, blurFields } = (0, hooks_1.useFocusCell)(codeLength);
|
|
19
|
-
const { code, cellHandlers, onChangeCode } = (0, hooks_1.useCodeInput)({ value, onChange, codeLength, moveFocus, onComplete });
|
|
20
|
-
const { resetCode } = (0, hooks_1.useFieldHelpers)({
|
|
21
|
-
onChangeCode,
|
|
22
|
-
isMobile,
|
|
23
|
-
moveFocus,
|
|
24
|
-
showEmptyChars,
|
|
25
|
-
code,
|
|
26
|
-
codeLength,
|
|
27
|
-
});
|
|
28
|
-
(0, react_1.useImperativeHandle)(ref, () => ({
|
|
29
|
-
moveFocus,
|
|
30
|
-
blurFields,
|
|
31
|
-
resetCode,
|
|
32
|
-
}), [moveFocus, blurFields, resetCode]);
|
|
33
|
-
const resolvedError = error !== null && error !== void 0 ? error : invalidCode;
|
|
34
|
-
const resolvedDecoratorProps = {
|
|
35
|
-
label,
|
|
36
|
-
disabled,
|
|
37
|
-
size,
|
|
38
|
-
error: resolvedError,
|
|
39
|
-
};
|
|
40
|
-
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, classnames_1.default)(styles_module_scss_1.default.fieldCode, className), "data-stretch-cells": stretchCells || undefined }, (dataTestId ? { 'data-test-id': dataTestId } : undefined), { children: [(0, jsx_runtime_1.jsx)(fields_1.FieldDecorator, Object.assign({ className: styles_module_scss_1.default.fieldDecorator }, resolvedDecoratorProps, { children: (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.codeContainer, "data-size": size, "data-stretch-cells": stretchCells || undefined, children: code.map((char, index) => ((0, jsx_runtime_1.jsx)(components_1.Cell, { ref: inputRef => {
|
|
41
|
-
if (inputRef) {
|
|
42
|
-
inputsRef.current[index] = inputRef;
|
|
43
|
-
}
|
|
44
|
-
}, className: (0, classnames_1.default)((spacing === null || spacing === void 0 ? void 0 : spacing.includes(index)) && styles_module_scss_1.default.cellSpacing, cellClassName), stretchCells: stretchCells, size: size, value: char, disabled: disabled, autoComplete: index === 0 ? 'one-time-code' : undefined, onKeyDown: e => cellHandlers.onKeyDown(e, index), onPaste: cellHandlers.onPaste, onChange: e => cellHandlers.onChange(e, index), validationState: (0, utils_1.getCellValidationState)(char, showEmptyChars, Boolean(resolvedError)) }, index))) }) })), resendCode ? (0, jsx_runtime_1.jsx)(components_1.ResendCode, Object.assign({}, resendCode, { size: (_a = resendCode.size) !== null && _a !== void 0 ? _a : size })) : null] })));
|
|
45
|
-
});
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { FieldTextProps } from '@snack-uikit/fields';
|
|
2
|
-
export declare const Cell: import("react").ForwardRefExoticComponent<{
|
|
3
|
-
/** CSS-класс ячейки кода */
|
|
4
|
-
className?: string;
|
|
5
|
-
/** Растягивать ячейку на всю доступную ширину */
|
|
6
|
-
stretchCells?: boolean;
|
|
7
|
-
} & Pick<FieldTextProps, "size" | "onPaste" | "onChange" | "onKeyDown" | "value" | "disabled" | "autoComplete" | "validationState"> & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Cell = void 0;
|
|
18
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
-
const classnames_1 = __importDefault(require("classnames"));
|
|
20
|
-
const react_1 = require("react");
|
|
21
|
-
const fields_1 = require("@snack-uikit/fields");
|
|
22
|
-
const constants_1 = require("../../constants");
|
|
23
|
-
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
24
|
-
exports.Cell = (0, react_1.forwardRef)((props, ref) => {
|
|
25
|
-
const { className, size, stretchCells, value } = props, fieldCellProps = __rest(props, ["className", "size", "stretchCells", "value"]);
|
|
26
|
-
return ((0, jsx_runtime_1.jsx)(fields_1.FieldText, Object.assign({ inputMode: 'numeric', ref: ref, className: (0, classnames_1.default)(styles_module_scss_1.default.cell, className), "data-size": size, "data-stretch-cells": stretchCells || undefined, showClearButton: false, value: value === constants_1.ZERO_WIDTH_SPACE ? '' : value, size: size }, fieldCellProps)));
|
|
27
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Cell';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./Cell"), exports);
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
.cell{
|
|
2
|
-
flex-shrink:0;
|
|
3
|
-
}
|
|
4
|
-
.cell input{
|
|
5
|
-
text-align:center;
|
|
6
|
-
}
|
|
7
|
-
.cell[data-size=s]:not([data-stretch-cells]){
|
|
8
|
-
width:32px;
|
|
9
|
-
}
|
|
10
|
-
.cell[data-size=m]:not([data-stretch-cells]){
|
|
11
|
-
width:40px;
|
|
12
|
-
}
|
|
13
|
-
.cell[data-size=l]:not([data-stretch-cells]){
|
|
14
|
-
width:52px;
|
|
15
|
-
}
|
|
16
|
-
.cell[data-stretch-cells]{
|
|
17
|
-
flex:1 1 0;
|
|
18
|
-
min-width:0;
|
|
19
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ButtonFunctionProps } from '@snack-uikit/button';
|
|
2
|
-
export type ResendCodeProps = {
|
|
3
|
-
/** Колбек отправки нового кода */
|
|
4
|
-
onResend: () => void;
|
|
5
|
-
/** Количество секунд до следующего отправления кода */
|
|
6
|
-
secondsToNextResend: number;
|
|
7
|
-
} & Pick<ButtonFunctionProps, 'size' | 'disabled'>;
|
|
8
|
-
export declare function ResendCode(props: ResendCodeProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.ResendCode = ResendCode;
|
|
15
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
|
-
const uikit_product_icons_1 = require("@cloud-ru/uikit-product-icons");
|
|
17
|
-
const uikit_product_locale_1 = require("@cloud-ru/uikit-product-locale");
|
|
18
|
-
const button_1 = require("@snack-uikit/button");
|
|
19
|
-
const utils_1 = require("./utils");
|
|
20
|
-
function ResendCode(props) {
|
|
21
|
-
const { onResend, secondsToNextResend } = props, buttonProps = __rest(props, ["onResend", "secondsToNextResend"]);
|
|
22
|
-
const { t } = (0, uikit_product_locale_1.useLocale)('FieldsPredefined');
|
|
23
|
-
const isResendCodeWithVia = secondsToNextResend > 0;
|
|
24
|
-
return ((0, jsx_runtime_1.jsx)(button_1.ButtonFunction, Object.assign({ label: isResendCodeWithVia
|
|
25
|
-
? t('FieldCode.resendCodeButtons.resendCodeWithVia', {
|
|
26
|
-
timer: (0, utils_1.formatSecondsAsMmSs)(secondsToNextResend),
|
|
27
|
-
})
|
|
28
|
-
: t('FieldCode.resendCodeButtons.resendCode'), onClick: onResend, icon: (0, jsx_runtime_1.jsx)(uikit_product_icons_1.UpdateSVG, {}), iconPosition: 'before', disabled: isResendCodeWithVia !== null && isResendCodeWithVia !== void 0 ? isResendCodeWithVia : buttonProps.disabled }, buttonProps)));
|
|
29
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './ResendCode';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./ResendCode"), exports);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function formatSecondsAsMmSs(totalSeconds: number): string;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatSecondsAsMmSs = formatSecondsAsMmSs;
|
|
4
|
-
function formatSecondsAsMmSs(totalSeconds) {
|
|
5
|
-
const minutes = Math.floor(totalSeconds / 60);
|
|
6
|
-
const seconds = totalSeconds % 60;
|
|
7
|
-
return `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
|
|
8
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./Cell"), exports);
|
|
18
|
-
__exportStar(require("./ResendCode"), exports);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const ZERO_WIDTH_SPACE = "\u200B";
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./useCodeInput"), exports);
|
|
18
|
-
__exportStar(require("./useFieldCodeValidate"), exports);
|
|
19
|
-
__exportStar(require("./useFocusCell"), exports);
|
|
20
|
-
__exportStar(require("./useFieldHelpers"), exports);
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ClipboardEvent, KeyboardEvent } from 'react';
|
|
2
|
-
export type UseCodeInputParams = {
|
|
3
|
-
/** Количество цифр в коде (ожидается целое ≥ 1) */
|
|
4
|
-
codeLength: number;
|
|
5
|
-
/** Значение кода */
|
|
6
|
-
value?: string;
|
|
7
|
-
/** Колбек изменения значения */
|
|
8
|
-
onChange?: (code: string) => void;
|
|
9
|
-
/** Функция фокуса */
|
|
10
|
-
moveFocus: (index: number) => void;
|
|
11
|
-
/** Колбек достижения ввода всех символов кода */
|
|
12
|
-
onComplete?: (code: string) => void;
|
|
13
|
-
};
|
|
14
|
-
export declare function useCodeInput(params: UseCodeInputParams): {
|
|
15
|
-
code: string[];
|
|
16
|
-
cellHandlers: {
|
|
17
|
-
onKeyDown: (e: KeyboardEvent<HTMLInputElement>, index: number) => void;
|
|
18
|
-
onPaste: (e: ClipboardEvent<HTMLInputElement>) => void;
|
|
19
|
-
onChange: (code: string, index: number) => void;
|
|
20
|
-
};
|
|
21
|
-
onChangeCode: (value: any, ...args: any[]) => any | void;
|
|
22
|
-
};
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useCodeInput = useCodeInput;
|
|
4
|
-
const reactuse_1 = require("@siberiacancode/reactuse");
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
const utils_1 = require("@snack-uikit/utils");
|
|
7
|
-
const constants_1 = require("../constants");
|
|
8
|
-
const utils_2 = require("../utils");
|
|
9
|
-
const buildCodeArray = (str, codeLength) => Array.from({ length: codeLength }, (_, idx) => str[idx] || constants_1.ZERO_WIDTH_SPACE);
|
|
10
|
-
function useCodeInput(params) {
|
|
11
|
-
const { value: valueProp, onChange: onChangeProp, codeLength, moveFocus, onComplete } = params;
|
|
12
|
-
const [value = '', onChange] = (0, utils_1.useValueControl)({
|
|
13
|
-
value: valueProp,
|
|
14
|
-
onChange: onChangeProp,
|
|
15
|
-
defaultValue: '',
|
|
16
|
-
});
|
|
17
|
-
const codeRef = (0, reactuse_1.useRefState)(buildCodeArray(value, codeLength));
|
|
18
|
-
const updateCodeByIndex = (0, react_1.useCallback)((index, newChar) => {
|
|
19
|
-
codeRef.current[index] = newChar;
|
|
20
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(codeRef.current.join(''));
|
|
21
|
-
}, [codeRef, onChange]);
|
|
22
|
-
const updateFullCode = (0, react_1.useCallback)((newCode) => {
|
|
23
|
-
codeRef.current = newCode.split('');
|
|
24
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(newCode);
|
|
25
|
-
moveFocus(codeLength - 1);
|
|
26
|
-
onComplete === null || onComplete === void 0 ? void 0 : onComplete(newCode);
|
|
27
|
-
}, [codeLength, codeRef, moveFocus, onChange, onComplete]);
|
|
28
|
-
const handleAfterCellUpdate = (0, react_1.useCallback)((index) => {
|
|
29
|
-
const normalizedCode = codeRef.current.join('');
|
|
30
|
-
const isLastInput = index === codeLength - 1;
|
|
31
|
-
const isAllInputsFilled = (0, utils_2.isStringCodeLength)(normalizedCode, codeLength);
|
|
32
|
-
if (!isLastInput) {
|
|
33
|
-
moveFocus(index + 1);
|
|
34
|
-
}
|
|
35
|
-
else if (isAllInputsFilled) {
|
|
36
|
-
onComplete === null || onComplete === void 0 ? void 0 : onComplete(normalizedCode);
|
|
37
|
-
}
|
|
38
|
-
}, [codeLength, codeRef, moveFocus, onComplete]);
|
|
39
|
-
const deleteChar = (0, react_1.useCallback)((index) => {
|
|
40
|
-
if (codeRef.current[index] && !(0, utils_2.isZeroWidthSpace)(codeRef.current[index])) {
|
|
41
|
-
updateCodeByIndex(index, constants_1.ZERO_WIDTH_SPACE);
|
|
42
|
-
}
|
|
43
|
-
else if (index > 0) {
|
|
44
|
-
moveFocus(index - 1);
|
|
45
|
-
}
|
|
46
|
-
}, [codeRef, moveFocus, updateCodeByIndex]);
|
|
47
|
-
const onAutoCompleteInput = (0, react_1.useCallback)((code, index) => {
|
|
48
|
-
if ((0, utils_2.isStringCodeLength)(code, codeLength)) {
|
|
49
|
-
updateFullCode(code);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
if (!(0, utils_2.isNumberChar)(code)) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
updateCodeByIndex(index, code);
|
|
56
|
-
handleAfterCellUpdate(index);
|
|
57
|
-
}, [codeLength, handleAfterCellUpdate, updateCodeByIndex, updateFullCode]);
|
|
58
|
-
const onKeyDown = (0, react_1.useCallback)((e, index) => {
|
|
59
|
-
switch (e.key) {
|
|
60
|
-
case 'ArrowLeft':
|
|
61
|
-
moveFocus(index - 1);
|
|
62
|
-
break;
|
|
63
|
-
case 'ArrowRight':
|
|
64
|
-
moveFocus(index + 1);
|
|
65
|
-
break;
|
|
66
|
-
case 'Backspace':
|
|
67
|
-
deleteChar(index);
|
|
68
|
-
break;
|
|
69
|
-
default:
|
|
70
|
-
if ((0, utils_2.isNumberChar)(e.key)) {
|
|
71
|
-
e.preventDefault();
|
|
72
|
-
updateCodeByIndex(index, e.key);
|
|
73
|
-
handleAfterCellUpdate(index);
|
|
74
|
-
}
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
}, [deleteChar, handleAfterCellUpdate, moveFocus, updateCodeByIndex]);
|
|
78
|
-
const onPaste = (0, react_1.useCallback)((e) => {
|
|
79
|
-
var _a;
|
|
80
|
-
const codeInput = (_a = e === null || e === void 0 ? void 0 : e.clipboardData.getData('text')) !== null && _a !== void 0 ? _a : '';
|
|
81
|
-
if (!(0, utils_2.isStringCodeLength)(codeInput, codeLength)) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
updateFullCode(codeInput);
|
|
85
|
-
}, [codeLength, updateFullCode]);
|
|
86
|
-
(0, react_1.useEffect)(() => {
|
|
87
|
-
codeRef.current = buildCodeArray(value, codeLength);
|
|
88
|
-
}, [codeLength, codeRef, value]);
|
|
89
|
-
return {
|
|
90
|
-
code: codeRef.current,
|
|
91
|
-
cellHandlers: {
|
|
92
|
-
onKeyDown,
|
|
93
|
-
onPaste,
|
|
94
|
-
onChange: onAutoCompleteInput,
|
|
95
|
-
},
|
|
96
|
-
onChangeCode: onChange,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export type UseFieldCodeValidateParams = {
|
|
2
|
-
/** Ожидаемая длина кода (цифр) */
|
|
3
|
-
codeLength: number;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* Возвращает функцию валидации значения кода (пусто / неполный код).
|
|
7
|
-
*/
|
|
8
|
-
export declare function useFieldCodeValidate(params: UseFieldCodeValidateParams): (value?: string | number) => string | undefined;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useFieldCodeValidate = useFieldCodeValidate;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const uikit_product_locale_1 = require("@cloud-ru/uikit-product-locale");
|
|
6
|
-
const utils_1 = require("../utils");
|
|
7
|
-
/**
|
|
8
|
-
* Возвращает функцию валидации значения кода (пусто / неполный код).
|
|
9
|
-
*/
|
|
10
|
-
function useFieldCodeValidate(params) {
|
|
11
|
-
const { codeLength } = params;
|
|
12
|
-
const { t } = (0, uikit_product_locale_1.useLocale)('FieldsPredefined');
|
|
13
|
-
return (0, react_1.useCallback)((value) => {
|
|
14
|
-
const str = value != null ? String(value) : '';
|
|
15
|
-
const digits = str.split('').filter(utils_1.isNumberChar).join('');
|
|
16
|
-
if (digits.length === 0) {
|
|
17
|
-
return t('FieldCode.required');
|
|
18
|
-
}
|
|
19
|
-
if (digits.length < codeLength) {
|
|
20
|
-
return t('FieldCode.minLength', { count: codeLength });
|
|
21
|
-
}
|
|
22
|
-
return undefined;
|
|
23
|
-
}, [codeLength, t]);
|
|
24
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
type UseFieldHelpersParams = {
|
|
2
|
-
onChangeCode: (code: string) => void;
|
|
3
|
-
moveFocus: (index: number) => void;
|
|
4
|
-
isMobile?: boolean;
|
|
5
|
-
showEmptyChars?: boolean;
|
|
6
|
-
code: readonly string[];
|
|
7
|
-
codeLength: number;
|
|
8
|
-
};
|
|
9
|
-
export declare function useFieldHelpers(params: UseFieldHelpersParams): {
|
|
10
|
-
resetCode: () => void;
|
|
11
|
-
};
|
|
12
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useFieldHelpers = useFieldHelpers;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
function useFieldHelpers(params) {
|
|
7
|
-
const { onChangeCode, moveFocus, isMobile = false, showEmptyChars, code, codeLength } = params;
|
|
8
|
-
const resetCode = (0, react_1.useCallback)(() => {
|
|
9
|
-
onChangeCode('');
|
|
10
|
-
if (!isMobile) {
|
|
11
|
-
moveFocus(0);
|
|
12
|
-
}
|
|
13
|
-
}, [isMobile, moveFocus, onChangeCode]);
|
|
14
|
-
(0, react_1.useEffect)(() => {
|
|
15
|
-
if (!isMobile) {
|
|
16
|
-
moveFocus(0);
|
|
17
|
-
}
|
|
18
|
-
}, [isMobile, moveFocus]);
|
|
19
|
-
(0, react_1.useEffect)(() => {
|
|
20
|
-
if (isMobile || !showEmptyChars) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const emptyIndex = (0, utils_1.getFirstEmptyCellIndex)(code);
|
|
24
|
-
if (emptyIndex >= 0) {
|
|
25
|
-
moveFocus(emptyIndex);
|
|
26
|
-
}
|
|
27
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
|
-
}, [showEmptyChars, isMobile, moveFocus, codeLength]);
|
|
29
|
-
return { resetCode };
|
|
30
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useFocusCell = useFocusCell;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
function useFocusCell(codeLength) {
|
|
6
|
-
const inputsRef = (0, react_1.useRef)([]);
|
|
7
|
-
const focusInput = (0, react_1.useCallback)((index) => {
|
|
8
|
-
var _a;
|
|
9
|
-
(_a = inputsRef.current[index]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
10
|
-
}, [inputsRef]);
|
|
11
|
-
const moveFocus = (0, react_1.useCallback)((newIndex) => {
|
|
12
|
-
if (newIndex >= 0 && newIndex < codeLength) {
|
|
13
|
-
focusInput(newIndex);
|
|
14
|
-
}
|
|
15
|
-
}, [codeLength, focusInput]);
|
|
16
|
-
const blurFields = (0, react_1.useCallback)(() => {
|
|
17
|
-
inputsRef.current.forEach(input => {
|
|
18
|
-
input === null || input === void 0 ? void 0 : input.blur();
|
|
19
|
-
});
|
|
20
|
-
}, [inputsRef]);
|
|
21
|
-
return { inputsRef, moveFocus, blurFields };
|
|
22
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.useFieldCodeValidate = void 0;
|
|
18
|
-
__exportStar(require("./FieldCode"), exports);
|
|
19
|
-
var useFieldCodeValidate_1 = require("./hooks/useFieldCodeValidate");
|
|
20
|
-
Object.defineProperty(exports, "useFieldCodeValidate", { enumerable: true, get: function () { return useFieldCodeValidate_1.useFieldCodeValidate; } });
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
.fieldCode{
|
|
2
|
-
display:flex;
|
|
3
|
-
flex-direction:column;
|
|
4
|
-
align-items:center;
|
|
5
|
-
gap:8px;
|
|
6
|
-
}
|
|
7
|
-
.fieldCode[data-stretch-cells]{
|
|
8
|
-
width:100%;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
.fieldDecorator{
|
|
12
|
-
width:unset;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.codeContainer{
|
|
16
|
-
display:flex;
|
|
17
|
-
justify-content:center;
|
|
18
|
-
}
|
|
19
|
-
.codeContainer[data-size=s]{
|
|
20
|
-
gap:8px;
|
|
21
|
-
}
|
|
22
|
-
.codeContainer[data-size=m]{
|
|
23
|
-
gap:8px;
|
|
24
|
-
}
|
|
25
|
-
.codeContainer[data-size=l]{
|
|
26
|
-
gap:12px;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
.cellSpacing[data-size=s]{
|
|
30
|
-
margin-right:8px;
|
|
31
|
-
}
|
|
32
|
-
.cellSpacing[data-size=m]{
|
|
33
|
-
margin-right:8px;
|
|
34
|
-
}
|
|
35
|
-
.cellSpacing[data-size=l]{
|
|
36
|
-
margin-right:12px;
|
|
37
|
-
}
|