@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@true-engineering/true-react-common-ui-kit",
3
- "version": "3.33.2",
3
+ "version": "3.34.0",
4
4
  "description": "True Engineering React UI Kit with theming support",
5
5
  "author": "True Engineering (https://trueengineering.ru)",
6
6
  "keywords": [
@@ -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 { useStyles, IToasterStyles } from './Toaster.styles';
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?: string;
22
- text?: string;
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 (onTimeEnd === undefined) {
60
+ if (!Number.isFinite(timeout) || isEmpty(onTimeEnd)) {
63
61
  return;
64
62
  }
65
63
 
66
- const disappear = async () => {
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(timeoutFunction);
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
- {isStringNotEmpty(title) && <div className={classes.title}>{title}</div>}
94
- {isStringNotEmpty(text) && <div className={classes.text}>{text}</div>}
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) && (