@true-engineering/true-react-common-ui-kit 2.2.0 → 2.3.1
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/README.md +16 -0
- package/dist/components/Modal/Modal.d.ts +3 -3
- package/dist/true-react-common-ui-kit.js +95 -41
- package/dist/true-react-common-ui-kit.js.map +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs +95 -41
- package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
- package/package.json +2 -2
- package/src/components/Modal/Modal.tsx +26 -12
- package/src/helpers/deprecated.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@true-engineering/true-react-common-ui-kit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "True Engineering React UI Kit with theming support",
|
|
5
5
|
"author": "True Engineering (https://trueengineering.ru)",
|
|
6
6
|
"keywords": [
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"types-check": "tsc --noEmit"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@true-engineering/true-react-platform-helpers": "0.0.
|
|
45
|
+
"@true-engineering/true-react-platform-helpers": "0.0.5",
|
|
46
46
|
"clsx": "1.2.1",
|
|
47
47
|
"country-flag-icons": "1.5.5",
|
|
48
48
|
"date-fns": "2.29.3",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FC, ReactNode, MouseEvent, useCallback, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { RemoveScroll } from 'react-remove-scroll';
|
|
3
3
|
import { CSSTransition } from 'react-transition-group';
|
|
4
|
+
import { TransitionProps } from 'react-transition-group/Transition';
|
|
4
5
|
import clsx from 'clsx';
|
|
5
6
|
import {
|
|
6
7
|
addDataTestId,
|
|
@@ -15,7 +16,21 @@ import { ModalStyles, styles } from './Modal.styles';
|
|
|
15
16
|
|
|
16
17
|
export type IModalPosition = 'center' | 'left' | 'right' | 'static';
|
|
17
18
|
|
|
18
|
-
export
|
|
19
|
+
export type IModalTransitionProps = Pick<
|
|
20
|
+
TransitionProps<HTMLDivElement>,
|
|
21
|
+
| 'in' // Аналог isOpen, но это свойство нужно для корректной отрисовки Modal внутри TransitionGroup
|
|
22
|
+
| 'mountOnEnter'
|
|
23
|
+
| 'unmountOnExit'
|
|
24
|
+
| 'timeout'
|
|
25
|
+
| 'onEnter'
|
|
26
|
+
| 'onEntering'
|
|
27
|
+
| 'onEntered'
|
|
28
|
+
| 'onExit'
|
|
29
|
+
| 'onExiting'
|
|
30
|
+
| 'onExited'
|
|
31
|
+
>;
|
|
32
|
+
|
|
33
|
+
export interface IModalProps extends ICommonProps, IModalTransitionProps {
|
|
19
34
|
tweakStyles?: ModalStyles;
|
|
20
35
|
title?: ReactNode;
|
|
21
36
|
size?: 'l' | 'm' | 's';
|
|
@@ -32,9 +47,7 @@ export interface IModalProps extends ICommonProps {
|
|
|
32
47
|
isOpen?: boolean;
|
|
33
48
|
zIndex?: number;
|
|
34
49
|
testId?: string;
|
|
35
|
-
onEnter?(): void;
|
|
36
50
|
onClose?(): void;
|
|
37
|
-
onCompletelyHidden?(): void;
|
|
38
51
|
}
|
|
39
52
|
|
|
40
53
|
export const Modal: FC<IModalProps> = ({
|
|
@@ -55,10 +68,12 @@ export const Modal: FC<IModalProps> = ({
|
|
|
55
68
|
shouldCloseOnOverlayClick = true,
|
|
56
69
|
shouldCloseOnEsc = true,
|
|
57
70
|
shouldBlockScroll = true,
|
|
71
|
+
timeout = 150,
|
|
72
|
+
unmountOnExit = true,
|
|
58
73
|
onClose,
|
|
59
|
-
|
|
60
|
-
onEnter,
|
|
74
|
+
...restProps
|
|
61
75
|
}) => {
|
|
76
|
+
const isModalOpen = isOpen ?? restProps.in ?? false;
|
|
62
77
|
const { classes, componentStyles } = useTheme('Modal', styles, tweakStyles);
|
|
63
78
|
|
|
64
79
|
const tweakCloseButtonStyles = useTweakStyles(componentStyles, tweakStyles, 'tweakCloseButton');
|
|
@@ -96,27 +111,26 @@ export const Modal: FC<IModalProps> = ({
|
|
|
96
111
|
);
|
|
97
112
|
|
|
98
113
|
useEffect(() => {
|
|
99
|
-
if (!shouldCloseOnEsc || onClose === undefined || !
|
|
114
|
+
if (!shouldCloseOnEsc || onClose === undefined || !isModalOpen) {
|
|
100
115
|
return () => null;
|
|
101
116
|
}
|
|
102
117
|
|
|
103
118
|
document.addEventListener('keydown', handleEscClose);
|
|
104
119
|
return () => document.removeEventListener('keydown', handleEscClose);
|
|
105
|
-
}, [shouldCloseOnEsc, onClose,
|
|
120
|
+
}, [shouldCloseOnEsc, onClose, isModalOpen, handleEscClose]);
|
|
106
121
|
|
|
107
122
|
return (
|
|
108
123
|
<CSSTransition
|
|
109
|
-
in={
|
|
110
|
-
timeout={
|
|
111
|
-
unmountOnExit
|
|
124
|
+
in={isModalOpen}
|
|
125
|
+
timeout={timeout}
|
|
126
|
+
unmountOnExit={unmountOnExit}
|
|
112
127
|
classNames={{
|
|
113
128
|
enter: classes['modal-enter'],
|
|
114
129
|
enterActive: classes['modal-enter-active'],
|
|
115
130
|
exit: classes['modal-exit'],
|
|
116
131
|
exitActive: classes['modal-exit-active'],
|
|
117
132
|
}}
|
|
118
|
-
|
|
119
|
-
onExited={onCompletelyHidden}
|
|
133
|
+
{...restProps}
|
|
120
134
|
>
|
|
121
135
|
<div className={classes.modalWrapper}>
|
|
122
136
|
<RemoveScroll enabled={shouldBlockScroll} forwardProps>
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
getSelectKeyHandler as getSelectKeyHandlerHelper,
|
|
6
6
|
getTestId as getTestIdHelper,
|
|
7
7
|
isEmpty as isEmptyHelper,
|
|
8
|
+
isNotEmpty as isNotEmptyHelper,
|
|
8
9
|
isNumberInteger,
|
|
9
10
|
isString,
|
|
10
11
|
isStringNotEmpty as isStringNotEmptyHelper,
|
|
@@ -19,4 +20,4 @@ export const getTestId = getTestIdHelper;
|
|
|
19
20
|
export const isStringNotEmpty = isStringNotEmptyHelper;
|
|
20
21
|
export const isEmpty = isEmptyHelper;
|
|
21
22
|
export const isNotEmpty = <T>(val: T | null | undefined): val is T =>
|
|
22
|
-
(isString(val) &&
|
|
23
|
+
(isString(val) && isStringNotEmptyHelper(val)) || isNotEmptyHelper(val);
|