@alfalab/core-components-pattern-lock 1.0.2 → 1.1.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/Component.d.ts +2 -10
- package/Component.js +16 -9
- package/cssm/Component.d.ts +2 -10
- package/cssm/Component.js +15 -8
- package/cssm/index.js +3 -1
- package/cssm/index.module.css +40 -14
- package/cssm/typings.d.ts +22 -2
- package/cssm/utils.d.ts +10 -0
- package/cssm/utils.js +69 -7
- package/esm/Component.d.ts +2 -10
- package/esm/Component.js +15 -8
- package/esm/index.css +41 -15
- package/esm/index.js +3 -1
- package/esm/typings.d.ts +22 -2
- package/esm/utils.d.ts +10 -0
- package/esm/utils.js +68 -2
- package/index.css +41 -15
- package/index.js +3 -1
- package/modern/Component.d.ts +2 -10
- package/modern/Component.js +12 -6
- package/modern/index.css +41 -15
- package/modern/index.js +1 -0
- package/modern/typings.d.ts +22 -2
- package/package.json +6 -4
- package/typings.d.ts +22 -2
- package/utils.d.ts +10 -0
- package/utils.js +69 -7
- package/cssm/utils-5745f540.d.ts +0 -43
- package/cssm/utils-5745f540.js +0 -112
- package/esm/utils-30ae747f.d.ts +0 -43
- package/esm/utils-30ae747f.js +0 -106
- package/utils-a2a5e3e1.d.ts +0 -43
- package/utils-a2a5e3e1.js +0 -112
package/Component.d.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { TPatternLockInstance } from 'react-canvas-pattern-lock';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
error?: React.ReactNode;
|
|
7
|
-
dataTestId?: string | undefined;
|
|
8
|
-
observeTokens?: boolean | undefined;
|
|
9
|
-
observerParams?: {
|
|
10
|
-
getTarget?: (() => Node) | undefined;
|
|
11
|
-
options?: MutationObserverInit | undefined;
|
|
12
|
-
} | undefined;
|
|
13
|
-
} & Omit<import("react-canvas-pattern-lock").ReactPatternLockProps, "theme" | "width" | "height" | "rows" | "cols"> & React.RefAttributes<TPatternLockInstance>>;
|
|
4
|
+
import { PatternLockProps } from "./typings";
|
|
5
|
+
declare const PatternLock: React.ForwardRefExoticComponent<PatternLockProps & React.RefAttributes<TPatternLockInstance>>;
|
|
14
6
|
export { PatternLock };
|
package/Component.js
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var tslib = require('tslib');
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var reactCanvasPatternLock = require('react-canvas-pattern-lock');
|
|
6
6
|
var cn = require('classnames');
|
|
7
|
+
var coreComponentsButton = require('@alfalab/core-components-button');
|
|
7
8
|
var coreComponentsGap = require('@alfalab/core-components-gap');
|
|
8
9
|
var consts = require('./consts.js');
|
|
10
|
+
var utils = require('./utils.js');
|
|
9
11
|
|
|
10
12
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
11
13
|
|
|
12
14
|
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
13
15
|
var cn__default = /*#__PURE__*/_interopDefaultCompat(cn);
|
|
14
16
|
|
|
15
|
-
var
|
|
17
|
+
var getDataTestId = function (dataTestId, element) {
|
|
18
|
+
var elementPart = element ? "-".concat(element.toLowerCase()) : '';
|
|
19
|
+
return dataTestId ? "".concat(dataTestId).concat(elementPart) : undefined;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
var styles = {"component":"pattern-lock__component_1dmbz","hidden":"pattern-lock__hidden_1dmbz","error":"pattern-lock__error_1dmbz","forgotBtn":"pattern-lock__forgotBtn_1dmbz"};
|
|
16
23
|
require('./index.css')
|
|
17
24
|
|
|
18
25
|
var PatternLock = React.forwardRef(function (_a, ref) {
|
|
19
26
|
var _b;
|
|
20
|
-
var _c = _a.observeTokens, observeTokens = _c === void 0 ? false : _c, _d = _a.observerParams, observerParams = _d === void 0 ? {} : _d, _e = _a.justifyNodes, justifyNodes = _e === void 0 ? 'space-between' : _e, className = _a.className, error = _a.error, dataTestId = _a.dataTestId, restProps =
|
|
21
|
-
var
|
|
27
|
+
var _c = _a.observeTokens, observeTokens = _c === void 0 ? false : _c, _d = _a.observerParams, observerParams = _d === void 0 ? {} : _d, _e = _a.justifyNodes, justifyNodes = _e === void 0 ? 'space-between' : _e, className = _a.className, error = _a.error, dataTestId = _a.dataTestId, _f = _a.forgotCodeBtnText, forgotCodeBtnText = _f === void 0 ? 'Забыли код?' : _f, _g = _a.showForgotCodeBtn, showForgotCodeBtn = _g === void 0 ? false : _g, onForgotBtnClick = _a.onForgotBtnClick, restProps = tslib.__rest(_a, ["observeTokens", "observerParams", "justifyNodes", "className", "error", "dataTestId", "forgotCodeBtnText", "showForgotCodeBtn", "onForgotBtnClick"]);
|
|
28
|
+
var _h = React.useState(), params = _h[0], setParams = _h[1];
|
|
22
29
|
React.useEffect(function () {
|
|
23
30
|
var _a = utils.getSizes(), elementSizes = _a.elementSizes, width = _a.width, height = _a.height;
|
|
24
31
|
setParams({
|
|
@@ -40,7 +47,7 @@ var PatternLock = React.forwardRef(function (_a, ref) {
|
|
|
40
47
|
var prevBgColor = prevState.theme[consts.THEME_STATE.INITIAL].colors.bg;
|
|
41
48
|
var themeChanged = prevBgColor !== utils.getColorByToken(consts.OBSERVABLE_TOKENS.BG);
|
|
42
49
|
if (themeChanged)
|
|
43
|
-
return
|
|
50
|
+
return tslib.__assign(tslib.__assign({}, prevState), { theme: utils.getTheme(elementSizes) });
|
|
44
51
|
return prevState;
|
|
45
52
|
});
|
|
46
53
|
});
|
|
@@ -50,11 +57,11 @@ var PatternLock = React.forwardRef(function (_a, ref) {
|
|
|
50
57
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
51
58
|
}, [observeTokens]);
|
|
52
59
|
return (React__default.default.createElement("div", { className: cn__default.default(styles.component, className, (_b = {}, _b[styles.hidden] = !params, _b)), "data-test-id": dataTestId },
|
|
53
|
-
React__default.default.createElement(coreComponentsGap.Gap, { size: '
|
|
54
|
-
React__default.default.createElement(coreComponentsGap.Gap, { size: 's' }),
|
|
60
|
+
React__default.default.createElement(coreComponentsGap.Gap, { size: 'xs' }),
|
|
55
61
|
React__default.default.createElement("div", { className: styles.error }, error),
|
|
56
|
-
React__default.default.createElement(coreComponentsGap.Gap, { size: '
|
|
57
|
-
React__default.default.createElement(reactCanvasPatternLock.ReactCanvasPatternLock,
|
|
62
|
+
React__default.default.createElement(coreComponentsGap.Gap, { size: '3xl' }),
|
|
63
|
+
React__default.default.createElement(reactCanvasPatternLock.ReactCanvasPatternLock, tslib.__assign({}, restProps, params, { ref: ref, rows: 3, cols: 3, justifyNodes: justifyNodes })),
|
|
64
|
+
showForgotCodeBtn ? (React__default.default.createElement(coreComponentsButton.Button, { view: 'link', className: styles.forgotBtn, onClick: onForgotBtnClick, dataTestId: getDataTestId(dataTestId, 'forgot-code-btn') }, forgotCodeBtnText)) : (React__default.default.createElement("div", { className: styles.forgotBtn }))));
|
|
58
65
|
});
|
|
59
66
|
|
|
60
67
|
exports.PatternLock = PatternLock;
|
package/cssm/Component.d.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { TPatternLockInstance } from 'react-canvas-pattern-lock';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
error?: React.ReactNode;
|
|
7
|
-
dataTestId?: string | undefined;
|
|
8
|
-
observeTokens?: boolean | undefined;
|
|
9
|
-
observerParams?: {
|
|
10
|
-
getTarget?: (() => Node) | undefined;
|
|
11
|
-
options?: MutationObserverInit | undefined;
|
|
12
|
-
} | undefined;
|
|
13
|
-
} & Omit<import("react-canvas-pattern-lock").ReactPatternLockProps, "theme" | "width" | "height" | "rows" | "cols"> & React.RefAttributes<TPatternLockInstance>>;
|
|
4
|
+
import { PatternLockProps } from "./typings";
|
|
5
|
+
declare const PatternLock: React.ForwardRefExoticComponent<PatternLockProps & React.RefAttributes<TPatternLockInstance>>;
|
|
14
6
|
export { PatternLock };
|
package/cssm/Component.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var tslib = require('tslib');
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var reactCanvasPatternLock = require('react-canvas-pattern-lock');
|
|
6
6
|
var cn = require('classnames');
|
|
7
|
+
var coreComponentsButton = require('@alfalab/core-components-button/cssm');
|
|
7
8
|
var coreComponentsGap = require('@alfalab/core-components-gap/cssm');
|
|
8
9
|
var consts = require('./consts.js');
|
|
10
|
+
var utils = require('./utils.js');
|
|
9
11
|
var styles = require('./index.module.css');
|
|
10
12
|
|
|
11
13
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
@@ -14,10 +16,15 @@ var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
|
14
16
|
var cn__default = /*#__PURE__*/_interopDefaultCompat(cn);
|
|
15
17
|
var styles__default = /*#__PURE__*/_interopDefaultCompat(styles);
|
|
16
18
|
|
|
19
|
+
var getDataTestId = function (dataTestId, element) {
|
|
20
|
+
var elementPart = element ? "-".concat(element.toLowerCase()) : '';
|
|
21
|
+
return dataTestId ? "".concat(dataTestId).concat(elementPart) : undefined;
|
|
22
|
+
};
|
|
23
|
+
|
|
17
24
|
var PatternLock = React.forwardRef(function (_a, ref) {
|
|
18
25
|
var _b;
|
|
19
|
-
var _c = _a.observeTokens, observeTokens = _c === void 0 ? false : _c, _d = _a.observerParams, observerParams = _d === void 0 ? {} : _d, _e = _a.justifyNodes, justifyNodes = _e === void 0 ? 'space-between' : _e, className = _a.className, error = _a.error, dataTestId = _a.dataTestId, restProps =
|
|
20
|
-
var
|
|
26
|
+
var _c = _a.observeTokens, observeTokens = _c === void 0 ? false : _c, _d = _a.observerParams, observerParams = _d === void 0 ? {} : _d, _e = _a.justifyNodes, justifyNodes = _e === void 0 ? 'space-between' : _e, className = _a.className, error = _a.error, dataTestId = _a.dataTestId, _f = _a.forgotCodeBtnText, forgotCodeBtnText = _f === void 0 ? 'Забыли код?' : _f, _g = _a.showForgotCodeBtn, showForgotCodeBtn = _g === void 0 ? false : _g, onForgotBtnClick = _a.onForgotBtnClick, restProps = tslib.__rest(_a, ["observeTokens", "observerParams", "justifyNodes", "className", "error", "dataTestId", "forgotCodeBtnText", "showForgotCodeBtn", "onForgotBtnClick"]);
|
|
27
|
+
var _h = React.useState(), params = _h[0], setParams = _h[1];
|
|
21
28
|
React.useEffect(function () {
|
|
22
29
|
var _a = utils.getSizes(), elementSizes = _a.elementSizes, width = _a.width, height = _a.height;
|
|
23
30
|
setParams({
|
|
@@ -39,7 +46,7 @@ var PatternLock = React.forwardRef(function (_a, ref) {
|
|
|
39
46
|
var prevBgColor = prevState.theme[consts.THEME_STATE.INITIAL].colors.bg;
|
|
40
47
|
var themeChanged = prevBgColor !== utils.getColorByToken(consts.OBSERVABLE_TOKENS.BG);
|
|
41
48
|
if (themeChanged)
|
|
42
|
-
return
|
|
49
|
+
return tslib.__assign(tslib.__assign({}, prevState), { theme: utils.getTheme(elementSizes) });
|
|
43
50
|
return prevState;
|
|
44
51
|
});
|
|
45
52
|
});
|
|
@@ -49,11 +56,11 @@ var PatternLock = React.forwardRef(function (_a, ref) {
|
|
|
49
56
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
50
57
|
}, [observeTokens]);
|
|
51
58
|
return (React__default.default.createElement("div", { className: cn__default.default(styles__default.default.component, className, (_b = {}, _b[styles__default.default.hidden] = !params, _b)), "data-test-id": dataTestId },
|
|
52
|
-
React__default.default.createElement(coreComponentsGap.Gap, { size: '
|
|
53
|
-
React__default.default.createElement(coreComponentsGap.Gap, { size: 's' }),
|
|
59
|
+
React__default.default.createElement(coreComponentsGap.Gap, { size: 'xs' }),
|
|
54
60
|
React__default.default.createElement("div", { className: styles__default.default.error }, error),
|
|
55
|
-
React__default.default.createElement(coreComponentsGap.Gap, { size: '
|
|
56
|
-
React__default.default.createElement(reactCanvasPatternLock.ReactCanvasPatternLock,
|
|
61
|
+
React__default.default.createElement(coreComponentsGap.Gap, { size: '3xl' }),
|
|
62
|
+
React__default.default.createElement(reactCanvasPatternLock.ReactCanvasPatternLock, tslib.__assign({}, restProps, params, { ref: ref, rows: 3, cols: 3, justifyNodes: justifyNodes })),
|
|
63
|
+
showForgotCodeBtn ? (React__default.default.createElement(coreComponentsButton.Button, { view: 'link', className: styles__default.default.forgotBtn, onClick: onForgotBtnClick, dataTestId: getDataTestId(dataTestId, 'forgot-code-btn') }, forgotCodeBtnText)) : (React__default.default.createElement("div", { className: styles__default.default.forgotBtn }))));
|
|
57
64
|
});
|
|
58
65
|
|
|
59
66
|
exports.PatternLock = PatternLock;
|
package/cssm/index.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var Component = require('./Component.js');
|
|
4
4
|
var consts = require('./consts.js');
|
|
5
|
-
require('
|
|
5
|
+
require('tslib');
|
|
6
6
|
require('react');
|
|
7
7
|
require('react-canvas-pattern-lock');
|
|
8
8
|
require('classnames');
|
|
9
|
+
require('@alfalab/core-components-button/cssm');
|
|
9
10
|
require('@alfalab/core-components-gap/cssm');
|
|
11
|
+
require('./utils.js');
|
|
10
12
|
require('./index.module.css');
|
|
11
13
|
|
|
12
14
|
|
package/cssm/index.module.css
CHANGED
|
@@ -1,34 +1,39 @@
|
|
|
1
1
|
:root {
|
|
2
|
+
} /* deprecated */ :root {
|
|
2
3
|
--color-light-text-negative: #d91d0b;
|
|
3
|
-
}
|
|
4
|
-
:root {
|
|
4
|
+
} :root {
|
|
5
|
+
} :root {
|
|
6
|
+
} :root {
|
|
5
7
|
|
|
6
8
|
/* Hard */
|
|
7
9
|
|
|
8
10
|
/* Up */
|
|
9
11
|
|
|
10
12
|
/* Hard up */
|
|
11
|
-
}
|
|
12
|
-
:root {
|
|
13
|
+
} :root {
|
|
14
|
+
} :root {
|
|
13
15
|
--gap-xs: 8px;
|
|
16
|
+
--gap-s: 12px;
|
|
14
17
|
--gap-m: 16px;
|
|
18
|
+
--gap-l: 20px;
|
|
15
19
|
--gap-xl: 24px;
|
|
16
|
-
|
|
17
|
-
:root {
|
|
20
|
+
--gap-2xl: 32px;
|
|
21
|
+
} :root {
|
|
22
|
+
} :root {
|
|
23
|
+
--size-xs-height: 40px;
|
|
24
|
+
--size-s-height: 48px;
|
|
25
|
+
--size-m-height: 56px;
|
|
26
|
+
} :root {
|
|
18
27
|
--pattern-lock-max-width: 500px;
|
|
19
|
-
}
|
|
20
|
-
.component {
|
|
28
|
+
} .component {
|
|
21
29
|
max-width: var(--pattern-lock-max-width);
|
|
22
30
|
margin: var(--gap-xs) 0 var(--gap-xl) 0
|
|
23
|
-
}
|
|
24
|
-
.component canvas {
|
|
31
|
+
} .component canvas {
|
|
25
32
|
display: block;
|
|
26
33
|
margin: 0 auto;
|
|
27
|
-
}
|
|
28
|
-
.hidden {
|
|
34
|
+
} .hidden {
|
|
29
35
|
visibility: hidden;
|
|
30
|
-
}
|
|
31
|
-
.error {
|
|
36
|
+
} .error {
|
|
32
37
|
font-size: 16px;
|
|
33
38
|
line-height: 24px;
|
|
34
39
|
font-weight: 400;
|
|
@@ -39,4 +44,25 @@
|
|
|
39
44
|
padding: 0 var(--gap-m);
|
|
40
45
|
min-height: 24px;
|
|
41
46
|
color: var(--color-light-text-negative);
|
|
47
|
+
} .forgotBtn {
|
|
48
|
+
display: block;
|
|
49
|
+
min-height: var(--size-xs-height);
|
|
50
|
+
margin: var(--gap-xl) auto 0;
|
|
51
|
+
} @media screen and (min-width: 360px) {
|
|
52
|
+
.forgotBtn {
|
|
53
|
+
margin-top: var(--gap-2xl);
|
|
54
|
+
min-height: var(--size-s-height);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.component {
|
|
58
|
+
margin-bottom: var(--gap-s);
|
|
59
|
+
}
|
|
60
|
+
} @media screen and (min-width: 390px) {
|
|
61
|
+
.forgotBtn {
|
|
62
|
+
min-height: var(--size-m-height);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.component {
|
|
66
|
+
margin-bottom: var(--gap-l);
|
|
67
|
+
}
|
|
42
68
|
}
|
package/cssm/typings.d.ts
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
1
|
+
import { MouseEvent, ReactNode } from 'react';
|
|
2
2
|
import { ReactPatternLockProps } from 'react-canvas-pattern-lock';
|
|
3
|
+
type ConditionalProps = {
|
|
4
|
+
/**
|
|
5
|
+
* Текст кнопки "забыли код"
|
|
6
|
+
* @default "Забыли код?"
|
|
7
|
+
*/
|
|
8
|
+
showForgotCodeBtn: true;
|
|
9
|
+
/**
|
|
10
|
+
* Текст кнопки "забыли код"
|
|
11
|
+
* @default "Забыли код?"
|
|
12
|
+
*/
|
|
13
|
+
forgotCodeBtnText?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Коллбэк, вызываемый при клике на кнопку "Забыли код"
|
|
16
|
+
*/
|
|
17
|
+
onForgotBtnClick: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
18
|
+
} | {
|
|
19
|
+
showForgotCodeBtn?: false;
|
|
20
|
+
onForgotBtnClick?: never;
|
|
21
|
+
forgotCodeBtnText?: never;
|
|
22
|
+
};
|
|
3
23
|
type PatternLockProps = {
|
|
4
24
|
/**
|
|
5
25
|
* Дополнительный класс.
|
|
@@ -25,7 +45,7 @@ type PatternLockProps = {
|
|
|
25
45
|
getTarget?: () => Node;
|
|
26
46
|
options?: MutationObserverInit;
|
|
27
47
|
};
|
|
28
|
-
} & Omit<ReactPatternLockProps, 'theme' | 'width' | 'height' | 'rows' | 'cols'
|
|
48
|
+
} & Omit<ReactPatternLockProps, 'theme' | 'width' | 'height' | 'rows' | 'cols'> & ConditionalProps;
|
|
29
49
|
type ObservableTokens = {
|
|
30
50
|
ACCENT_INITIAL: string;
|
|
31
51
|
ACCENT_SUCCESS: string;
|
package/cssm/utils.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Theme, ThemeParams } from 'react-canvas-pattern-lock';
|
|
2
|
+
declare function getDefaultObserveTarget(): HTMLHeadElement;
|
|
3
|
+
declare function getColorByToken(token: string): string;
|
|
4
|
+
declare const getSizes: () => {
|
|
5
|
+
elementSizes: ThemeParams['dimens'];
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
};
|
|
9
|
+
declare function getTheme(dimens: ThemeParams['dimens']): Theme;
|
|
10
|
+
export { getDefaultObserveTarget, getColorByToken, getSizes, getTheme };
|
package/cssm/utils.js
CHANGED
|
@@ -1,11 +1,73 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./consts.js');
|
|
3
|
+
var tslib = require('tslib');
|
|
4
|
+
var consts = require('./consts.js');
|
|
5
5
|
|
|
6
|
+
function getDefaultObserveTarget() {
|
|
7
|
+
return document.head;
|
|
8
|
+
}
|
|
9
|
+
function getColorByToken(token) {
|
|
10
|
+
return getComputedStyle(document.documentElement).getPropertyValue(token);
|
|
11
|
+
}
|
|
12
|
+
var getSizes = (function () {
|
|
13
|
+
var COMMON_SIZES = {
|
|
14
|
+
lineWidth: 6,
|
|
15
|
+
nodeRing: 0,
|
|
16
|
+
nodeCore: 12,
|
|
17
|
+
};
|
|
18
|
+
var cachedSize;
|
|
19
|
+
return function () {
|
|
20
|
+
if (cachedSize) {
|
|
21
|
+
return cachedSize;
|
|
22
|
+
}
|
|
23
|
+
if (window.matchMedia('(min-width: 390px)').matches) {
|
|
24
|
+
cachedSize = {
|
|
25
|
+
elementSizes: tslib.__assign(tslib.__assign({}, COMMON_SIZES), { nodeRadius: 43 }),
|
|
26
|
+
width: 322,
|
|
27
|
+
height: 322,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
else if (window.matchMedia('(min-width: 360px)').matches) {
|
|
31
|
+
cachedSize = {
|
|
32
|
+
elementSizes: tslib.__assign(tslib.__assign({}, COMMON_SIZES), { nodeRadius: 38 }),
|
|
33
|
+
width: 292,
|
|
34
|
+
height: 292,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
cachedSize = {
|
|
39
|
+
elementSizes: tslib.__assign(tslib.__assign({}, COMMON_SIZES), { nodeRadius: 32 }),
|
|
40
|
+
width: 240,
|
|
41
|
+
height: 240,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return cachedSize;
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
function getTheme(dimens) {
|
|
48
|
+
var _a;
|
|
49
|
+
var baseColors = {
|
|
50
|
+
primary: getColorByToken(consts.OBSERVABLE_TOKENS.PRIMARY),
|
|
51
|
+
bg: getColorByToken(consts.OBSERVABLE_TOKENS.BG),
|
|
52
|
+
ringBg: getColorByToken(consts.OBSERVABLE_TOKENS.RING_BG_INITIAL),
|
|
53
|
+
};
|
|
54
|
+
return _a = {},
|
|
55
|
+
_a[consts.THEME_STATE.INITIAL] = {
|
|
56
|
+
colors: tslib.__assign(tslib.__assign({}, baseColors), { accent: getColorByToken(consts.OBSERVABLE_TOKENS.ACCENT_INITIAL), selectedRingBg: getColorByToken(consts.OBSERVABLE_TOKENS.SELECTED_RING_BG_INITIAL) }),
|
|
57
|
+
dimens: dimens,
|
|
58
|
+
},
|
|
59
|
+
_a[consts.THEME_STATE.SUCCESS] = {
|
|
60
|
+
colors: tslib.__assign(tslib.__assign({}, baseColors), { accent: getColorByToken(consts.OBSERVABLE_TOKENS.ACCENT_SUCCESS), selectedRingBg: getColorByToken(consts.OBSERVABLE_TOKENS.SELECTED_RING_BG_SUCCESS) }),
|
|
61
|
+
dimens: dimens,
|
|
62
|
+
},
|
|
63
|
+
_a[consts.THEME_STATE.FAILURE] = {
|
|
64
|
+
colors: tslib.__assign(tslib.__assign({}, baseColors), { accent: getColorByToken(consts.OBSERVABLE_TOKENS.ACCENT_FAILURE), selectedRingBg: getColorByToken(consts.OBSERVABLE_TOKENS.SELECTED_RING_BG_FAILURE) }),
|
|
65
|
+
dimens: dimens,
|
|
66
|
+
},
|
|
67
|
+
_a;
|
|
68
|
+
}
|
|
6
69
|
|
|
7
|
-
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
11
|
-
exports.getTheme = utils.getTheme;
|
|
70
|
+
exports.getColorByToken = getColorByToken;
|
|
71
|
+
exports.getDefaultObserveTarget = getDefaultObserveTarget;
|
|
72
|
+
exports.getSizes = getSizes;
|
|
73
|
+
exports.getTheme = getTheme;
|
package/esm/Component.d.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { TPatternLockInstance } from 'react-canvas-pattern-lock';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
error?: React.ReactNode;
|
|
7
|
-
dataTestId?: string | undefined;
|
|
8
|
-
observeTokens?: boolean | undefined;
|
|
9
|
-
observerParams?: {
|
|
10
|
-
getTarget?: (() => Node) | undefined;
|
|
11
|
-
options?: MutationObserverInit | undefined;
|
|
12
|
-
} | undefined;
|
|
13
|
-
} & Omit<import("react-canvas-pattern-lock").ReactPatternLockProps, "theme" | "width" | "height" | "rows" | "cols"> & React.RefAttributes<TPatternLockInstance>>;
|
|
4
|
+
import { PatternLockProps } from "./typings";
|
|
5
|
+
declare const PatternLock: React.ForwardRefExoticComponent<PatternLockProps & React.RefAttributes<TPatternLockInstance>>;
|
|
14
6
|
export { PatternLock };
|
package/esm/Component.js
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __rest, __assign } from 'tslib';
|
|
2
2
|
import React, { forwardRef, useState, useEffect } from 'react';
|
|
3
3
|
import { ReactCanvasPatternLock } from 'react-canvas-pattern-lock';
|
|
4
4
|
import cn from 'classnames';
|
|
5
|
+
import { Button } from '@alfalab/core-components-button/esm';
|
|
5
6
|
import { Gap } from '@alfalab/core-components-gap/esm';
|
|
6
7
|
import { THEME_STATE, OBSERVE_OPTIONS, OBSERVABLE_TOKENS } from './consts.js';
|
|
8
|
+
import { getSizes, getTheme, getColorByToken, getDefaultObserveTarget } from './utils.js';
|
|
7
9
|
|
|
8
|
-
var
|
|
10
|
+
var getDataTestId = function (dataTestId, element) {
|
|
11
|
+
var elementPart = element ? "-".concat(element.toLowerCase()) : '';
|
|
12
|
+
return dataTestId ? "".concat(dataTestId).concat(elementPart) : undefined;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
var styles = {"component":"pattern-lock__component_1dmbz","hidden":"pattern-lock__hidden_1dmbz","error":"pattern-lock__error_1dmbz","forgotBtn":"pattern-lock__forgotBtn_1dmbz"};
|
|
9
16
|
require('./index.css')
|
|
10
17
|
|
|
11
18
|
var PatternLock = forwardRef(function (_a, ref) {
|
|
12
19
|
var _b;
|
|
13
|
-
var _c = _a.observeTokens, observeTokens = _c === void 0 ? false : _c, _d = _a.observerParams, observerParams = _d === void 0 ? {} : _d, _e = _a.justifyNodes, justifyNodes = _e === void 0 ? 'space-between' : _e, className = _a.className, error = _a.error, dataTestId = _a.dataTestId, restProps = __rest(_a, ["observeTokens", "observerParams", "justifyNodes", "className", "error", "dataTestId"]);
|
|
14
|
-
var
|
|
20
|
+
var _c = _a.observeTokens, observeTokens = _c === void 0 ? false : _c, _d = _a.observerParams, observerParams = _d === void 0 ? {} : _d, _e = _a.justifyNodes, justifyNodes = _e === void 0 ? 'space-between' : _e, className = _a.className, error = _a.error, dataTestId = _a.dataTestId, _f = _a.forgotCodeBtnText, forgotCodeBtnText = _f === void 0 ? 'Забыли код?' : _f, _g = _a.showForgotCodeBtn, showForgotCodeBtn = _g === void 0 ? false : _g, onForgotBtnClick = _a.onForgotBtnClick, restProps = __rest(_a, ["observeTokens", "observerParams", "justifyNodes", "className", "error", "dataTestId", "forgotCodeBtnText", "showForgotCodeBtn", "onForgotBtnClick"]);
|
|
21
|
+
var _h = useState(), params = _h[0], setParams = _h[1];
|
|
15
22
|
useEffect(function () {
|
|
16
23
|
var _a = getSizes(), elementSizes = _a.elementSizes, width = _a.width, height = _a.height;
|
|
17
24
|
setParams({
|
|
@@ -43,11 +50,11 @@ var PatternLock = forwardRef(function (_a, ref) {
|
|
|
43
50
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
44
51
|
}, [observeTokens]);
|
|
45
52
|
return (React.createElement("div", { className: cn(styles.component, className, (_b = {}, _b[styles.hidden] = !params, _b)), "data-test-id": dataTestId },
|
|
46
|
-
React.createElement(Gap, { size: '
|
|
47
|
-
React.createElement(Gap, { size: 's' }),
|
|
53
|
+
React.createElement(Gap, { size: 'xs' }),
|
|
48
54
|
React.createElement("div", { className: styles.error }, error),
|
|
49
|
-
React.createElement(Gap, { size: '
|
|
50
|
-
React.createElement(ReactCanvasPatternLock, __assign({}, restProps, params, { ref: ref, rows: 3, cols: 3, justifyNodes: justifyNodes }))
|
|
55
|
+
React.createElement(Gap, { size: '3xl' }),
|
|
56
|
+
React.createElement(ReactCanvasPatternLock, __assign({}, restProps, params, { ref: ref, rows: 3, cols: 3, justifyNodes: justifyNodes })),
|
|
57
|
+
showForgotCodeBtn ? (React.createElement(Button, { view: 'link', className: styles.forgotBtn, onClick: onForgotBtnClick, dataTestId: getDataTestId(dataTestId, 'forgot-code-btn') }, forgotCodeBtnText)) : (React.createElement("div", { className: styles.forgotBtn }))));
|
|
51
58
|
});
|
|
52
59
|
|
|
53
60
|
export { PatternLock };
|
package/esm/index.css
CHANGED
|
@@ -1,35 +1,40 @@
|
|
|
1
|
-
/* hash:
|
|
1
|
+
/* hash: rkcoc */
|
|
2
2
|
:root {
|
|
3
|
+
} /* deprecated */ :root {
|
|
3
4
|
--color-light-text-negative: #d91d0b;
|
|
4
|
-
}
|
|
5
|
-
:root {
|
|
5
|
+
} :root {
|
|
6
|
+
} :root {
|
|
7
|
+
} :root {
|
|
6
8
|
|
|
7
9
|
/* Hard */
|
|
8
10
|
|
|
9
11
|
/* Up */
|
|
10
12
|
|
|
11
13
|
/* Hard up */
|
|
12
|
-
}
|
|
13
|
-
:root {
|
|
14
|
+
} :root {
|
|
15
|
+
} :root {
|
|
14
16
|
--gap-xs: 8px;
|
|
17
|
+
--gap-s: 12px;
|
|
15
18
|
--gap-m: 16px;
|
|
19
|
+
--gap-l: 20px;
|
|
16
20
|
--gap-xl: 24px;
|
|
17
|
-
|
|
18
|
-
:root {
|
|
21
|
+
--gap-2xl: 32px;
|
|
22
|
+
} :root {
|
|
23
|
+
} :root {
|
|
24
|
+
--size-xs-height: 40px;
|
|
25
|
+
--size-s-height: 48px;
|
|
26
|
+
--size-m-height: 56px;
|
|
27
|
+
} :root {
|
|
19
28
|
--pattern-lock-max-width: 500px;
|
|
20
|
-
}
|
|
21
|
-
.pattern-lock__component_188cp {
|
|
29
|
+
} .pattern-lock__component_1dmbz {
|
|
22
30
|
max-width: var(--pattern-lock-max-width);
|
|
23
31
|
margin: var(--gap-xs) 0 var(--gap-xl) 0
|
|
24
|
-
}
|
|
25
|
-
.pattern-lock__component_188cp canvas {
|
|
32
|
+
} .pattern-lock__component_1dmbz canvas {
|
|
26
33
|
display: block;
|
|
27
34
|
margin: 0 auto;
|
|
28
|
-
}
|
|
29
|
-
.pattern-lock__hidden_188cp {
|
|
35
|
+
} .pattern-lock__hidden_1dmbz {
|
|
30
36
|
visibility: hidden;
|
|
31
|
-
}
|
|
32
|
-
.pattern-lock__error_188cp {
|
|
37
|
+
} .pattern-lock__error_1dmbz {
|
|
33
38
|
font-size: 16px;
|
|
34
39
|
line-height: 24px;
|
|
35
40
|
font-weight: 400;
|
|
@@ -40,4 +45,25 @@
|
|
|
40
45
|
padding: 0 var(--gap-m);
|
|
41
46
|
min-height: 24px;
|
|
42
47
|
color: var(--color-light-text-negative);
|
|
48
|
+
} .pattern-lock__forgotBtn_1dmbz {
|
|
49
|
+
display: block;
|
|
50
|
+
min-height: var(--size-xs-height);
|
|
51
|
+
margin: var(--gap-xl) auto 0;
|
|
52
|
+
} @media screen and (min-width: 360px) {
|
|
53
|
+
.pattern-lock__forgotBtn_1dmbz {
|
|
54
|
+
margin-top: var(--gap-2xl);
|
|
55
|
+
min-height: var(--size-s-height);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.pattern-lock__component_1dmbz {
|
|
59
|
+
margin-bottom: var(--gap-s);
|
|
60
|
+
}
|
|
61
|
+
} @media screen and (min-width: 390px) {
|
|
62
|
+
.pattern-lock__forgotBtn_1dmbz {
|
|
63
|
+
min-height: var(--size-m-height);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.pattern-lock__component_1dmbz {
|
|
67
|
+
margin-bottom: var(--gap-l);
|
|
68
|
+
}
|
|
43
69
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export { PatternLock } from './Component.js';
|
|
2
2
|
export { THEME_STATE } from './consts.js';
|
|
3
|
-
import '
|
|
3
|
+
import 'tslib';
|
|
4
4
|
import 'react';
|
|
5
5
|
import 'react-canvas-pattern-lock';
|
|
6
6
|
import 'classnames';
|
|
7
|
+
import '@alfalab/core-components-button/esm';
|
|
7
8
|
import '@alfalab/core-components-gap/esm';
|
|
9
|
+
import './utils.js';
|
package/esm/typings.d.ts
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
1
|
+
import { MouseEvent, ReactNode } from 'react';
|
|
2
2
|
import { ReactPatternLockProps } from 'react-canvas-pattern-lock';
|
|
3
|
+
type ConditionalProps = {
|
|
4
|
+
/**
|
|
5
|
+
* Текст кнопки "забыли код"
|
|
6
|
+
* @default "Забыли код?"
|
|
7
|
+
*/
|
|
8
|
+
showForgotCodeBtn: true;
|
|
9
|
+
/**
|
|
10
|
+
* Текст кнопки "забыли код"
|
|
11
|
+
* @default "Забыли код?"
|
|
12
|
+
*/
|
|
13
|
+
forgotCodeBtnText?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Коллбэк, вызываемый при клике на кнопку "Забыли код"
|
|
16
|
+
*/
|
|
17
|
+
onForgotBtnClick: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
18
|
+
} | {
|
|
19
|
+
showForgotCodeBtn?: false;
|
|
20
|
+
onForgotBtnClick?: never;
|
|
21
|
+
forgotCodeBtnText?: never;
|
|
22
|
+
};
|
|
3
23
|
type PatternLockProps = {
|
|
4
24
|
/**
|
|
5
25
|
* Дополнительный класс.
|
|
@@ -25,7 +45,7 @@ type PatternLockProps = {
|
|
|
25
45
|
getTarget?: () => Node;
|
|
26
46
|
options?: MutationObserverInit;
|
|
27
47
|
};
|
|
28
|
-
} & Omit<ReactPatternLockProps, 'theme' | 'width' | 'height' | 'rows' | 'cols'
|
|
48
|
+
} & Omit<ReactPatternLockProps, 'theme' | 'width' | 'height' | 'rows' | 'cols'> & ConditionalProps;
|
|
29
49
|
type ObservableTokens = {
|
|
30
50
|
ACCENT_INITIAL: string;
|
|
31
51
|
ACCENT_SUCCESS: string;
|
package/esm/utils.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Theme, ThemeParams } from 'react-canvas-pattern-lock';
|
|
2
|
+
declare function getDefaultObserveTarget(): HTMLHeadElement;
|
|
3
|
+
declare function getColorByToken(token: string): string;
|
|
4
|
+
declare const getSizes: () => {
|
|
5
|
+
elementSizes: ThemeParams['dimens'];
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
};
|
|
9
|
+
declare function getTheme(dimens: ThemeParams['dimens']): Theme;
|
|
10
|
+
export { getDefaultObserveTarget, getColorByToken, getSizes, getTheme };
|
package/esm/utils.js
CHANGED
|
@@ -1,2 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
import './consts.js';
|
|
1
|
+
import { __assign } from 'tslib';
|
|
2
|
+
import { OBSERVABLE_TOKENS, THEME_STATE } from './consts.js';
|
|
3
|
+
|
|
4
|
+
function getDefaultObserveTarget() {
|
|
5
|
+
return document.head;
|
|
6
|
+
}
|
|
7
|
+
function getColorByToken(token) {
|
|
8
|
+
return getComputedStyle(document.documentElement).getPropertyValue(token);
|
|
9
|
+
}
|
|
10
|
+
var getSizes = (function () {
|
|
11
|
+
var COMMON_SIZES = {
|
|
12
|
+
lineWidth: 6,
|
|
13
|
+
nodeRing: 0,
|
|
14
|
+
nodeCore: 12,
|
|
15
|
+
};
|
|
16
|
+
var cachedSize;
|
|
17
|
+
return function () {
|
|
18
|
+
if (cachedSize) {
|
|
19
|
+
return cachedSize;
|
|
20
|
+
}
|
|
21
|
+
if (window.matchMedia('(min-width: 390px)').matches) {
|
|
22
|
+
cachedSize = {
|
|
23
|
+
elementSizes: __assign(__assign({}, COMMON_SIZES), { nodeRadius: 43 }),
|
|
24
|
+
width: 322,
|
|
25
|
+
height: 322,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
else if (window.matchMedia('(min-width: 360px)').matches) {
|
|
29
|
+
cachedSize = {
|
|
30
|
+
elementSizes: __assign(__assign({}, COMMON_SIZES), { nodeRadius: 38 }),
|
|
31
|
+
width: 292,
|
|
32
|
+
height: 292,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
cachedSize = {
|
|
37
|
+
elementSizes: __assign(__assign({}, COMMON_SIZES), { nodeRadius: 32 }),
|
|
38
|
+
width: 240,
|
|
39
|
+
height: 240,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return cachedSize;
|
|
43
|
+
};
|
|
44
|
+
})();
|
|
45
|
+
function getTheme(dimens) {
|
|
46
|
+
var _a;
|
|
47
|
+
var baseColors = {
|
|
48
|
+
primary: getColorByToken(OBSERVABLE_TOKENS.PRIMARY),
|
|
49
|
+
bg: getColorByToken(OBSERVABLE_TOKENS.BG),
|
|
50
|
+
ringBg: getColorByToken(OBSERVABLE_TOKENS.RING_BG_INITIAL),
|
|
51
|
+
};
|
|
52
|
+
return _a = {},
|
|
53
|
+
_a[THEME_STATE.INITIAL] = {
|
|
54
|
+
colors: __assign(__assign({}, baseColors), { accent: getColorByToken(OBSERVABLE_TOKENS.ACCENT_INITIAL), selectedRingBg: getColorByToken(OBSERVABLE_TOKENS.SELECTED_RING_BG_INITIAL) }),
|
|
55
|
+
dimens: dimens,
|
|
56
|
+
},
|
|
57
|
+
_a[THEME_STATE.SUCCESS] = {
|
|
58
|
+
colors: __assign(__assign({}, baseColors), { accent: getColorByToken(OBSERVABLE_TOKENS.ACCENT_SUCCESS), selectedRingBg: getColorByToken(OBSERVABLE_TOKENS.SELECTED_RING_BG_SUCCESS) }),
|
|
59
|
+
dimens: dimens,
|
|
60
|
+
},
|
|
61
|
+
_a[THEME_STATE.FAILURE] = {
|
|
62
|
+
colors: __assign(__assign({}, baseColors), { accent: getColorByToken(OBSERVABLE_TOKENS.ACCENT_FAILURE), selectedRingBg: getColorByToken(OBSERVABLE_TOKENS.SELECTED_RING_BG_FAILURE) }),
|
|
63
|
+
dimens: dimens,
|
|
64
|
+
},
|
|
65
|
+
_a;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { getColorByToken, getDefaultObserveTarget, getSizes, getTheme };
|