@teambit/notifications 0.0.566 → 0.0.570

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.
@@ -0,0 +1,21 @@
1
+ import { Message } from '@teambit/ui-foundation.ui.notifications.store';
2
+
3
+ export type NotificationAction = {
4
+ type: 'add' | 'dismiss' | 'clear';
5
+ content?: Message;
6
+ id?: string;
7
+ };
8
+
9
+ export function notificationReducer(state: Message[], action: NotificationAction) {
10
+ switch (action.type) {
11
+ case 'dismiss':
12
+ return state.filter((x) => x.id !== action.id);
13
+ case 'add':
14
+ if (!action.content) return state;
15
+ return state.concat(action.content);
16
+ case 'clear':
17
+ return [];
18
+ default:
19
+ return state;
20
+ }
21
+ }
@@ -0,0 +1,87 @@
1
+ import { UIAspect, UIRuntime, UiUI } from '@teambit/ui';
2
+ import React, { ReactNode, useReducer } from 'react';
3
+ import { v1 } from 'uuid';
4
+
5
+ import { NotificationContext } from '@teambit/ui-foundation.ui.notifications.notification-context';
6
+ import {
7
+ NotificationCenter,
8
+ NotificationCenterProps,
9
+ } from '@teambit/ui-foundation.ui.notifications.notification-center';
10
+ import { MessageLevel, NotificationsStore } from '@teambit/ui-foundation.ui.notifications.store';
11
+ import { NotificationAction, notificationReducer } from './notification-reducer';
12
+ import { NotificationsAspect } from './notifications.aspect';
13
+
14
+ /**
15
+ * extension
16
+ */
17
+ export default class NotificationUI implements NotificationsStore {
18
+ static dependencies = [UIAspect];
19
+
20
+ static runtime = UIRuntime;
21
+
22
+ static async provider([uiRuntimeExtension]: [UiUI]) {
23
+ return new NotificationUI(uiRuntimeExtension);
24
+ }
25
+
26
+ constructor(uiRuntimeExtension: UiUI) {
27
+ uiRuntimeExtension.registerHudItem(<this.render key="NotificationUI" />);
28
+ uiRuntimeExtension.registerContext(this.renderContext);
29
+ }
30
+
31
+ private dispatch?: React.Dispatch<NotificationAction>;
32
+
33
+ /** adds a full message to the log */
34
+ add = (message: string, level: MessageLevel) => {
35
+ const id = v1();
36
+
37
+ this.dispatch?.({
38
+ type: 'add',
39
+ content: {
40
+ id,
41
+ message,
42
+ level,
43
+ time: new Date().toISOString(),
44
+ },
45
+ });
46
+
47
+ return id;
48
+ };
49
+
50
+ /** removes/archives a message from the log */
51
+ dismiss(id: string) {
52
+ this.dispatch?.({
53
+ type: 'dismiss',
54
+ id,
55
+ });
56
+ }
57
+
58
+ /** adds a message with level "info" to the log */
59
+ log = (message: string) => this.add(message, MessageLevel.info);
60
+ /** adds a message with level "warning" to the log */
61
+ warn = (message: string) => this.add(message, MessageLevel.warning);
62
+ /** adds a message with level "error" to the log */
63
+ error = (message: string) => this.add(message, MessageLevel.error);
64
+ /** adds a message with level "success" to the log */
65
+ success = (message: string) => this.add(message, MessageLevel.success);
66
+
67
+ /** removes all notifications */
68
+ clear = () => {
69
+ this.dispatch?.({
70
+ type: 'clear',
71
+ });
72
+ };
73
+
74
+ private render = (props: Omit<NotificationCenterProps, 'notifications'>) => {
75
+ // this code assumes a single place of render per instance of NotificationUI
76
+ const [messages, dispatch] = useReducer(notificationReducer, []);
77
+ this.dispatch = dispatch;
78
+
79
+ return <NotificationCenter {...props} notifications={messages} />;
80
+ };
81
+
82
+ private renderContext = ({ children }: { children: ReactNode }) => {
83
+ return <NotificationContext.Provider value={this}>{children}</NotificationContext.Provider>;
84
+ };
85
+ }
86
+
87
+ NotificationsAspect.addRuntime(NotificationUI);
package/package.json CHANGED
@@ -1,22 +1,22 @@
1
1
  {
2
2
  "name": "@teambit/notifications",
3
- "version": "0.0.566",
3
+ "version": "0.0.570",
4
4
  "homepage": "https://bit.dev/teambit/ui-foundation/notifications",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.ui-foundation",
8
8
  "name": "notifications",
9
- "version": "0.0.566"
9
+ "version": "0.0.570"
10
10
  },
