@genesislcap/foundation-notifications 14.50.2-alpha-f13a8e3.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.
Files changed (135) hide show
  1. package/README.md +66 -0
  2. package/dist/dts/banner/banner-builder.d.ts +35 -0
  3. package/dist/dts/banner/banner-builder.d.ts.map +1 -0
  4. package/dist/dts/banner/banner-launcher.d.ts +11 -0
  5. package/dist/dts/banner/banner-launcher.d.ts.map +1 -0
  6. package/dist/dts/banner/index.d.ts +3 -0
  7. package/dist/dts/banner/index.d.ts.map +1 -0
  8. package/dist/dts/dialog/dialog-builder.d.ts +35 -0
  9. package/dist/dts/dialog/dialog-builder.d.ts.map +1 -0
  10. package/dist/dts/dialog/dialog-launcher.d.ts +10 -0
  11. package/dist/dts/dialog/dialog-launcher.d.ts.map +1 -0
  12. package/dist/dts/dialog/index.d.ts +3 -0
  13. package/dist/dts/dialog/index.d.ts.map +1 -0
  14. package/dist/dts/index.d.ts +9 -0
  15. package/dist/dts/index.d.ts.map +1 -0
  16. package/dist/dts/index.federated.d.ts +1 -0
  17. package/dist/dts/index.federated.d.ts.map +1 -0
  18. package/dist/dts/logger.d.ts +2 -0
  19. package/dist/dts/logger.d.ts.map +1 -0
  20. package/dist/dts/notification-builder.d.ts +83 -0
  21. package/dist/dts/notification-builder.d.ts.map +1 -0
  22. package/dist/dts/notification-launcher.d.ts +11 -0
  23. package/dist/dts/notification-launcher.d.ts.map +1 -0
  24. package/dist/dts/notification-util.d.ts +32 -0
  25. package/dist/dts/notification-util.d.ts.map +1 -0
  26. package/dist/dts/snackbar/index.d.ts +3 -0
  27. package/dist/dts/snackbar/index.d.ts.map +1 -0
  28. package/dist/dts/snackbar/snackbar-builder.d.ts +34 -0
  29. package/dist/dts/snackbar/snackbar-builder.d.ts.map +1 -0
  30. package/dist/dts/snackbar/snackbar-launcher.d.ts +10 -0
  31. package/dist/dts/snackbar/snackbar-launcher.d.ts.map +1 -0
  32. package/dist/dts/toast/index.d.ts +3 -0
  33. package/dist/dts/toast/index.d.ts.map +1 -0
  34. package/dist/dts/toast/toast-builder.d.ts +49 -0
  35. package/dist/dts/toast/toast-builder.d.ts.map +1 -0
  36. package/dist/dts/toast/toast-launcher.d.ts +10 -0
  37. package/dist/dts/toast/toast-launcher.d.ts.map +1 -0
  38. package/dist/dts/tsdoc-metadata.json +11 -0
  39. package/dist/dts/types.d.ts +106 -0
  40. package/dist/dts/types.d.ts.map +1 -0
  41. package/dist/esm/banner/banner-builder.js +49 -0
  42. package/dist/esm/banner/banner-launcher.js +23 -0
  43. package/dist/esm/banner/index.js +2 -0
  44. package/dist/esm/dialog/dialog-builder.js +49 -0
  45. package/dist/esm/dialog/dialog-launcher.js +16 -0
  46. package/dist/esm/dialog/index.js +2 -0
  47. package/dist/esm/index.federated.js +1 -0
  48. package/dist/esm/index.js +8 -0
  49. package/dist/esm/logger.js +2 -0
  50. package/dist/esm/notification-builder.js +133 -0
  51. package/dist/esm/notification-launcher.js +36 -0
  52. package/dist/esm/notification-util.js +67 -0
  53. package/dist/esm/snackbar/index.js +2 -0
  54. package/dist/esm/snackbar/snackbar-builder.js +48 -0
  55. package/dist/esm/snackbar/snackbar-launcher.js +15 -0
  56. package/dist/esm/toast/index.js +2 -0
  57. package/dist/esm/toast/toast-builder.js +70 -0
  58. package/dist/esm/toast/toast-launcher.js +54 -0
  59. package/dist/esm/types.js +8 -0
  60. package/dist/foundation-notifications.api.json +2531 -0
  61. package/dist/foundation-notifications.d.ts +435 -0
  62. package/docs/.gitattributes +2 -0
  63. package/docs/api/foundation-notifications.banner.confirmingactions.md +11 -0
  64. package/docs/api/foundation-notifications.banner.dismissingaction.md +11 -0
  65. package/docs/api/foundation-notifications.banner.md +21 -0
  66. package/docs/api/foundation-notifications.bannerbuilder.build.md +19 -0
  67. package/docs/api/foundation-notifications.bannerbuilder.md +22 -0
  68. package/docs/api/foundation-notifications.bannerbuilder.withconfirmingaction.md +25 -0
  69. package/docs/api/foundation-notifications.bannerbuilder.withdismissingaction.md +25 -0
  70. package/docs/api/foundation-notifications.confirmingaction.action.md +11 -0
  71. package/docs/api/foundation-notifications.confirmingaction.label.md +11 -0
  72. package/docs/api/foundation-notifications.confirmingaction.md +21 -0
  73. package/docs/api/foundation-notifications.dialog.confirmingactions.md +11 -0
  74. package/docs/api/foundation-notifications.dialog.dismissingaction.md +11 -0
  75. package/docs/api/foundation-notifications.dialog.md +21 -0
  76. package/docs/api/foundation-notifications.dialogbuilder.build.md +19 -0
  77. package/docs/api/foundation-notifications.dialogbuilder.md +22 -0
  78. package/docs/api/foundation-notifications.dialogbuilder.withconfirmingaction.md +25 -0
  79. package/docs/api/foundation-notifications.dialogbuilder.withdismissingaction.md +25 -0
  80. package/docs/api/foundation-notifications.dismissingaction.action.md +11 -0
  81. package/docs/api/foundation-notifications.dismissingaction.label.md +11 -0
  82. package/docs/api/foundation-notifications.dismissingaction.md +21 -0
  83. package/docs/api/foundation-notifications.getbanneranchor.md +13 -0
  84. package/docs/api/foundation-notifications.getbannerbuilder.md +13 -0
  85. package/docs/api/foundation-notifications.getdialogbuilder.md +13 -0
  86. package/docs/api/foundation-notifications.getloglevel.md +13 -0
  87. package/docs/api/foundation-notifications.getnotificationbuilder.md +13 -0
  88. package/docs/api/foundation-notifications.getnotificationcontainer.md +13 -0
  89. package/docs/api/foundation-notifications.getnotificationdetails.md +13 -0
  90. package/docs/api/foundation-notifications.getsnackbarbuilder.md +13 -0
  91. package/docs/api/foundation-notifications.gettoastbuilder.md +13 -0
  92. package/docs/api/foundation-notifications.md +58 -0
  93. package/docs/api/foundation-notifications.notificationbuilder.build.md +18 -0
  94. package/docs/api/foundation-notifications.notificationbuilder.md +28 -0
  95. package/docs/api/foundation-notifications.notificationbuilder.withalert.md +25 -0
  96. package/docs/api/foundation-notifications.notificationbuilder.withbanner.md +25 -0
  97. package/docs/api/foundation-notifications.notificationbuilder.withbody.md +25 -0
  98. package/docs/api/foundation-notifications.notificationbuilder.withdialog.md +25 -0
  99. package/docs/api/foundation-notifications.notificationbuilder.withloglevel.md +25 -0
  100. package/docs/api/foundation-notifications.notificationbuilder.withsnackbar.md +25 -0
  101. package/docs/api/foundation-notifications.notificationbuilder.withtitle.md +25 -0
  102. package/docs/api/foundation-notifications.notificationbuilder.withtoast.md +25 -0
  103. package/docs/api/foundation-notifications.notificationevent.md +20 -0
  104. package/docs/api/foundation-notifications.notificationstructure.body.md +11 -0
  105. package/docs/api/foundation-notifications.notificationstructure.config.md +18 -0
  106. package/docs/api/foundation-notifications.notificationstructure.loglevel.md +11 -0
  107. package/docs/api/foundation-notifications.notificationstructure.md +23 -0
  108. package/docs/api/foundation-notifications.notificationstructure.title.md +11 -0
  109. package/docs/api/foundation-notifications.notificationtype.md +13 -0
  110. package/docs/api/foundation-notifications.showbanner.md +13 -0
  111. package/docs/api/foundation-notifications.shownotification.md +13 -0
  112. package/docs/api/foundation-notifications.snackbar.confirmingactions.md +11 -0
  113. package/docs/api/foundation-notifications.snackbar.md +21 -0
  114. package/docs/api/foundation-notifications.snackbar.type.md +11 -0
  115. package/docs/api/foundation-notifications.snackbarbuilder.build.md +19 -0
  116. package/docs/api/foundation-notifications.snackbarbuilder.md +22 -0
  117. package/docs/api/foundation-notifications.snackbarbuilder.withconfirmingaction.md +25 -0
  118. package/docs/api/foundation-notifications.snackbarbuilder.withtype.md +23 -0
  119. package/docs/api/foundation-notifications.snackbartype.md +13 -0
  120. package/docs/api/foundation-notifications.toast.autoclose.md +11 -0
  121. package/docs/api/foundation-notifications.toast.closetimeout.md +11 -0
  122. package/docs/api/foundation-notifications.toast.md +23 -0
  123. package/docs/api/foundation-notifications.toast.position.md +11 -0
  124. package/docs/api/foundation-notifications.toast.type.md +11 -0
  125. package/docs/api/foundation-notifications.toastbuilder.build.md +19 -0
  126. package/docs/api/foundation-notifications.toastbuilder.md +23 -0
  127. package/docs/api/foundation-notifications.toastbuilder.withautoclose.md +25 -0
  128. package/docs/api/foundation-notifications.toastbuilder.withclosetimeout.md +25 -0
  129. package/docs/api/foundation-notifications.toastbuilder.withposition.md +25 -0
  130. package/docs/api/foundation-notifications.toastbuilder.withtype.md +25 -0
  131. package/docs/api/foundation-notifications.toastposition.md +13 -0
  132. package/docs/api/index.md +12 -0
  133. package/docs/api-report.md +203 -0
  134. package/license.txt +46 -0
  135. package/package.json +57 -0
