@alfalab/core-components-pattern-lock-v1 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@alfalab/core-components-shared/package.json +23 -0
- package/Component.responsive.d.ts +10 -0
- package/Component.responsive.js +27 -0
- package/components/base-pattern-lock/Component.d.ts +6 -0
- package/components/base-pattern-lock/Component.js +68 -0
- package/components/base-pattern-lock/index.css +45 -0
- package/components/base-pattern-lock/index.d.ts +1 -0
- package/components/base-pattern-lock/index.js +9 -0
- package/consts.d.ts +11 -0
- package/consts.js +34 -0
- package/cssm/Component.responsive.d.ts +10 -0
- package/cssm/Component.responsive.js +27 -0
- package/cssm/components/base-pattern-lock/Component.d.ts +6 -0
- package/cssm/components/base-pattern-lock/Component.js +67 -0
- package/cssm/components/base-pattern-lock/index.d.ts +1 -0
- package/cssm/components/base-pattern-lock/index.js +9 -0
- package/cssm/components/base-pattern-lock/index.module.css +44 -0
- package/cssm/consts.d.ts +11 -0
- package/cssm/consts.js +34 -0
- package/cssm/desktop/Component.desktop.d.ts +6 -0
- package/cssm/desktop/Component.desktop.js +17 -0
- package/cssm/desktop/desktop.module.css +27 -0
- package/cssm/desktop/index.d.ts +2 -0
- package/cssm/desktop/index.js +9 -0
- package/cssm/hooks/use-pattern-lock-cleanup.d.ts +6 -0
- package/cssm/hooks/use-pattern-lock-cleanup.js +18 -0
- package/cssm/index.d.ts +3 -0
- package/cssm/index.js +11 -0
- package/cssm/mobile/Component.mobile.d.ts +6 -0
- package/cssm/mobile/Component.mobile.js +17 -0
- package/cssm/mobile/index.d.ts +2 -0
- package/cssm/mobile/index.js +9 -0
- package/cssm/mobile/mobile.module.css +47 -0
- package/cssm/shared/index.d.ts +2 -0
- package/cssm/shared/index.js +11 -0
- package/cssm/typings.d.ts +91 -0
- package/cssm/typings.js +2 -0
- package/cssm/utils.d.ts +16 -0
- package/cssm/utils.js +96 -0
- package/cssm/vars.css +0 -0
- package/desktop/Component.desktop.d.ts +6 -0
- package/desktop/Component.desktop.js +18 -0
- package/desktop/desktop.css +28 -0
- package/desktop/index.d.ts +2 -0
- package/desktop/index.js +9 -0
- package/desktop/package.json +3 -0
- package/esm/Component.responsive.d.ts +10 -0
- package/esm/Component.responsive.js +19 -0
- package/esm/components/base-pattern-lock/Component.d.ts +6 -0
- package/esm/components/base-pattern-lock/Component.js +59 -0
- package/esm/components/base-pattern-lock/index.css +45 -0
- package/esm/components/base-pattern-lock/index.d.ts +1 -0
- package/esm/components/base-pattern-lock/index.js +1 -0
- package/esm/consts.d.ts +11 -0
- package/esm/consts.js +27 -0
- package/esm/desktop/Component.desktop.d.ts +6 -0
- package/esm/desktop/Component.desktop.js +10 -0
- package/esm/desktop/desktop.css +28 -0
- package/esm/desktop/index.d.ts +2 -0
- package/esm/desktop/index.js +1 -0
- package/esm/hooks/use-pattern-lock-cleanup.d.ts +6 -0
- package/esm/hooks/use-pattern-lock-cleanup.js +14 -0
- package/esm/index.d.ts +3 -0
- package/esm/index.js +2 -0
- package/esm/mobile/Component.mobile.d.ts +6 -0
- package/esm/mobile/Component.mobile.js +10 -0
- package/esm/mobile/index.d.ts +2 -0
- package/esm/mobile/index.js +1 -0
- package/esm/mobile/mobile.css +48 -0
- package/esm/shared/index.d.ts +2 -0
- package/esm/shared/index.js +2 -0
- package/esm/typings.d.ts +91 -0
- package/esm/typings.js +1 -0
- package/esm/utils.d.ts +16 -0
- package/esm/utils.js +88 -0
- package/hooks/use-pattern-lock-cleanup.d.ts +6 -0
- package/hooks/use-pattern-lock-cleanup.js +18 -0
- package/index.d.ts +3 -0
- package/index.js +11 -0
- package/mobile/Component.mobile.d.ts +6 -0
- package/mobile/Component.mobile.js +18 -0
- package/mobile/index.d.ts +2 -0
- package/mobile/index.js +9 -0
- package/mobile/mobile.css +48 -0
- package/mobile/package.json +3 -0
- package/modern/Component.responsive.d.ts +10 -0
- package/modern/Component.responsive.js +17 -0
- package/modern/components/base-pattern-lock/Component.d.ts +6 -0
- package/modern/components/base-pattern-lock/Component.js +54 -0
- package/modern/components/base-pattern-lock/index.css +45 -0
- package/modern/components/base-pattern-lock/index.d.ts +1 -0
- package/modern/components/base-pattern-lock/index.js +1 -0
- package/modern/consts.d.ts +11 -0
- package/modern/consts.js +27 -0
- package/modern/desktop/Component.desktop.d.ts +6 -0
- package/modern/desktop/Component.desktop.js +9 -0
- package/modern/desktop/desktop.css +28 -0
- package/modern/desktop/index.d.ts +2 -0
- package/modern/desktop/index.js +1 -0
- package/modern/hooks/use-pattern-lock-cleanup.d.ts +6 -0
- package/modern/hooks/use-pattern-lock-cleanup.js +14 -0
- package/modern/index.d.ts +3 -0
- package/modern/index.js +2 -0
- package/modern/mobile/Component.mobile.d.ts +6 -0
- package/modern/mobile/Component.mobile.js +9 -0
- package/modern/mobile/index.d.ts +2 -0
- package/modern/mobile/index.js +1 -0
- package/modern/mobile/mobile.css +48 -0
- package/modern/shared/index.d.ts +2 -0
- package/modern/shared/index.js +2 -0
- package/modern/typings.d.ts +91 -0
- package/modern/typings.js +1 -0
- package/modern/utils.d.ts +16 -0
- package/modern/utils.js +98 -0
- package/package.json +25 -0
- package/shared/index.d.ts +2 -0
- package/shared/index.js +11 -0
- package/shared/package.json +3 -0
- package/src/Component.responsive.tsx +24 -0
- package/src/components/base-pattern-lock/Component.tsx +146 -0
- package/src/components/base-pattern-lock/index.module.css +34 -0
- package/src/components/base-pattern-lock/index.ts +1 -0
- package/src/consts.ts +32 -0
- package/src/desktop/Component.desktop.tsx +11 -0
- package/src/desktop/desktop.module.css +15 -0
- package/src/desktop/index.ts +2 -0
- package/src/desktop/package.json +3 -0
- package/src/hooks/use-pattern-lock-cleanup.tsx +16 -0
- package/src/index.ts +3 -0
- package/src/mobile/Component.mobile.tsx +11 -0
- package/src/mobile/index.ts +2 -0
- package/src/mobile/mobile.module.css +32 -0
- package/src/mobile/package.json +3 -0
- package/src/shared/index.ts +2 -0
- package/src/shared/package.json +3 -0
- package/src/typings.ts +103 -0
- package/src/utils.ts +105 -0
- package/src/vars.css +4 -0
- package/typings.d.ts +91 -0
- package/typings.js +2 -0
- package/utils.d.ts +16 -0
- package/utils.js +96 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import type { TPatternLockInstance } from 'react-canvas-pattern-lock';
|
|
3
|
+
|
|
4
|
+
export const usePatternLockCleanup = (
|
|
5
|
+
patternLockRef: React.MutableRefObject<TPatternLockInstance | null>,
|
|
6
|
+
) => {
|
|
7
|
+
const clear = useMemo(() => {
|
|
8
|
+
if (patternLockRef.current) {
|
|
9
|
+
patternLockRef.current.setInitialState();
|
|
10
|
+
}
|
|
11
|
+
}, [patternLockRef]);
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
clear,
|
|
15
|
+
};
|
|
16
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import type { TPatternLockInstance } from 'react-canvas-pattern-lock';
|
|
3
|
+
|
|
4
|
+
import { BasePatternLock } from '../components/base-pattern-lock';
|
|
5
|
+
import { CommonPatternLockProps } from '../typings';
|
|
6
|
+
|
|
7
|
+
import styles from './mobile.module.css';
|
|
8
|
+
|
|
9
|
+
export const PatternLockMobileV1 = forwardRef<TPatternLockInstance, CommonPatternLockProps>(
|
|
10
|
+
(restProps, ref) => <BasePatternLock {...restProps} ref={ref} styles={styles} />,
|
|
11
|
+
);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
@import '@alfalab/core-components-themes/src/default.css';
|
|
2
|
+
@import '../vars.css';
|
|
3
|
+
|
|
4
|
+
.component {
|
|
5
|
+
max-width: var(--pattern-lock-v1-max-width);
|
|
6
|
+
margin: var(--gap-xs) 0 var(--gap-xl) 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.forgotBtn {
|
|
10
|
+
margin: var(--gap-xl) auto 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@media screen and (min-width: 360px) {
|
|
14
|
+
.forgotBtn {
|
|
15
|
+
margin-top: var(--gap-2xl);
|
|
16
|
+
min-height: var(--size-s-height);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.component {
|
|
20
|
+
margin-bottom: var(--gap-s);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@media screen and (min-width: 390px) {
|
|
25
|
+
.forgotBtn {
|
|
26
|
+
min-height: var(--size-m-height);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.component {
|
|
30
|
+
margin-bottom: var(--gap-l);
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/typings.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { MouseEvent, ReactNode } from 'react';
|
|
2
|
+
import { ReactPatternLockProps } from 'react-canvas-pattern-lock';
|
|
3
|
+
|
|
4
|
+
type ConditionalProps =
|
|
5
|
+
| {
|
|
6
|
+
/**
|
|
7
|
+
* Показать кнопку "забыли код"
|
|
8
|
+
* @default "Забыли код?"
|
|
9
|
+
*/
|
|
10
|
+
showForgotCodeBtn: true;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Текст кнопки "забыли код"
|
|
14
|
+
* @default "Забыли код?"
|
|
15
|
+
*/
|
|
16
|
+
forgotCodeBtnText?: string;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Коллбэк, вызываемый при клике на кнопку "Забыли код"
|
|
20
|
+
*/
|
|
21
|
+
onForgotBtnClick: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
22
|
+
}
|
|
23
|
+
| {
|
|
24
|
+
showForgotCodeBtn?: false;
|
|
25
|
+
onForgotBtnClick?: never;
|
|
26
|
+
forgotCodeBtnText?: never;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type CommonPatternLockProps = {
|
|
30
|
+
/**
|
|
31
|
+
* Дополнительный класс
|
|
32
|
+
*/
|
|
33
|
+
className?: string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Сообщение об ошибке
|
|
37
|
+
*/
|
|
38
|
+
error?: ReactNode;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Сообщение над графическим ключом
|
|
42
|
+
*/
|
|
43
|
+
message?: ReactNode;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Идентификатор для систем автоматизированного тестирования.
|
|
47
|
+
* Для сообщения используется модификатор -message, ошибки -error,
|
|
48
|
+
* кнопки "забыли код" -forgot-code-btn
|
|
49
|
+
*/
|
|
50
|
+
dataTestId?: string;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Следить ли за изменениями значений цветовых токенов
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
observeTokens?: boolean;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Параметры MutationObserver для наблюдения за изменениями режима(css custom properties)
|
|
60
|
+
*/
|
|
61
|
+
observerParams?: {
|
|
62
|
+
getTarget?: () => Node;
|
|
63
|
+
options?: MutationObserverInit;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Дополнительный класс для message/errorMessage
|
|
68
|
+
*/
|
|
69
|
+
messageClassName?: string;
|
|
70
|
+
} & Omit<ReactPatternLockProps, 'theme' | 'width' | 'height' | 'rows' | 'cols' | 'hover'> &
|
|
71
|
+
ConditionalProps;
|
|
72
|
+
|
|
73
|
+
export type PrivatePatternLockProps = {
|
|
74
|
+
/**
|
|
75
|
+
* Включает ховер-эффект
|
|
76
|
+
*/
|
|
77
|
+
hover?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Стили компонента
|
|
80
|
+
*/
|
|
81
|
+
styles: { [key: string]: string };
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export type PatternLockProps = CommonPatternLockProps & {
|
|
85
|
+
/**
|
|
86
|
+
* Контрольная точка, с нее начинается desktop версия
|
|
87
|
+
* @default 1024
|
|
88
|
+
*/
|
|
89
|
+
breakpoint?: number;
|
|
90
|
+
};
|
|
91
|
+
export type ObservableTokens = {
|
|
92
|
+
ACCENT_INITIAL: string;
|
|
93
|
+
ACCENT_SUCCESS: string;
|
|
94
|
+
ACCENT_FAILURE: string;
|
|
95
|
+
RING_BG_INITIAL: string;
|
|
96
|
+
SELECTED_RING_BG_INITIAL: string;
|
|
97
|
+
SELECTED_RING_BG_SUCCESS: string;
|
|
98
|
+
SELECTED_RING_BG_FAILURE: string;
|
|
99
|
+
PRIMARY: string;
|
|
100
|
+
BG: string;
|
|
101
|
+
HOVER_INNER: string;
|
|
102
|
+
HOVER_OUTER: string;
|
|
103
|
+
};
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Theme, ThemeParams } from 'react-canvas-pattern-lock';
|
|
2
|
+
|
|
3
|
+
import { getDataTestId } from '@alfalab/core-components-shared';
|
|
4
|
+
|
|
5
|
+
import { OBSERVABLE_TOKENS, THEME_STATE } from './consts';
|
|
6
|
+
|
|
7
|
+
export function getDefaultObserveTarget() {
|
|
8
|
+
return document.head;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getColorByToken(token: string) {
|
|
12
|
+
return getComputedStyle(document.documentElement).getPropertyValue(token);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const getSizes = (() => {
|
|
16
|
+
const COMMON_SIZES = {
|
|
17
|
+
lineWidth: 6,
|
|
18
|
+
nodeRing: 0,
|
|
19
|
+
nodeCore: 12,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
let cachedSize: { elementSizes: ThemeParams['dimens']; width: number; height: number };
|
|
23
|
+
|
|
24
|
+
return () => {
|
|
25
|
+
if (cachedSize) {
|
|
26
|
+
return cachedSize;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (window.matchMedia('(min-width: 600px)').matches) {
|
|
30
|
+
cachedSize = {
|
|
31
|
+
elementSizes: { ...COMMON_SIZES, nodeRadius: 32 },
|
|
32
|
+
width: 240,
|
|
33
|
+
height: 240,
|
|
34
|
+
};
|
|
35
|
+
} else if (window.matchMedia('(min-width: 390px)').matches) {
|
|
36
|
+
cachedSize = {
|
|
37
|
+
elementSizes: { ...COMMON_SIZES, nodeRadius: 43 },
|
|
38
|
+
width: 322,
|
|
39
|
+
height: 322,
|
|
40
|
+
};
|
|
41
|
+
} else if (window.matchMedia('(min-width: 360px)').matches) {
|
|
42
|
+
cachedSize = {
|
|
43
|
+
elementSizes: { ...COMMON_SIZES, nodeRadius: 38 },
|
|
44
|
+
width: 292,
|
|
45
|
+
height: 292,
|
|
46
|
+
};
|
|
47
|
+
} else {
|
|
48
|
+
cachedSize = {
|
|
49
|
+
elementSizes: { ...COMMON_SIZES, nodeRadius: 32 },
|
|
50
|
+
width: 240,
|
|
51
|
+
height: 240,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return cachedSize;
|
|
56
|
+
};
|
|
57
|
+
})();
|
|
58
|
+
|
|
59
|
+
export function getTheme(dimens: ThemeParams['dimens']): Theme {
|
|
60
|
+
const baseColors = {
|
|
61
|
+
primary: getColorByToken(OBSERVABLE_TOKENS.PRIMARY),
|
|
62
|
+
bg: getColorByToken(OBSERVABLE_TOKENS.BG),
|
|
63
|
+
ringBg: getColorByToken(OBSERVABLE_TOKENS.RING_BG_INITIAL),
|
|
64
|
+
hover: {
|
|
65
|
+
inner: getColorByToken(OBSERVABLE_TOKENS.HOVER_INNER),
|
|
66
|
+
outer: getColorByToken(OBSERVABLE_TOKENS.HOVER_OUTER),
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
[THEME_STATE.INITIAL]: {
|
|
72
|
+
colors: {
|
|
73
|
+
...baseColors,
|
|
74
|
+
accent: getColorByToken(OBSERVABLE_TOKENS.ACCENT_INITIAL),
|
|
75
|
+
selectedRingBg: getColorByToken(OBSERVABLE_TOKENS.SELECTED_RING_BG_INITIAL),
|
|
76
|
+
},
|
|
77
|
+
dimens,
|
|
78
|
+
},
|
|
79
|
+
[THEME_STATE.SUCCESS]: {
|
|
80
|
+
colors: {
|
|
81
|
+
...baseColors,
|
|
82
|
+
accent: getColorByToken(OBSERVABLE_TOKENS.ACCENT_SUCCESS),
|
|
83
|
+
selectedRingBg: getColorByToken(OBSERVABLE_TOKENS.SELECTED_RING_BG_SUCCESS),
|
|
84
|
+
},
|
|
85
|
+
dimens,
|
|
86
|
+
},
|
|
87
|
+
[THEME_STATE.FAILURE]: {
|
|
88
|
+
colors: {
|
|
89
|
+
...baseColors,
|
|
90
|
+
accent: getColorByToken(OBSERVABLE_TOKENS.ACCENT_FAILURE),
|
|
91
|
+
selectedRingBg: getColorByToken(OBSERVABLE_TOKENS.SELECTED_RING_BG_FAILURE),
|
|
92
|
+
},
|
|
93
|
+
dimens,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function getPatternLockTestIds(dataTestId: string) {
|
|
99
|
+
return {
|
|
100
|
+
patternLock: dataTestId,
|
|
101
|
+
forgotCodeBtn: getDataTestId(dataTestId, 'forgot-code-btn'),
|
|
102
|
+
error: getDataTestId(dataTestId, 'error'),
|
|
103
|
+
message: getDataTestId(dataTestId, 'message'),
|
|
104
|
+
};
|
|
105
|
+
}
|
package/src/vars.css
ADDED
package/typings.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { MouseEvent, ReactNode } from 'react';
|
|
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
|
+
};
|
|
23
|
+
type CommonPatternLockProps = {
|
|
24
|
+
/**
|
|
25
|
+
* Дополнительный класс
|
|
26
|
+
*/
|
|
27
|
+
className?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Сообщение об ошибке
|
|
30
|
+
*/
|
|
31
|
+
error?: ReactNode;
|
|
32
|
+
/**
|
|
33
|
+
* Сообщение над графическим ключом
|
|
34
|
+
*/
|
|
35
|
+
message?: ReactNode;
|
|
36
|
+
/**
|
|
37
|
+
* Идентификатор для систем автоматизированного тестирования.
|
|
38
|
+
* Для сообщения используется модификатор -message, ошибки -error,
|
|
39
|
+
* кнопки "забыли код" -forgot-code-btn
|
|
40
|
+
*/
|
|
41
|
+
dataTestId?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Следить ли за изменениями значений цветовых токенов
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
observeTokens?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Параметры MutationObserver для наблюдения за изменениями режима(css custom properties)
|
|
49
|
+
*/
|
|
50
|
+
observerParams?: {
|
|
51
|
+
getTarget?: () => Node;
|
|
52
|
+
options?: MutationObserverInit;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Дополнительный класс для message/errorMessage
|
|
56
|
+
*/
|
|
57
|
+
messageClassName?: string;
|
|
58
|
+
} & Omit<ReactPatternLockProps, 'theme' | 'width' | 'height' | 'rows' | 'cols' | 'hover'> & ConditionalProps;
|
|
59
|
+
type PrivatePatternLockProps = {
|
|
60
|
+
/**
|
|
61
|
+
* Включает ховер-эффект
|
|
62
|
+
*/
|
|
63
|
+
hover?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Стили компонента
|
|
66
|
+
*/
|
|
67
|
+
styles: {
|
|
68
|
+
[key: string]: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
type PatternLockProps = CommonPatternLockProps & {
|
|
72
|
+
/**
|
|
73
|
+
* Контрольная точка, с нее начинается desktop версия
|
|
74
|
+
* @default 1024
|
|
75
|
+
*/
|
|
76
|
+
breakpoint?: number;
|
|
77
|
+
};
|
|
78
|
+
type ObservableTokens = {
|
|
79
|
+
ACCENT_INITIAL: string;
|
|
80
|
+
ACCENT_SUCCESS: string;
|
|
81
|
+
ACCENT_FAILURE: string;
|
|
82
|
+
RING_BG_INITIAL: string;
|
|
83
|
+
SELECTED_RING_BG_INITIAL: string;
|
|
84
|
+
SELECTED_RING_BG_SUCCESS: string;
|
|
85
|
+
SELECTED_RING_BG_FAILURE: string;
|
|
86
|
+
PRIMARY: string;
|
|
87
|
+
BG: string;
|
|
88
|
+
HOVER_INNER: string;
|
|
89
|
+
HOVER_OUTER: string;
|
|
90
|
+
};
|
|
91
|
+
export { CommonPatternLockProps, PrivatePatternLockProps, PatternLockProps, ObservableTokens };
|
package/typings.js
ADDED
package/utils.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
declare function getPatternLockTestIds(dataTestId: string): {
|
|
11
|
+
patternLock: string;
|
|
12
|
+
forgotCodeBtn: string;
|
|
13
|
+
error: string;
|
|
14
|
+
message: string;
|
|
15
|
+
};
|
|
16
|
+
export { getDefaultObserveTarget, getColorByToken, getSizes, getTheme, getPatternLockTestIds };
|
package/utils.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var coreComponentsShared = require('@alfalab/core-components-shared');
|
|
7
|
+
var consts = require('./consts.js');
|
|
8
|
+
|
|
9
|
+
function getDefaultObserveTarget() {
|
|
10
|
+
return document.head;
|
|
11
|
+
}
|
|
12
|
+
function getColorByToken(token) {
|
|
13
|
+
return getComputedStyle(document.documentElement).getPropertyValue(token);
|
|
14
|
+
}
|
|
15
|
+
var getSizes = (function () {
|
|
16
|
+
var COMMON_SIZES = {
|
|
17
|
+
lineWidth: 6,
|
|
18
|
+
nodeRing: 0,
|
|
19
|
+
nodeCore: 12,
|
|
20
|
+
};
|
|
21
|
+
var cachedSize;
|
|
22
|
+
return function () {
|
|
23
|
+
if (cachedSize) {
|
|
24
|
+
return cachedSize;
|
|
25
|
+
}
|
|
26
|
+
if (window.matchMedia('(min-width: 600px)').matches) {
|
|
27
|
+
cachedSize = {
|
|
28
|
+
elementSizes: tslib.__assign(tslib.__assign({}, COMMON_SIZES), { nodeRadius: 32 }),
|
|
29
|
+
width: 240,
|
|
30
|
+
height: 240,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
else if (window.matchMedia('(min-width: 390px)').matches) {
|
|
34
|
+
cachedSize = {
|
|
35
|
+
elementSizes: tslib.__assign(tslib.__assign({}, COMMON_SIZES), { nodeRadius: 43 }),
|
|
36
|
+
width: 322,
|
|
37
|
+
height: 322,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
else if (window.matchMedia('(min-width: 360px)').matches) {
|
|
41
|
+
cachedSize = {
|
|
42
|
+
elementSizes: tslib.__assign(tslib.__assign({}, COMMON_SIZES), { nodeRadius: 38 }),
|
|
43
|
+
width: 292,
|
|
44
|
+
height: 292,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
cachedSize = {
|
|
49
|
+
elementSizes: tslib.__assign(tslib.__assign({}, COMMON_SIZES), { nodeRadius: 32 }),
|
|
50
|
+
width: 240,
|
|
51
|
+
height: 240,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return cachedSize;
|
|
55
|
+
};
|
|
56
|
+
})();
|
|
57
|
+
function getTheme(dimens) {
|
|
58
|
+
var _a;
|
|
59
|
+
var baseColors = {
|
|
60
|
+
primary: getColorByToken(consts.OBSERVABLE_TOKENS.PRIMARY),
|
|
61
|
+
bg: getColorByToken(consts.OBSERVABLE_TOKENS.BG),
|
|
62
|
+
ringBg: getColorByToken(consts.OBSERVABLE_TOKENS.RING_BG_INITIAL),
|
|
63
|
+
hover: {
|
|
64
|
+
inner: getColorByToken(consts.OBSERVABLE_TOKENS.HOVER_INNER),
|
|
65
|
+
outer: getColorByToken(consts.OBSERVABLE_TOKENS.HOVER_OUTER),
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
return _a = {},
|
|
69
|
+
_a[consts.THEME_STATE.INITIAL] = {
|
|
70
|
+
colors: tslib.__assign(tslib.__assign({}, baseColors), { accent: getColorByToken(consts.OBSERVABLE_TOKENS.ACCENT_INITIAL), selectedRingBg: getColorByToken(consts.OBSERVABLE_TOKENS.SELECTED_RING_BG_INITIAL) }),
|
|
71
|
+
dimens: dimens,
|
|
72
|
+
},
|
|
73
|
+
_a[consts.THEME_STATE.SUCCESS] = {
|
|
74
|
+
colors: tslib.__assign(tslib.__assign({}, baseColors), { accent: getColorByToken(consts.OBSERVABLE_TOKENS.ACCENT_SUCCESS), selectedRingBg: getColorByToken(consts.OBSERVABLE_TOKENS.SELECTED_RING_BG_SUCCESS) }),
|
|
75
|
+
dimens: dimens,
|
|
76
|
+
},
|
|
77
|
+
_a[consts.THEME_STATE.FAILURE] = {
|
|
78
|
+
colors: tslib.__assign(tslib.__assign({}, baseColors), { accent: getColorByToken(consts.OBSERVABLE_TOKENS.ACCENT_FAILURE), selectedRingBg: getColorByToken(consts.OBSERVABLE_TOKENS.SELECTED_RING_BG_FAILURE) }),
|
|
79
|
+
dimens: dimens,
|
|
80
|
+
},
|
|
81
|
+
_a;
|
|
82
|
+
}
|
|
83
|
+
function getPatternLockTestIds(dataTestId) {
|
|
84
|
+
return {
|
|
85
|
+
patternLock: dataTestId,
|
|
86
|
+
forgotCodeBtn: coreComponentsShared.getDataTestId(dataTestId, 'forgot-code-btn'),
|
|
87
|
+
error: coreComponentsShared.getDataTestId(dataTestId, 'error'),
|
|
88
|
+
message: coreComponentsShared.getDataTestId(dataTestId, 'message'),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
exports.getColorByToken = getColorByToken;
|
|
93
|
+
exports.getDefaultObserveTarget = getDefaultObserveTarget;
|
|
94
|
+
exports.getPatternLockTestIds = getPatternLockTestIds;
|
|
95
|
+
exports.getSizes = getSizes;
|
|
96
|
+
exports.getTheme = getTheme;
|