11
11
  "dependencies": {
12
12
  "uuid": "3.4.0",
13
13
  "@teambit/harmony": "0.2.11",
14
14
  "@babel/runtime": "7.12.18",
15
15
  "core-js": "^3.0.0",
16
- "@teambit/ui-foundation.ui.notifications.store": "0.0.470",
17
- "@teambit/ui-foundation.ui.notifications.notification-center": "0.0.475",
18
- "@teambit/ui-foundation.ui.notifications.notification-context": "0.0.471",
19
- "@teambit/ui": "0.0.566"
16
+ "@teambit/ui-foundation.ui.notifications.store": "0.0.472",
17
+ "@teambit/ui-foundation.ui.notifications.notification-center": "0.0.477",
18
+ "@teambit/ui-foundation.ui.notifications.notification-context": "0.0.473",
19
+ "@teambit/ui": "0.0.570"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/react": "^17.0.8",
@@ -28,7 +28,7 @@
28
28
  "@types/node": "12.20.4"
29
29
  },
30
30
  "peerDependencies": {
31
- "@teambit/legacy": "1.0.179",
31
+ "@teambit/legacy": "1.0.181",
32
32
  "react-dom": "^16.8.0 || ^17.0.0",
33
33
  "react": "^16.8.0 || ^17.0.0"
34
34
  },
@@ -56,27 +56,12 @@
56
56
  "react": "-"
57
57
  },
58
58
  "peerDependencies": {
59
- "@teambit/legacy": "1.0.179",
59
+ "@teambit/legacy": "1.0.181",
60
60
  "react-dom": "^16.8.0 || ^17.0.0",
61
61
  "react": "^16.8.0 || ^17.0.0"
62
62
  }
63
63
  }
64
64
  },
65
- "files": [
66
- "dist",
67
- "!dist/tsconfig.tsbuildinfo",
68
- "**/*.md",
69
- "**/*.mdx",
70
- "**/*.js",
71
- "**/*.json",
72
- "**/*.sass",
73
- "**/*.scss",
74
- "**/*.less",
75
- "**/*.css",
76
- "**/*.css",
77
- "**/*.jpeg",
78
- "**/*.gif"
79
- ],
80
65
  "private": false,
81
66
  "engines": {
82
67
  "node": ">=12.22.0"
@@ -0,0 +1,29 @@
1
+ declare module '*.png' {
2
+ const value: any;
3
+ export = value;
4
+ }
5
+ declare module '*.svg' {
6
+ import type { FunctionComponent, SVGProps } from 'react';
7
+
8
+ export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
9
+ const src: string;
10
+ export default src;
11
+ }
12
+
13
+ // @TODO Gilad
14
+ declare module '*.jpg' {
15
+ const value: any;
16
+ export = value;
17
+ }
18
+ declare module '*.jpeg' {
19
+ const value: any;
20
+ export = value;
21
+ }
22
+ declare module '*.gif' {
23
+ const value: any;
24
+ export = value;
25
+ }
26
+ declare module '*.bmp' {
27
+ const value: any;
28
+ export = value;
29
+ }
@@ -0,0 +1,42 @@
1
+ declare module '*.module.css' {
2
+ const classes: { readonly [key: string]: string };
3
+ export default classes;
4
+ }
5
+ declare module '*.module.scss' {
6
+ const classes: { readonly [key: string]: string };
7
+ export default classes;
8
+ }
9
+ declare module '*.module.sass' {
10
+ const classes: { readonly [key: string]: string };
11
+ export default classes;
12
+ }
13
+
14
+ declare module '*.module.less' {
15
+ const classes: { readonly [key: string]: string };
16
+ export default classes;
17
+ }
18
+
19
+ declare module '*.less' {
20
+ const classes: { readonly [key: string]: string };
21
+ export default classes;
22
+ }
23
+
24
+ declare module '*.css' {
25
+ const classes: { readonly [key: string]: string };
26
+ export default classes;
27
+ }
28
+
29
+ declare module '*.sass' {
30
+ const classes: { readonly [key: string]: string };
31
+ export default classes;
32
+ }
33
+
34
+ declare module '*.scss' {
35
+ const classes: { readonly [key: string]: string };
36
+ export default classes;
37
+ }
38
+
39
+ declare module '*.mdx' {
40
+ const component: any;
41
+ export default component;
42
+ }