You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
Plaintext
48 lines
1.2 KiB
Plaintext
notification-box
|
|
notification(each="{notification in notifications}", notification="{notification}")
|
|
|
|
script.
|
|
const defaultValue = require("default-value");
|
|
|
|
Object.assign(this, {
|
|
notifications: [{
|
|
title: "Foo bar!",
|
|
//message: "Bar bar baz foo. Bar.",
|
|
type: "info",
|
|
icon: "info-circle"
|
|
}, {
|
|
title: "Whoopteedoo",
|
|
//message: "Boop boop woop whoop toop boop!",
|
|
type: "error",
|
|
icon: "exclamation-circle"
|
|
}],
|
|
add: function addNotification(title, options = {}) {
|
|
let notificationObject = {
|
|
title: title,
|
|
message: options.message,
|
|
type: defaultValue(options.type, "info"),
|
|
icon: options.icon,
|
|
options: options
|
|
};
|
|
|
|
this.notifications.push(notificationObject);
|
|
|
|
if (options.timeout != null) {
|
|
setTimeout(() => {
|
|
this.remove(notificationObject);
|
|
}, options.timeout);
|
|
}
|
|
|
|
this.update();
|
|
},
|
|
remove: function removeNotification(notificationObject) {
|
|
let notificationIndex = this.notifications.indexOf(notificationObject);
|
|
|
|
// TODO: Fade/collapse animation?
|
|
if (notificationIndex !== -1) {
|
|
this.notifications.splice(notificationIndex, 1);
|
|
this.update();
|
|
}
|
|
}
|
|
})
|