@alfalab/core-components-notification-manager 5.2.8 → 5.3.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/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_dmwvq","notification":"notification-manager__notification_dmwvq","enter":"notification-manager__enter_dmwvq","enterActive":"notification-manager__enterActive_dmwvq","exit":"notification-manager__exit_dmwvq","exitActive":"notification-manager__exitActive_dmwvq"};
18
+ var styles = {"component":"notification-manager__component_1awn9","notification":"notification-manager__notification_1awn9","enter":"notification-manager__enter_1awn9","enterActive":"notification-manager__enterActive_1awn9","exit":"notification-manager__exit_1awn9","exitActive":"notification-manager__exitActive_1awn9"};
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_dmwvq","notification":"notification-manager__notification_dmwvq","enter":"notification-manager__enter_dmwvq","enterActive":"notification-manager__enterActive_dmwvq","exit":"notification-manager__exit_dmwvq","exitActive":"notification-manager__exitActive_dmwvq"};
9
+ var styles = {"component":"notification-manager__component_1awn9","notification":"notification-manager__notification_1awn9","enter":"notification-manager__enter_1awn9","enterActive":"notification-manager__enterActive_1awn9","exit":"notification-manager__exit_1awn9","exitActive":"notification-manager__exitActive_1awn9"};
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: 1mcng */
1
+ /* hash: 16vys */
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_dmwvq {
8
+ .notification-manager__component_1awn9 {
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_dmwvq .notification-manager__notification_dmwvq {
16
+ .notification-manager__component_1awn9 .notification-manager__notification_1awn9 {
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_dmwvq {
23
+ .notification-manager__enter_1awn9 {
24
24
  visibility: hidden;
25
25
  transform: translate(0, -500px);
26
26
  }
27
27
 
28
- .notification-manager__enterActive_dmwvq {
28
+ .notification-manager__enterActive_1awn9 {
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_dmwvq {
34
+ .notification-manager__exit_1awn9 {
35
35
  opacity: 0;
36
36
  }
37
37
 
38
- .notification-manager__exitActive_dmwvq {
38
+ .notification-manager__exitActive_1awn9 {
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_dmwvq {
45
+ .notification-manager__component_1awn9 {
46
46
  right: var(--gap-4xl);
47
47
  }
48
48
 
49
- .notification-manager__component_dmwvq .notification-manager__notification_dmwvq {
49
+ .notification-manager__component_1awn9 .notification-manager__notification_1awn9 {
50
50
  width: auto;
51
51
  }
52
52
 
53
- .notification-manager__enter_dmwvq {
53
+ .notification-manager__enter_1awn9 {
54
54
  transform: translate(100%, 0);
55
55
  }
56
56
 
57
- .notification-manager__enterActive_dmwvq {
57
+ .notification-manager__enterActive_1awn9 {
58
58
  transform: translate(0);
59
59
  }
60
60
  }
package/index.css CHANGED
@@ -1,11 +1,11 @@
1
- /* hash: 1mcng */
1
+ /* hash: 16vys */
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_dmwvq {
8
+ .notification-manager__component_1awn9 {
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_dmwvq .notification-manager__notification_dmwvq {
16
+ .notification-manager__component_1awn9 .notification-manager__notification_1awn9 {
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_dmwvq {
23
+ .notification-manager__enter_1awn9 {
24
24
  visibility: hidden;
25
25
  transform: translate(0, -500px);
26
26
  }
27
27
 
28
- .notification-manager__enterActive_dmwvq {
28
+ .notification-manager__enterActive_1awn9 {
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_dmwvq {
34
+ .notification-manager__exit_1awn9 {
35
35
  opacity: 0;
36
36
  }
37
37
 
38
- .notification-manager__exitActive_dmwvq {
38
+ .notification-manager__exitActive_1awn9 {
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_dmwvq {
45
+ .notification-manager__component_1awn9 {
46
46
  right: var(--gap-4xl);
47
47
  }
48
48
 
49
- .notification-manager__component_dmwvq .notification-manager__notification_dmwvq {
49
+ .notification-manager__component_1awn9 .notification-manager__notification_1awn9 {
50
50
  width: auto;
51
51
  }
52
52
 
53
- .notification-manager__enter_dmwvq {
53
+ .notification-manager__enter_1awn9 {
54
54
  transform: translate(100%, 0);
55
55
  }
56
56
 
57
- .notification-manager__enterActive_dmwvq {
57
+ .notification-manager__enterActive_1awn9 {
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_dmwvq","notification":"notification-manager__notification_dmwvq","enter":"notification-manager__enter_dmwvq","enterActive":"notification-manager__enterActive_dmwvq","exit":"notification-manager__exit_dmwvq","exitActive":"notification-manager__exitActive_dmwvq"};
8
+ const styles = {"component":"notification-manager__component_1awn9","notification":"notification-manager__notification_1awn9","enter":"notification-manager__enter_1awn9","enterActive":"notification-manager__enterActive_1awn9","exit":"notification-manager__exit_1awn9","exitActive":"notification-manager__exitActive_1awn9"};
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: 1mcng */
1
+ /* hash: 16vys */
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_dmwvq {
8
+ .notification-manager__component_1awn9 {
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_dmwvq .notification-manager__notification_dmwvq {
16
+ .notification-manager__component_1awn9 .notification-manager__notification_1awn9 {
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_dmwvq {
23
+ .notification-manager__enter_1awn9 {
24
24
  visibility: hidden;
25
25
  transform: translate(0, -500px);
26
26
  }
27
27
 
28
- .notification-manager__enterActive_dmwvq {
28
+ .notification-manager__enterActive_1awn9 {
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_dmwvq {
34
+ .notification-manager__exit_1awn9 {
35
35
  opacity: 0;
36
36
  }
37
37
 
38
- .notification-manager__exitActive_dmwvq {
38
+ .notification-manager__exitActive_1awn9 {
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_dmwvq {
45
+ .notification-manager__component_1awn9 {
46
46
  right: var(--gap-4xl);
47
47
  }
48
48
 
49
- .notification-manager__component_dmwvq .notification-manager__notification_dmwvq {
49
+ .notification-manager__component_1awn9 .notification-manager__notification_1awn9 {
50
50
  width: auto;
51
51
  }
52
52
 
53
- .notification-manager__enter_dmwvq {
53
+ .notification-manager__enter_1awn9 {
54
54
  transform: translate(100%, 0);
55
55
  }
56
56
 
57
- .notification-manager__enterActive_dmwvq {
57
+ .notification-manager__enterActive_1awn9 {
58
58
  transform: translate(0);
59
59
  }
60
60
  }
package/package.json CHANGED
@@ -1,14 +1,11 @@
1
1
  {
2
2
  "name": "@alfalab/core-components-notification-manager",
3
- "version": "5.2.8",
3
+ "version": "5.3.0",
4
4
  "description": "Notification manager",
5
5
  "keywords": [],
6
6
  "license": "MIT",
7
7
  "main": "index.js",
8
8
  "module": "./esm/index.js",
9
- "scripts": {
10
- "postinstall": "node -e \"if (require('fs').existsSync('./send-stats.js')){require('./send-stats.js')} \""
11
- },
12
9
  "publishConfig": {
13
10
  "access": "public",
14
11
  "directory": "dist"
@@ -17,9 +14,9 @@
17
14
  "react": "^16.9.0 || ^17.0.1 || ^18.0.0"
18
15
  },
19
16
  "dependencies": {
20
- "@alfalab/core-components-notification": "^6.1.26",
21
- "@alfalab/core-components-portal": "^3.1.4",
22
- "@alfalab/core-components-stack": "^4.0.4",
17
+ "@alfalab/core-components-notification": "^6.2.0",
18
+ "@alfalab/core-components-portal": "^3.2.0",
19
+ "@alfalab/core-components-stack": "^4.1.0",
23
20
  "classnames": "^2.3.1",
24
21
  "react-transition-group": "^4.4.5",
25
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';
package/send-stats.js DELETED
@@ -1,82 +0,0 @@
1
- const http = require('http');
2
- const fs = require('fs');
3
- const { promisify } = require('util');
4
- const path = require('path');
5
-
6
- const readFile = promisify(fs.readFile);
7
-
8
- async function main() {
9
- const remoteHost = process.env.NIS_HOST || 'digital';
10
- const remotePort = process.env.NIS_PORT || 80;
11
- const remotePath = process.env.NIS_PATH || '/npm-install-stats/api/install-stats';
12
-
13
- try {
14
- const [_, node, os, arch] =
15
- /node\/v(\d+\.\d+\.\d+) (\w+) (\w+)/.exec(process.env.npm_config_user_agent) || [];
16
- const [__, npm] = /npm\/(\d+\.\d+\.\d+)/.exec(process.env.npm_config_user_agent) || [];
17
- const [___, yarn] = /yarn\/(\d+\.\d+\.\d+)/.exec(process.env.npm_config_user_agent) || [];
18
-
19
- let ownPackageJson, packageJson;
20
-
21
- try {
22
- const result = await Promise.all([
23
- readFile(path.join(process.cwd(), 'package.json'), 'utf-8'),
24
- readFile(path.join(process.cwd(), '../../../package.json'), 'utf-8'),
25
- ]);
26
-
27
- ownPackageJson = JSON.parse(result[0]);
28
- packageJson = JSON.parse(result[1]);
29
- } catch (err) {
30
- ownPackageJson = '';
31
- packageJson = '';
32
- }
33
-
34
- const data = {
35
- node,
36
- npm,
37
- yarn,
38
- os,
39
- arch,
40
- ownPackageJson: JSON.stringify(ownPackageJson),
41
- packageJson: JSON.stringify(packageJson),
42
- };
43
-
44
- const body = JSON.stringify(data);
45
-
46
- const options = {
47
- host: remoteHost,
48
- port: remotePort,
49
- path: remotePath,
50
- method: 'POST',
51
- headers: {
52
- 'Content-Type': 'application/json',
53
- 'Content-Length': body.length,
54
- },
55
- };
56
-
57
- return new Promise((resolve, reject) => {
58
- const req = http.request(options, (res) => {
59
- res.on('end', () => {
60
- resolve();
61
- });
62
- });
63
-
64
- req.on('error', () => {
65
- reject();
66
- });
67
-
68
- req.write(body);
69
- req.end();
70
- });
71
- } catch (error) {
72
- throw error;
73
- }
74
- }
75
-
76
- main()
77
- .then(() => {
78
- process.exit(0);
79
- })
80
- .catch(() => {
81
- process.exit(0);
82
- });