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

@ -19,6 +19,7 @@
- client
- file browser now remembers the last displayed directory
- allow dismissing notifications by clicking on them
## 1.26.2

View file

@ -42,7 +42,7 @@ It is the main component, it contains all the widgets and takes all the availabl
## 4. Notifications
Notifications appear in the lower right corner, they are usually used to convey server status information.
Notifications appear in the lower right corner, they are usually used to convey server status information and can be dismissed with a single click.
## 5. Modals

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'})