ui: allow dismissing notifications with a click

This commit is contained in:
jean-emmanuel 2024-07-26 12:14:36 +02:00
parent 31700de021
commit 1510ebb80d
3 changed files with 15 additions and 6 deletions

View file

@ -1,5 +1,6 @@
var html = require('nanohtml'),
morph = require('nanomorph')
morph = require('nanomorph'),
UiWidget = require('./ui-widget')
var DEFAULT_DURATION = 3500
@ -53,15 +54,22 @@ class Toast {
}
class Notifications {
class Notifications extends UiWidget {
constructor() {
constructor(options) {
super(options)
this.container = DOM.get('#notifications')[0]
this.toasts = []
this.loop = null
this.container.addEventListener('fast-click', (e)=>{
for (var toast of this.toasts) {
if (toast.html.contains(e.target)) this.remove(toast)
}
})
}
add(data) {
@ -118,4 +126,4 @@ class Notifications {
}
module.exports = new Notifications()
module.exports = new Notifications({selector: '#notifications'})