@alfalab/core-components-notification-manager 5.2.9 → 5.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/component.js CHANGED
@@ -15,7 +15,7 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
15
15
  var React__default = /*#__PURE__*/_interopDefaultCompat(React);
16
16
  var cn__default = /*#__PURE__*/_interopDefaultCompat(cn);
17
17
 
18
- var styles = {"component":"notification-manager__component_1umri","notification":"notification-manager__notification_1umri","enter":"notification-manager__enter_1umri","enterActive":"notification-manager__enterActive_1umri","exit":"notification-manager__exit_1umri","exitActive":"notification-manager__exitActive_1umri"};
18
+ var styles = {"component":"notification-manager__component_18uty","notification":"notification-manager__notification_18uty","enter":"notification-manager__enter_18uty","enterActive":"notification-manager__enterActive_18uty","exit":"notification-manager__exit_18uty","exitActive":"notification-manager__exitActive_18uty"};
19
19
  require('./index.css')
20
20
 
21
21
  var CSS_TRANSITION_CLASS_NAMES = {
package/esm/component.js CHANGED
@@ -6,7 +6,7 @@ import { Portal } from '@alfalab/core-components-portal/esm';
6
6
  import { stackingOrder, Stack } from '@alfalab/core-components-stack/esm';
7
7
  import { Notification } from './components/notification/component.js';
8
8
 
9
- var styles = {"component":"notification-manager__component_1umri","notification":"notification-manager__notification_1umri","enter":"notification-manager__enter_1umri","enterActive":"notification-manager__enterActive_1umri","exit":"notification-manager__exit_1umri","exitActive":"notification-manager__exitActive_1umri"};
9
+ var styles = {"component":"notification-manager__component_18uty","notification":"notification-manager__notification_18uty","enter":"notification-manager__enter_18uty","enterActive":"notification-manager__enterActive_18uty","exit":"notification-manager__exit_18uty","exitActive":"notification-manager__exitActive_18uty"};
10
10
  require('./index.css')
11
11
 
12
12
  var CSS_TRANSITION_CLASS_NAMES = {
package/esm/index.css CHANGED
@@ -1,11 +1,11 @@
1
- /* hash: a45ka */
1
+ /* hash: 1rgsa */
2
2
  :root {
3
3
  --gap-s: 12px;
4
4
  --gap-xl: 24px;
5
5
  --gap-4xl: 48px;
6
6
  }
7
7
 
8
- .notification-manager__component_1umri {
8
+ .notification-manager__component_18uty {
9
9
  position: fixed;
10
10
  top: 0;
11
11
  right: var(--gap-s);
@@ -13,48 +13,48 @@
13
13
  flex-direction: column;
14
14
  }
15
15
 
16
- .notification-manager__component_1umri .notification-manager__notification_1umri {
16
+ .notification-manager__component_18uty .notification-manager__notification_18uty {
17
17
  position: static;
18
18
  width: calc(100vw - var(--gap-xl));
19
19
  margin-top: var(--gap-s);
20
20
  will-change: transform;
21
21
  }
22
22
 
23
- .notification-manager__enter_1umri {
23
+ .notification-manager__enter_18uty {
24
24
  visibility: hidden;
25
25
  transform: translate(0, -500px);
26
26
  }
27
27
 
28
- .notification-manager__enterActive_1umri {
28
+ .notification-manager__enterActive_18uty {
29
29
  visibility: visible;
30
30
  transform: translate(0);
31
31
  transition: transform 0.4s ease-out;
32
32
  }
33
33
 
34
- .notification-manager__exit_1umri {
34
+ .notification-manager__exit_18uty {
35
35
  opacity: 0;
36
36
  }
37
37
 
38
- .notification-manager__exitActive_1umri {
38
+ .notification-manager__exitActive_18uty {
39
39
  visibility: hidden;
40
40
  opacity: 0;
41
41
  transition: opacity 0.15s ease-in-out;
42
42
  }
43
43
 
44
44
  @media (min-width: 600px) {
45
- .notification-manager__component_1umri {
45
+ .notification-manager__component_18uty {
46
46
  right: var(--gap-4xl);
47
47
  }
48
48
 
49
- .notification-manager__component_1umri .notification-manager__notification_1umri {
49
+ .notification-manager__component_18uty .notification-manager__notification_18uty {
50
50
  width: auto;
51
51
  }
52
52
 
53
- .notification-manager__enter_1umri {
53
+ .notification-manager__enter_18uty {
54
54
  transform: translate(100%, 0);
55
55
  }
56
56
 
57
- .notification-manager__enterActive_1umri {
57
+ .notification-manager__enterActive_18uty {
58
58
  transform: translate(0);
59
59
  }
60
60
  }
package/index.css CHANGED
@@ -1,11 +1,11 @@
1
- /* hash: a45ka */
1
+ /* hash: 1rgsa */
2
2
  :root {
3
3
  --gap-s: 12px;
4
4
  --gap-xl: 24px;
5
5
  --gap-4xl: 48px;
6
6
  }
7
7
 
8
- .notification-manager__component_1umri {
8
+ .notification-manager__component_18uty {
9
9
  position: fixed;
10
10
  top: 0;
11
11
  right: var(--gap-s);
@@ -13,48 +13,48 @@
13
13
  flex-direction: column;
14
14
  }
15
15
 
16
- .notification-manager__component_1umri .notification-manager__notification_1umri {
16
+ .notification-manager__component_18uty .notification-manager__notification_18uty {
17
17
  position: static;
18
18
  width: calc(100vw - var(--gap-xl));
19
19
  margin-top: var(--gap-s);
20
20
  will-change: transform;
21
21
  }
22
22
 
23
- .notification-manager__enter_1umri {
23
+ .notification-manager__enter_18uty {
24
24
  visibility: hidden;
25
25
  transform: translate(0, -500px);
26
26
  }
27
27
 
28
- .notification-manager__enterActive_1umri {
28
+ .notification-manager__enterActive_18uty {
29
29
  visibility: visible;
30
30
  transform: translate(0);
31
31
  transition: transform 0.4s ease-out;
32
32
  }
33
33
 
34
- .notification-manager__exit_1umri {
34
+ .notification-manager__exit_18uty {
35
35
  opacity: 0;
36
36
  }
37
37
 
38
- .notification-manager__exitActive_1umri {
38
+ .notification-manager__exitActive_18uty {
39
39
  visibility: hidden;
40
40
  opacity: 0;
41
41
  transition: opacity 0.15s ease-in-out;
42
42
  }
43
43
 
44
44
  @media (min-width: 600px) {
45
- .notification-manager__component_1umri {
45
+ .notification-manager__component_18uty {
46
46
  right: var(--gap-4xl);
47
47
  }
48
48
 
49
- .notification-manager__component_1umri .notification-manager__notification_1umri {
49
+ .notification-manager__component_18uty .notification-manager__notification_18uty {
50
50
  width: auto;
51
51
  }
52
52
 
53
- .notification-manager__enter_1umri {
53
+ .notification-manager__enter_18uty {
54
54
  transform: translate(100%, 0);
55
55
  }
56
56
 
57
- .notification-manager__enterActive_1umri {
57
+ .notification-manager__enterActive_18uty {
58
58
  transform: translate(0);
59
59
  }
60
60
  }
@@ -5,7 +5,7 @@ import { Portal } from '@alfalab/core-components-portal/modern';
5
5
  import { Stack, stackingOrder } from '@alfalab/core-components-stack/modern';
6
6
  import { Notification } from './components/notification/component.js';
7
7
 
8
- const styles = {"component":"notification-manager__component_1umri","notification":"notification-manager__notification_1umri","enter":"notification-manager__enter_1umri","enterActive":"notification-manager__enterActive_1umri","exit":"notification-manager__exit_1umri","exitActive":"notification-manager__exitActive_1umri"};
8
+ const styles = {"component":"notification-manager__component_18uty","notification":"notification-manager__notification_18uty","enter":"notification-manager__enter_18uty","enterActive":"notification-manager__enterActive_18uty","exit":"notification-manager__exit_18uty","exitActive":"notification-manager__exitActive_18uty"};
9
9
  require('./index.css')
10
10
 
11
11
  const CSS_TRANSITION_CLASS_NAMES = {
package/modern/index.css CHANGED
@@ -1,11 +1,11 @@
1
- /* hash: a45ka */
1
+ /* hash: 1rgsa */
2
2
  :root {
3
3
  --gap-s: 12px;
4
4
  --gap-xl: 24px;
5
5
  --gap-4xl: 48px;
6
6
  }
7
7
 
8
- .notification-manager__component_1umri {
8
+ .notification-manager__component_18uty {
9
9
  position: fixed;
10
10
  top: 0;
11
11
  right: var(--gap-s);
@@ -13,48 +13,48 @@
13
13
  flex-direction: column;
14
14
  }
15
15
 
16
- .notification-manager__component_1umri .notification-manager__notification_1umri {
16
+ .notification-manager__component_18uty .notification-manager__notification_18uty {
17
17
  position: static;
18
18
  width: calc(100vw - var(--gap-xl));
19
19
  margin-top: var(--gap-s);
20
20
  will-change: transform;
21
21
  }
22
22
 
23
- .notification-manager__enter_1umri {
23
+ .notification-manager__enter_18uty {
24
24
  visibility: hidden;
25
25
  transform: translate(0, -500px);
26
26
  }
27
27
 
28
- .notification-manager__enterActive_1umri {
28
+ .notification-manager__enterActive_18uty {
29
29
  visibility: visible;
30
30
  transform: translate(0);
31
31
  transition: transform 0.4s ease-out;
32
32
  }
33
33
 
34
- .notification-manager__exit_1umri {
34
+ .notification-manager__exit_18uty {
35
35
  opacity: 0;
36
36
  }
37
37
 
38
- .notification-manager__exitActive_1umri {
38
+ .notification-manager__exitActive_18uty {
39
39
  visibility: hidden;
40
40
  opacity: 0;
41
41
  transition: opacity 0.15s ease-in-out;
42
42
  }
43
43
 
44
44
  @media (min-width: 600px) {
45
- .notification-manager__component_1umri {
45
+ .notification-manager__component_18uty {
46
46
  right: var(--gap-4xl);
47
47
  }
48
48
 
49
- .notification-manager__component_1umri .notification-manager__notification_1umri {
49
+ .notification-manager__component_18uty .notification-manager__notification_18uty {
50
50
  width: auto;
51
51
  }
52
52
 
53
- .notification-manager__enter_1umri {
53
+ .notification-manager__enter_18uty {
54
54
  transform: translate(100%, 0);
55
55
  }
56
56
 
57
- .notification-manager__enterActive_1umri {
57
+ .notification-manager__enterActive_18uty {
58
58
  transform: translate(0);
59
59
  }
60
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfalab/core-components-notification-manager",
3
- "version": "5.2.9",
3
+ "version": "5.3.1",
4
4
  "description": "Notification manager",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -14,9 +14,9 @@
14
14
  "react": "^16.9.0 || ^17.0.1 || ^18.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@alfalab/core-components-notification": "^6.1.27",
18
- "@alfalab/core-components-portal": "^3.1.5",
19
- "@alfalab/core-components-stack": "^4.0.4",
17
+ "@alfalab/core-components-notification": "^6.2.1",
18
+ "@alfalab/core-components-portal": "^3.2.0",
19
+ "@alfalab/core-components-stack": "^4.1.0",
20
20
  "classnames": "^2.3.1",
21
21
  "react-transition-group": "^4.4.5",
22
22
  "tslib": "^2.4.0"
@@ -0,0 +1,102 @@
1
+ import React, { forwardRef, HTMLAttributes } from 'react';
2
+ import { CSSTransition, TransitionGroup } from 'react-transition-group';
3
+ import cn from 'classnames';
4
+
5
+ import { Portal, PortalProps } from '@alfalab/core-components-portal';
6
+ import { Stack, stackingOrder } from '@alfalab/core-components-stack';
7
+
8
+ import { Notification, NotificationElement } from './components';
9
+
10
+ import styles from './index.module.css';
11
+
12
+ export type NotificationManagerProps = HTMLAttributes<HTMLDivElement> & {
13
+ /**
14
+ * Массив нотификаций.
15
+ * В нотификации обязательно передавайте id.
16
+ */
17
+ notifications: NotificationElement[];
18
+
19
+ /**
20
+ * Дополнительный класс (native prop)
21
+ */
22
+ className?: string;
23
+
24
+ /**
25
+ * Идентификатор для систем автоматизированного тестирования
26
+ */
27
+ dataTestId?: string;
28
+
29
+ /**
30
+ * z-index компонента
31
+ */
32
+ zIndex?: number;
33
+
34
+ /**
35
+ * Удаление нотификации
36
+ */
37
+ onRemoveNotification: (id: string) => void;
38
+
39
+ /**
40
+ * Нода, компонент или функция возвращающая их
41
+ *
42
+ * Контейнер к которому будут добавляться порталы
43
+ */
44
+ container?: PortalProps['getPortalContainer'];
45
+ };
46
+
47
+ const CSS_TRANSITION_CLASS_NAMES = {
48
+ enter: styles.enter,
49
+ enterActive: styles.enterActive,
50
+ exit: styles.exit,
51
+ exitActive: styles.exitActive,
52
+ };
53
+
54
+ export const NotificationManager = forwardRef<HTMLDivElement, NotificationManagerProps>(
55
+ (
56
+ {
57
+ notifications,
58
+ className,
59
+ dataTestId,
60
+ zIndex = stackingOrder.TOAST,
61
+ style = {},
62
+ onRemoveNotification,
63
+ container,
64
+ ...restProps
65
+ },
66
+ ref,
67
+ ) => (
68
+ <Stack value={zIndex}>
69
+ {(computedZIndex) => (
70
+ <Portal getPortalContainer={container}>
71
+ <div
72
+ className={cn(styles.component, className)}
73
+ ref={ref}
74
+ data-test-id={dataTestId}
75
+ style={{
76
+ zIndex: computedZIndex,
77
+ ...style,
78
+ }}
79
+ {...restProps}
80
+ >
81
+ <TransitionGroup>
82
+ {notifications.map((element) => (
83
+ <CSSTransition
84
+ key={element.props.id}
85
+ timeout={400}
86
+ classNames={CSS_TRANSITION_CLASS_NAMES}
87
+ unmountOnExit={true}
88
+ >
89
+ <Notification
90
+ element={element}
91
+ className={styles.notification}
92
+ onRemoveNotification={onRemoveNotification}
93
+ />
94
+ </CSSTransition>
95
+ ))}
96
+ </TransitionGroup>
97
+ </div>
98
+ </Portal>
99
+ )}
100
+ </Stack>
101
+ ),
102
+ );
@@ -0,0 +1 @@
1
+ export * from './notification';
@@ -0,0 +1,51 @@
1
+ import { cloneElement, FC, ReactElement, useCallback, useMemo } from 'react';
2
+ import cn from 'classnames';
3
+
4
+ import { NotificationProps as CoreNotificationProps } from '@alfalab/core-components-notification';
5
+
6
+ export type NotificationElement = ReactElement<CoreNotificationProps & { id: string }>;
7
+
8
+ type NotificationProps = {
9
+ element: NotificationElement;
10
+ className: string;
11
+ onRemoveNotification: (id: string) => void;
12
+ };
13
+
14
+ export const Notification: FC<NotificationProps> = ({
15
+ element,
16
+ className,
17
+ onRemoveNotification,
18
+ }) => {
19
+ const { onClose, onCloseTimeout } = element.props;
20
+
21
+ const handleClose = useCallback(() => {
22
+ if (onClose) {
23
+ onClose();
24
+ }
25
+
26
+ onRemoveNotification(element.props.id);
27
+ }, [onClose, onRemoveNotification, element.props.id]);
28
+
29
+ const handleCloseTimeout = useCallback(() => {
30
+ if (onCloseTimeout) {
31
+ onCloseTimeout();
32
+ }
33
+
34
+ onRemoveNotification(element.props.id);
35
+ }, [element.props.id, onCloseTimeout, onRemoveNotification]);
36
+
37
+ const notificationProps = useMemo<CoreNotificationProps>(
38
+ () => ({
39
+ ...element.props,
40
+ visible: true,
41
+ className: cn(className, element.props.className),
42
+ usePortal: false,
43
+ offset: 0,
44
+ onClose: handleClose,
45
+ onCloseTimeout: handleCloseTimeout,
46
+ }),
47
+ [element, handleClose, handleCloseTimeout, className],
48
+ );
49
+
50
+ return cloneElement(element, notificationProps);
51
+ };
@@ -0,0 +1 @@
1
+ export * from './component';
@@ -0,0 +1,55 @@
1
+ @import '@alfalab/core-components-vars/src/gaps.css';
2
+
3
+ .component {
4
+ position: fixed;
5
+ top: 0;
6
+ right: var(--gap-s);
7
+ display: flex;
8
+ flex-direction: column;
9
+ }
10
+
11
+ .component .notification {
12
+ position: static;
13
+ width: calc(100vw - var(--gap-xl));
14
+ margin-top: var(--gap-s);
15
+ will-change: transform;
16
+ }
17
+
18
+ .enter {
19
+ visibility: hidden;
20
+ transform: translate(0, -500px);
21
+ }
22
+
23
+ .enterActive {
24
+ visibility: visible;
25
+ transform: translate(0);
26
+ transition: transform 0.4s ease-out;
27
+ }
28
+
29
+ .exit {
30
+ opacity: 0;
31
+ }
32
+
33
+ .exitActive {
34
+ visibility: hidden;
35
+ opacity: 0;
36
+ transition: opacity 0.15s ease-in-out;
37
+ }
38
+
39
+ @media (--tablet-s) {
40
+ .component {
41
+ right: var(--gap-4xl);
42
+ }
43
+
44
+ .component .notification {
45
+ width: auto;
46
+ }
47
+
48
+ .enter {
49
+ transform: translate(100%, 0);
50
+ }
51
+
52
+ .enterActive {
53
+ transform: translate(0);
54
+ }
55
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './component';