@@ -0,0 +1,49 @@
1
+ /**
2
+ * BannerBuilder
3
+ * @public
4
+ */
5
+ export class BannerBuilder {
6
+ /**
7
+ * Add dismissing action to Banner
8
+ * @public
9
+ * @param dismissingAction - {@link DismissingAction}
10
+ * @returns
11
+ */
12
+ withDismissingAction(dismissingAction) {
13
+ this.dismissingAction = dismissingAction;
14
+ return this;
15
+ }
16
+ /**
17
+ * Add confirming action to Banner
18
+ * @public
19
+ * @param confirmingAction - {@link ConfirmingAction}
20
+ * @returns
21
+ */
22
+ withConfirmingAction(confirmingAction) {
23
+ if (!this.confirmingActions) {
24
+ this.confirmingActions = [];
25
+ }
26
+ this.confirmingActions.push(confirmingAction);
27
+ return this;
28
+ }
29
+ /**
30
+ * Build Banner
31
+ * @public
32
+ * @returns Banner
33
+ */
34
+ build() {
35
+ let banner = {};
36
+ if (this.dismissingAction) {
37
+ banner = Object.assign({ dismissingAction: this.dismissingAction }, banner);
38
+ }
39
+ if (this.confirmingActions) {
40
+ banner = Object.assign({ confirmingActions: this.confirmingActions }, banner);
41
+ }
42
+ return banner;
43
+ }
44
+ }
45
+ /**
46
+ * Get banner builder instance
47
+ * @public
48
+ */
49
+ export const getBannerBuilder = () => new BannerBuilder();
@@ -0,0 +1,23 @@
1
+ import { getBannerAnchor } from '../notification-util';
2
+ /**
3
+ * Shows the notificationStructure dialog
4
+ * @public
5
+ * @param notificationStructure - The NotificationStructure object
6
+ * @param tagName - The tag name to create prefix for the design system provider & notificationStructure component
7
+ * @param notificationBoundary - target listener for the notification
8
+ * @returns
9
+ * */
10
+ export const showBanner = (notificationStructure, tagName, notificationBoundary) => {
11
+ var _a;
12
+ const tagPrefix = tagName.split('-')[0];
13
+ const banner = document.createElement(`${tagPrefix}-banner`);
14
+ const container = getBannerAnchor(notificationBoundary);
15
+ if (((_a = container === null || container === void 0 ? void 0 : container.children) === null || _a === void 0 ? void 0 : _a.length) > 0) {
16
+ banner.style.position = 'absolute';
17
+ banner.style.top = '0';
18
+ banner.style.left = '0';
19
+ banner.style.width = '100%';
20
+ }
21
+ container.appendChild(banner);
22
+ banner.notification = notificationStructure;
23
+ };
@@ -0,0 +1,2 @@
1
+ export * from './banner-builder';
2
+ export * from './banner-launcher';
@@ -0,0 +1,49 @@
1
+ /**
2
+ * DialogBuilder class
3
+ * @public
4
+ */
5
+ export class DialogBuilder {
6
+ /**
7
+ * Add dismissing action to Dialog
8
+ * @public
9
+ * @param dismissingAction - {@link DismissingAction}
10
+ * @returns
11
+ */
12
+ withDismissingAction(dismissingAction) {
13
+ this.dismissingAction = dismissingAction;
14
+ return this;
15
+ }
16
+ /**
17
+ * Add confirming action to Dialog
18
+ * @public
19
+ * @param confirmingAction - {@link ConfirmingAction}
20
+ * @returns
21
+ */
22
+ withConfirmingAction(confirmingAction) {
23
+ if (!this.confirmingActions) {
24
+ this.confirmingActions = [];
25
+ }
26
+ this.confirmingActions.push(confirmingAction);
27
+ return this;
28
+ }
29
+ /**
30
+ * Build Dialog
31
+ * @public
32
+ * @returns Dialog
33
+ */
34
+ build() {
35
+ let dialog = {};
36
+ if (this.dismissingAction) {
37
+ dialog = Object.assign({ dismissingAction: this.dismissingAction }, dialog);
38
+ }
39
+ if (this.confirmingActions) {
40
+ dialog = Object.assign({ confirmingActions: this.confirmingActions }, dialog);
41
+ }
42
+ return dialog;
43
+ }
44
+ }
45
+ /**
46
+ * Returns an instance of DialogBuilder
47
+ * @public
48
+ */
49
+ export const getDialogBuilder = () => new DialogBuilder();
@@ -0,0 +1,16 @@
1
+ import { getNotificationContainer } from '../notification-util';
2
+ /**
3
+ * Shows the dialog
4
+ * @internal
5
+ * @param notification - The NotificationStructure object
6
+ * @param tagName - The tag name to create prefix for the design system provider & notification component
7
+ * @returns
8
+ * */
9
+ export const showDialog = (notification, tagName) => {
10
+ const tagPrefix = tagName.split('-')[0];
11
+ const dialog = document.createElement(`${tagPrefix}-notification-dialog`);
12
+ const container = getNotificationContainer('dialog-container', tagName);
13
+ container.appendChild(dialog);
14
+ dialog.notification = notification;
15
+ dialog.show();
16
+ };
@@ -0,0 +1,2 @@
1
+ export * from './dialog-builder';
2
+ export * from './dialog-launcher';
@@ -0,0 +1 @@
1
+ import('./index');
@@ -0,0 +1,8 @@
1
+ export * from './types';
2
+ export * from './notification-builder';
3
+ export * from './toast';
4
+ export * from './banner';
5
+ export * from './dialog';
6
+ export * from './snackbar';
7
+ export * from './notification-util';
8
+ export * from './notification-launcher';
@@ -0,0 +1,2 @@
1
+ import { createLogger } from '@genesislcap/foundation-utils';
2
+ export const logger = createLogger('foundation-notifications');
@@ -0,0 +1,133 @@
1
+ import { LogLevel } from '@genesislcap/foundation-utils';
2
+ /**
3
+ * NotificationBuilder to build NotificationStructure
4
+ * @public
5
+ */
6
+ export class NotificationBuilder {
7
+ /**
8
+ * Add title to notification
9
+ * @public
10
+ * @param title - string
11
+ * @returns
12
+ */
13
+ withTitle(title) {
14
+ this.title = title;
15
+ return this;
16
+ }
17
+ /**
18
+ * Add body details to notification
19
+ * @public
20
+ * @param body - string
21
+ * @returns
22
+ */
23
+ withBody(body) {
24
+ this.body = body;
25
+ return this;
26
+ }
27
+ /**
28
+ * Add log level to notification
29
+ * @public
30
+ * @returns
31
+ */
32
+ withLogLevel(logLevel) {
33
+ this.logLevel = logLevel;
34
+ return this;
35
+ }
36
+ /**
37
+ * Add alert to notification
38
+ * @public
39
+ * @param alert - boolean
40
+ * @returns
41
+ */
42
+ withAlert(alert) {
43
+ this.alert = alert;
44
+ return this;
45
+ }
46
+ /**
47
+ * Add toast to notification
48
+ * @public
49
+ * @param notification - {@link Toast}
50
+ * @returns
51
+ */
52
+ withToast(toast) {
53
+ this.toast = toast;
54
+ return this;
55
+ }
56
+ /**
57
+ * Add banner to notification
58
+ * @public
59
+ * @param banner - {@link Banner}
60
+ * @returns
61
+ */
62
+ withBanner(banner) {
63
+ this.banner = banner;
64
+ return this;
65
+ }
66
+ /**
67
+ * Add snackbar to notification
68
+ * @public
69
+ * @param snackbar - {@link Snackbar}
70
+ * @returns
71
+ */
72
+ withSnackbar(snackbar) {
73
+ this.snackbar = snackbar;
74
+ return this;
75
+ }
76
+ /**
77
+ * Add dialog to notification
78
+ * @public
79
+ * @param dialog - {@link Dialog}
80
+ * @returns
81
+ */
82
+ withDialog(dialog) {
83
+ this.dialog = dialog;
84
+ return this;
85
+ }
86
+ /**
87
+ * Build NotificationStructure
88
+ * @public
89
+ * @returns
90
+ */
91
+ build() {
92
+ if (!this.title) {
93
+ throw new Error('Title is required');
94
+ }
95
+ if (!this.body) {
96
+ throw new Error(`Missing required param 'body'`);
97
+ }
98
+ let notificationStructure = {
99
+ title: this.title,
100
+ body: this.body,
101
+ };
102
+ let config = {};
103
+ if (this.logLevel in LogLevel) {
104
+ notificationStructure = Object.assign({ logLevel: this.logLevel }, notificationStructure);
105
+ }
106
+ if (this.alert) {
107
+ config = Object.assign({ alert: this.alert }, config);
108
+ notificationStructure = Object.assign({ config }, notificationStructure);
109
+ }
110
+ if (this.toast) {
111
+ config = Object.assign({ notification: this.toast }, config);
112
+ notificationStructure = Object.assign({ config }, notificationStructure);
113
+ }
114
+ if (this.banner) {
115
+ config = Object.assign({ banner: this.banner }, config);
116
+ notificationStructure = Object.assign({ config }, notificationStructure);
117
+ }
118
+ if (this.snackbar) {
119
+ config = Object.assign({ snackbar: this.snackbar }, config);
120
+ notificationStructure = Object.assign({ config }, notificationStructure);
121
+ }
122
+ if (this.dialog) {
123
+ config = Object.assign({ dialog: this.dialog }, config);
124
+ notificationStructure = Object.assign({ config }, notificationStructure);
125
+ }
126
+ return notificationStructure;
127
+ }
128
+ }
129
+ /**
130
+ * Returns a new NotificationBuilder instance
131
+ * @public
132
+ */
133
+ export const getNotificationBuilder = () => new NotificationBuilder();
@@ -0,0 +1,36 @@
1
+ import { createLogger } from '@genesislcap/foundation-utils';
2
+ import { showBanner } from './banner';
3
+ import { showDialog } from './dialog';
4
+ import { getNotificationDetails, getLoglevel } from './notification-util';
5
+ import { showSnackbar } from './snackbar';
6
+ import { showToast } from './toast';
7
+ const logger = createLogger('foundation-notifications');
8
+ const notificationTypeToComponentMap = {
9
+ alert: (notificationStructure) => {
10
+ alert(getNotificationDetails(notificationStructure));
11
+ },
12
+ notification: showToast,
13
+ dialog: showDialog,
14
+ snackbar: showSnackbar,
15
+ banner: showBanner,
16
+ };
17
+ /**
18
+ * Shows the notificationStructure in the appropriate component
19
+ * @public
20
+ * @param notificationStructure - The NotificationStructure object
21
+ * @param tagName - The tag name to create prefix for the design system provider *
22
+ * @param notificationBoundary - The notificationStructure boundary element
23
+ * @returns
24
+ * */
25
+ export const showNotification = (notificationStructure, tagName, notificationBoundary) => {
26
+ logger.log({
27
+ message: getNotificationDetails(notificationStructure),
28
+ level: getLoglevel(notificationStructure),
29
+ });
30
+ const keys = Object.keys((notificationStructure === null || notificationStructure === void 0 ? void 0 : notificationStructure.config) || {});
31
+ keys.forEach((key) => {
32
+ if (notificationTypeToComponentMap[key]) {
33
+ notificationTypeToComponentMap[key](notificationStructure, tagName, notificationBoundary);
34
+ }
35
+ });
36
+ };
@@ -0,0 +1,67 @@
1
+ import { LogLevel } from '@genesislcap/foundation-utils';
2
+ /**
3
+ * Retrieves the notification details from an NotificationStructure object
4
+ * @public
5
+ * @param details - The NotificationStructure object
6
+ * @returns The title and body concatenated as a string, or default values ('Error: Something went wrong') if not present
7
+ */
8
+ export const getNotificationDetails = (details) => {
9
+ var _a, _b;
10
+ const title = (_a = details === null || details === void 0 ? void 0 : details.title) !== null && _a !== void 0 ? _a : 'Error';
11
+ const body = (_b = details === null || details === void 0 ? void 0 : details.body) !== null && _b !== void 0 ? _b : 'Something went wrong';
12
+ return `${title}: ${body}`;
13
+ };
14
+ /**
15
+ * Retrieves the log level from an NotificationStructure object
16
+ * @public
17
+ * @param details - The NotificationStructure object
18
+ * @returns The log level or the default value (LogLevel.Debug) if not present
19
+ */
20
+ export const getLoglevel = (details) => {
21
+ var _a;
22
+ return (details === null || details === void 0 ? void 0 : details.logLevel) || ((_a = details === null || details === void 0 ? void 0 : details.config) === null || _a === void 0 ? void 0 : _a.logLevel) || LogLevel.Debug;
23
+ };
24
+ /**
25
+ * Get/Create the error container in the DOM
26
+ * @public
27
+ * @param id - The id of the container
28
+ * @param tagName - The tag name to create prefix for the design system provider
29
+ * @returns
30
+ */
31
+ export const getNotificationContainer = (id, tagName) => {
32
+ const tagPrefix = tagName.split('-')[0];
33
+ let container = document.querySelector(`#${id}`);
34
+ if (!container) {
35
+ container = document.createElement('div');
36
+ container.setAttribute('id', id);
37
+ const dsProvider = document.createElement(`${tagPrefix}-design-system-provider`);
38
+ dsProvider.appendChild(container);
39
+ document.body.appendChild(dsProvider);
40
+ }
41
+ return container;
42
+ };
43
+ /**
44
+ * Get the banner anchor to attach the banner to
45
+ * @public
46
+ * @param element - The element to start searching from
47
+ * @returns
48
+ */
49
+ export const getBannerAnchor = (element) => {
50
+ var _a, _b;
51
+ while (element && !(element instanceof ShadowRoot)) {
52
+ const anchor = (_a = element === null || element === void 0 ? void 0 : element.getRootNode()) === null || _a === void 0 ? void 0 : _a.getElementById('banner-anchor');
53
+ if (anchor) {
54
+ anchor.style.position = 'relative';
55
+ return anchor;
56
+ }
57
+ element = (_b = element === null || element === void 0 ? void 0 : element.getRootNode()) === null || _b === void 0 ? void 0 : _b.host;
58
+ }
59
+ return createBannerContainer();
60
+ };
61
+ const createBannerContainer = () => {
62
+ const anchor = document.createElement('div');
63
+ anchor.setAttribute('id', 'banner-anchor');
64
+ anchor.style.position = 'relative';
65
+ document.body.insertBefore(anchor, document.body.firstChild);
66
+ return anchor;
67
+ };
@@ -0,0 +1,2 @@
1
+ export * from './snackbar-builder';
2
+ export * from './snackbar-launcher';
@@ -0,0 +1,48 @@
1
+ /**
2
+ * SnackbarBuilder to build Snackbar
3
+ * @public
4
+ */
5
+ export class SnackbarBuilder {
6
+ /**
7
+ * @public
8
+ * @param type - {@link SnackbarType}
9
+ * @returns
10
+ */
11
+ withType(type) {
12
+ this.type = type;
13
+ return this;
14
+ }
15
+ /**
16
+ * Add confirming action to snackbar
17
+ * @public
18
+ * @param confirmingAction - {@link ConfirmingAction}
19
+ * @returns
20
+ */
21
+ withConfirmingAction(confirmingAction) {
22
+ if (!this.confirmingActions) {
23
+ this.confirmingActions = [];
24
+ }
25
+ this.confirmingActions.push(confirmingAction);
26
+ return this;
27
+ }
28
+ /**
29
+ * Build snackbar
30
+ * @public
31
+ * @returns Snackbar
32
+ */
33
+ build() {
34
+ let snackbar = {};
35
+ if (this.confirmingActions) {
36
+ snackbar = Object.assign({ confirmingActions: this.confirmingActions }, snackbar);
37
+ }
38
+ if (this.type !== undefined) {
39
+ snackbar = Object.assign({ type: this.type }, snackbar);
40
+ }
41
+ return snackbar;
42
+ }
43
+ }
44
+ /**
45
+ * Get snackbar builder instance
46
+ * @public
47
+ */
48
+ export const getSnackbarBuilder = () => new SnackbarBuilder();
@@ -0,0 +1,15 @@
1
+ import { getNotificationContainer } from '../notification-util';
2
+ /**
3
+ * Shows the snackbar
4
+ * @internal
5
+ * @param notification - The NotificationStructure object
6
+ * @param tagName - The tag name to create prefix for the design system provider & notification component
7
+ * @returns
8
+ * */
9
+ export const showSnackbar = (notification, tagName) => {
10
+ const tagPrefix = tagName.split('-')[0];
11
+ const snackbar = document.createElement(`${tagPrefix}-snackbar`);
12
+ const container = getNotificationContainer('snack-container', tagName);
13
+ container.appendChild(snackbar);
14
+ snackbar.notification = notification;
15
+ };
@@ -0,0 +1,2 @@
1
+ export * from './toast-builder';
2
+ export * from './toast-launcher';
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @public
3
+ */
4
+ export class ToastBuilder {
5
+ /**
6
+ * Add position to toast
7
+ * @public
8
+ * @param position - {@link ToastPosition}
9
+ * @returns
10
+ */
11
+ withPosition(position) {
12
+ this.position = position;
13
+ return this;
14
+ }
15
+ /**
16
+ * Add auto close to notification
17
+ * @public
18
+ * @param autoClose - boolean
19
+ * @returns
20
+ */
21
+ withAutoClose(autoClose) {
22
+ this.autoClose = autoClose;
23
+ return this;
24
+ }
25
+ /**
26
+ * Add close timeout to notification
27
+ * @public
28
+ * @param closeTimeout - number
29
+ * @returns
30
+ */
31
+ withCloseTimeout(closeTimeout) {
32
+ this.closeTimeout = closeTimeout;
33
+ return this;
34
+ }
35
+ /**
36
+ * Add type to notification, if the type is anything other than 'warning' or 'success' do not add it
37
+ * @public
38
+ * @param type - {@link NotificationType}
39
+ * @returns
40
+ */
41
+ withType(type) {
42
+ this.type = type;
43
+ return this;
44
+ }
45
+ /**
46
+ * Build notification
47
+ * @returns Toast
48
+ */
49
+ build() {
50
+ let notification = {};
51
+ if (this.position) {
52
+ notification = Object.assign({ position: this.position }, notification);
53
+ }
54
+ if (this.autoClose) {
55
+ notification = Object.assign({ autoClose: this.autoClose }, notification);
56
+ }
57
+ if (this.closeTimeout) {
58
+ notification = Object.assign({ closeTimeout: this.closeTimeout }, notification);
59
+ }
60
+ if (this.type) {
61
+ notification = Object.assign({ type: this.type }, notification);
62
+ }
63
+ return notification;
64
+ }
65
+ }
66
+ /**
67
+ * Get notification builder instance
68
+ * @public
69
+ */
70
+ export const getToastBuilder = () => new ToastBuilder();
@@ -0,0 +1,54 @@
1
+ import { getNotificationContainer } from '../notification-util';
2
+ /**
3
+ * Shows the notificationStructure
4
+ * @internal
5
+ * @param notificationStructure - The NotificationStructure object
6
+ * @param tagName - The tag name to create prefix for the design system provider & notificationStructure component
7
+ * @returns
8
+ * */
9
+ export const showToast = (notificationStructure, tagName) => {
10
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
11
+ const tagPrefix = tagName.split('-')[0];
12
+ const container = getNotificationContainer('notify-container', tagName);
13
+ if (container) {
14
+ container.style.position = 'fixed';
15
+ switch ((_b = (_a = notificationStructure === null || notificationStructure === void 0 ? void 0 : notificationStructure.config) === null || _a === void 0 ? void 0 : _a.toast) === null || _b === void 0 ? void 0 : _b.position) {
16
+ case 'top-left':
17
+ container.style.top = '0';
18
+ container.style.left = '0';
19
+ break;
20
+ case 'bottom-left':
21
+ container.style.bottom = '0';
22
+ container.style.left = '0';
23
+ break;
24
+ case 'bottom-right':
25
+ container.style.bottom = '0';
26
+ container.style.right = '0';
27
+ break;
28
+ default:
29
+ container.style.top = '0';
30
+ container.style.right = '0';
31
+ }
32
+ }
33
+ const toastNotify = document.createElement(`${tagPrefix}-toast`);
34
+ const toastTitle = document.createElement('div');
35
+ toastTitle.setAttribute('slot', 'top');
36
+ toastTitle.textContent = notificationStructure.title;
37
+ const toastDetails = document.createElement('div');
38
+ toastDetails.setAttribute('slot', 'content');
39
+ toastDetails.textContent = (notificationStructure === null || notificationStructure === void 0 ? void 0 : notificationStructure.body) || '';
40
+ const toastDate = document.createElement('div');
41
+ toastDate.setAttribute('slot', 'date');
42
+ toastDate.textContent = new Date().toLocaleTimeString();
43
+ toastNotify.setAttribute('notify', ((_d = (_c = notificationStructure === null || notificationStructure === void 0 ? void 0 : notificationStructure.config) === null || _c === void 0 ? void 0 : _c.toast) === null || _d === void 0 ? void 0 : _d.type) || '');
44
+ ((_f = (_e = notificationStructure === null || notificationStructure === void 0 ? void 0 : notificationStructure.config) === null || _e === void 0 ? void 0 : _e.toast) === null || _f === void 0 ? void 0 : _f.autoClose)
45
+ ? toastNotify.setAttribute('auto-close', `${(_h = (_g = notificationStructure === null || notificationStructure === void 0 ? void 0 : notificationStructure.config) === null || _g === void 0 ? void 0 : _g.toast) === null || _h === void 0 ? void 0 : _h.autoClose}`)
46
+ : '';
47
+ ((_k = (_j = notificationStructure === null || notificationStructure === void 0 ? void 0 : notificationStructure.config) === null || _j === void 0 ? void 0 : _j.toast) === null || _k === void 0 ? void 0 : _k.closeTimeout)
48
+ ? toastNotify.setAttribute('close-timeout', `${(_m = (_l = notificationStructure === null || notificationStructure === void 0 ? void 0 : notificationStructure.config) === null || _l === void 0 ? void 0 : _l.toast) === null || _m === void 0 ? void 0 : _m.closeTimeout}`)
49
+ : '';
50
+ toastNotify.appendChild(toastTitle);
51
+ toastNotify.appendChild(toastDetails);
52
+ toastNotify.appendChild(toastDate);
53
+ container.appendChild(toastNotify);
54
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @public
3
+ * enum for different types of notification events
4
+ */
5
+ export var NotificationEvent;
6
+ (function (NotificationEvent) {
7
+ NotificationEvent["NOTIFICATION_EVENT"] = "notification-event";
8
+ })(NotificationEvent || (NotificationEvent = {}));