@true-engineering/true-react-common-ui-kit 3.33.2 → 3.34.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/README.md +7 -0
- package/dist/components/Toaster/Toaster.d.ts +2 -2
- package/dist/true-react-common-ui-kit.js +55 -212
- package/dist/true-react-common-ui-kit.js.map +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs +55 -212
- package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
- package/package.json +1 -1
- package/src/components/Toaster/Toaster.tsx +13 -26
package/package.json
CHANGED
|
@@ -2,9 +2,9 @@ import { FC, ReactNode, useEffect } from 'react';
|
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import {
|
|
4
4
|
addDataTestId,
|
|
5
|
+
isEmpty,
|
|
5
6
|
isNotEmpty,
|
|
6
7
|
isReactNodeNotEmpty,
|
|
7
|
-
isStringNotEmpty,
|
|
8
8
|
} from '@true-engineering/true-react-platform-helpers';
|
|
9
9
|
import { addDataAttributes } from '../../helpers';
|
|
10
10
|
import { useTweakStyles } from '../../hooks';
|
|
@@ -13,13 +13,13 @@ import { Icon } from '../Icon';
|
|
|
13
13
|
import { IconButton } from '../IconButton';
|
|
14
14
|
import { DEFAULT_TIMEOUT } from './constants';
|
|
15
15
|
import { IToasterType } from './types';
|
|
16
|
-
import {
|
|
16
|
+
import { IToasterStyles, useStyles } from './Toaster.styles';
|
|
17
17
|
|
|
18
18
|
export interface IToasterProps extends ICommonProps<IToasterStyles> {
|
|
19
19
|
/** @default 'error' */
|
|
20
20
|
type?: IToasterType;
|
|
21
|
-
title?:
|
|
22
|
-
text?:
|
|
21
|
+
title?: ReactNode;
|
|
22
|
+
text?: ReactNode;
|
|
23
23
|
children?: ReactNode;
|
|
24
24
|
/**
|
|
25
25
|
* Время автоматического закрытия тостера в миллисекундах
|
|
@@ -35,16 +35,16 @@ export interface IToasterProps extends ICommonProps<IToasterStyles> {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export const Toaster: FC<IToasterProps> = ({
|
|
38
|
-
title,
|
|
39
38
|
type = 'error',
|
|
39
|
+
title,
|
|
40
40
|
text,
|
|
41
|
+
children,
|
|
41
42
|
timeout = DEFAULT_TIMEOUT,
|
|
43
|
+
hasCloseButton = false,
|
|
44
|
+
shouldCloseOnClick = false,
|
|
42
45
|
data,
|
|
43
46
|
testId,
|
|
44
47
|
tweakStyles,
|
|
45
|
-
hasCloseButton = false,
|
|
46
|
-
shouldCloseOnClick = false,
|
|
47
|
-
children,
|
|
48
48
|
onClose,
|
|
49
49
|
onTimeEnd,
|
|
50
50
|
}) => {
|
|
@@ -56,27 +56,14 @@ export const Toaster: FC<IToasterProps> = ({
|
|
|
56
56
|
currentComponentName: 'Toaster',
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
let timeoutFunction: ReturnType<typeof setTimeout>;
|
|
60
|
-
|
|
61
59
|
useEffect(() => {
|
|
62
|
-
if (
|
|
60
|
+
if (!Number.isFinite(timeout) || isEmpty(onTimeEnd)) {
|
|
63
61
|
return;
|
|
64
62
|
}
|
|
65
63
|
|
|
66
|
-
const
|
|
67
|
-
await new Promise((resolve) => {
|
|
68
|
-
timeoutFunction = setTimeout(() => {
|
|
69
|
-
resolve(undefined);
|
|
70
|
-
}, timeout);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
onTimeEnd();
|
|
74
|
-
clearTimeout(timeoutFunction);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
disappear();
|
|
64
|
+
const timeoutId = window.setTimeout(() => onTimeEnd(), timeout);
|
|
78
65
|
|
|
79
|
-
return () => clearTimeout(
|
|
66
|
+
return () => window.clearTimeout(timeoutId);
|
|
80
67
|
}, []);
|
|
81
68
|
|
|
82
69
|
return (
|
|
@@ -90,8 +77,8 @@ export const Toaster: FC<IToasterProps> = ({
|
|
|
90
77
|
<Icon type={`status-${type}`} />
|
|
91
78
|
</div>
|
|
92
79
|
<div>
|
|
93
|
-
{
|
|
94
|
-
{
|
|
80
|
+
{isReactNodeNotEmpty(title) && <div className={classes.title}>{title}</div>}
|
|
81
|
+
{isReactNodeNotEmpty(text) && <div className={classes.text}>{text}</div>}
|
|
95
82
|
{isReactNodeNotEmpty(children) && <div className={classes.content}>{children}</div>}
|
|
96
83
|
</div>
|
|
97
84
|
{hasCloseButton && isNotEmpty(onClose) && (
|