diff --git a/packages/notification/README.md b/packages/notification/README.md index c13c06fa5bd3b18808dac7677dbb30ccca59fe3b..c09908922b89a9a6303b6a698fe89a6bf5177775 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 0000000000000000000000000000000000000000..c654e6e39c3f937cd8d0d154aecf8d279f875b02 --- /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 693974c1ad22554d12e076d0fad8726b9cf12ca2..80ea7eb2385abf6413c3f34edb1e007ff71540c5 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); } }