|
| 1 | +# Notification |
| 2 | + |
| 3 | +## Setup |
| 4 | +Because the notifications are elements which should be displayed on top of everything and relative to the window |
| 5 | +you have to add the tag `<ws-notification></ws-notification>` to the most root container you can add. |
| 6 | +So either document body or the application root depending on your setup. This notification element is |
| 7 | +just the holder / list of notifications. |
| 8 | + |
| 9 | +## Creating notifications |
| 10 | +To create a notification you have to publish a custom event to the window containing the relevant data. |
| 11 | +The type of the event has to be `ws-notification-open` and the details has to be an object containing: |
| 12 | +- **title**: string, required |
| 13 | +- **description**: string, optional |
| 14 | +- **type**: info|error|warning|success, default: info |
| 15 | +- **lifetime**: number, milliseconds until disappearing, default: 2147483647 |
| 16 | + |
| 17 | +<button class="mod-small" id="notification1" click.delegate="notification({title: 'Do you want to stay logged in?', type: 'info', lifetime: 5000})">Show notification</button> |
| 18 | +```html |
| 19 | +<button class="mod-small" id="notification1">Show notification</button> |
| 20 | +<script type="text/javascript"> |
| 21 | + document.getElementById('notification1').addEventListener('click', event => { |
| 22 | + window.dispatchEvent(new CustomEvent('ws-notification-open', {detail: {title: 'Do you want to stay logged in?', type: 'info', lifetime: 5000}})); |
| 23 | + }); |
| 24 | +</script> |
| 25 | +``` |
| 26 | + |
| 27 | +## Options |
| 28 | +Here you can try out the different combinations of the options you can provide to the notification. |
| 29 | +<div class="row collapse"> |
| 30 | + <div class="column small-6"> |
| 31 | + <label>Title</label> |
| 32 | + <input type="text" placeholder="Title" value="Some title" ref="navTitle" /> |
| 33 | + </div> |
| 34 | + <div class="column small-6"> |
| 35 | + <label>Description</label> |
| 36 | + <input type="text" placeholder="Title" ref="navDescription" /> |
| 37 | + </div> |
| 38 | + <div class="column small-6"> |
| 39 | + <label>Type</label> |
| 40 | + <select ref="navType"> |
| 41 | + <option value="info">Info</option> |
| 42 | + <option value="success">Success</option> |
| 43 | + <option value="warning">Warning</option> |
| 44 | + <option value="error">Error</option> |
| 45 | + </select> |
| 46 | + </div> |
| 47 | + <div class="column small-6"> |
| 48 | + <label>Lifetime</label> |
| 49 | + <input type="number" placeholder="Title" value="5000" ref="navLifetime" /> |
| 50 | + </div> |
| 51 | +</div></br> |
| 52 | +<button class="mod-small" click.delegate="notification({title: navTitle.value, description: navDescription.value, type: navType.value, lifetime: navLifetime.value})">Show notification</button> |
0 commit comments