diff --git a/packages/common/notification.js b/packages/common/notification.js new file mode 100644 index 0000000000000000000000000000000000000000..9df57b21dc5deec91508478f4f94ce7a3230ddd0 --- /dev/null +++ b/packages/common/notification.js @@ -0,0 +1,32 @@ +/** + * Sends a notification via the event + * + * For type see: https://bulma.io/documentation/elements/notification/#colors + * + * example options: + * + * { + * "summary": "Item deleted", + * "body": "Item foo was deleted!", + * "type": "info", + * "timeout": 5, + * } + * + * @param options + */ +function send(options) { + const event = new CustomEvent("vpu-notification-send", { + bubbles: true, + cancelable: true, + detail: options, + }); + + const result = window.dispatchEvent(event); + + // true means the event was not handled + if (result) { + alert((options.summary !== undefined && options.summary !== "" ? options.summary + ": " : "") + options.body) + } +} + +export { send };