From 959f4583c01d11b6f77f2e37c55adbe0341dbee1 Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle <patrizio.bekerle@tugraz.at> Date: Wed, 24 Jul 2019 10:57:45 +0200 Subject: [PATCH] Create notification library to send notifications --- packages/notification/README.md | 26 +++++++------------ packages/notification/notification.js | 26 +++++++++++++++++++ .../notification/vpu-notification-demo.js | 19 +++++--------- 3 files changed, 43 insertions(+), 28 deletions(-) create mode 100644 packages/notification/notification.js diff --git a/packages/notification/README.md b/packages/notification/README.md index c13c06fa..c0990892 100644 --- a/packages/notification/README.md +++ b/packages/notification/README.md @@ -13,22 +13,16 @@ - `lang` (optional, default: `de`): set to `de` or `en` for German or English - example `<vpu-notification lang="de" client-id="my-client-id"></vpu-notification>` -## Events to dispatch - -### Sending notifications - -`vpu-notification-send` sends a notification to the web component - -```javascript -event = new CustomEvent("vpu-notification-send", { - bubbles: true, - cancelable: true, - detail: { - "summary": "Item deleted", - "body": "Item foo was deleted!", - "type": "info", - "timeout": 5, - }, +## Sending notifications + +```javascript +import notification from './notification'; + +notification.send({ + "summary": "Item deleted", + "body": "Item foo was deleted!", + "type": "info", + "timeout": 5, }); ``` diff --git a/packages/notification/notification.js b/packages/notification/notification.js new file mode 100644 index 00000000..c654e6e3 --- /dev/null +++ b/packages/notification/notification.js @@ -0,0 +1,26 @@ + +module.exports = { + /** + * Sends a notification via the event + * + * example options: + * + * { + * "summary": "Item deleted", + * "body": "Item foo was deleted!", + * "type": "info", + * "timeout": 5, + * } + * + * @param options + */ + send: (options) => { + const event = new CustomEvent("vpu-notification-send", { + bubbles: true, + cancelable: true, + detail: options, + }); + + document.dispatchEvent(event); + }, +}; diff --git a/packages/notification/vpu-notification-demo.js b/packages/notification/vpu-notification-demo.js index 693974c1..80ea7eb2 100644 --- a/packages/notification/vpu-notification-demo.js +++ b/packages/notification/vpu-notification-demo.js @@ -1,4 +1,5 @@ -import {i18n} from './i18n.js'; +import {i18n} from './i18n'; +import notification from './notification'; import {html, LitElement} from 'lit-element'; class NotificationDemo extends LitElement { @@ -46,18 +47,12 @@ class NotificationDemo extends LitElement { } send() { - const event = new CustomEvent("vpu-notification-send", { - bubbles: true, - cancelable: true, - detail: { - "summary": "Item deleted", - "body": "Item foo was deleted!", - "type": "info", - "timeout": 5, - }, + notification.send({ + "summary": "Item deleted", + "body": "Item foo was deleted!", + "type": "info", + "timeout": 5, }); - - document.dispatchEvent(event); } } -- GitLab