Skip to content

Commit 0698da5

Browse files
committed
Closing toasts can now trigger a function
Pass "onClose" to be called when a toast closes
1 parent 73ef0f5 commit 0698da5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

simpletoast.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
(() => {
55
if (window !== window.top) return;
6-
const version = buildVersion(1, 6, 1);
6+
const version = buildVersion(1, 7, 0);
77
if (window.SimpleToast) {
88
if (SimpleToast.version) {
99
if (SimpleToast.version >= version.number) return;
@@ -125,7 +125,7 @@
125125
exists: () => false,
126126
close: () => {},
127127
};
128-
function Toast({title, text, className, css = {}, buttons, timeout}) {
128+
function Toast({title, text, className, css = {}, buttons, timeout, onClose}) {
129129
if (typeof arguments[0] === 'string') {
130130
text = arguments[0];
131131
}
@@ -157,8 +157,12 @@
157157
},
158158
exists: () => toasts.has(id),
159159
close: () => {
160+
if (!toast.exists()) return;
160161
root.removeChild(el);
161162
toasts.delete(id);
163+
if (typeof onClose === 'function') {
164+
onClose(toast);
165+
}
162166
},
163167
};
164168
if (timeout) {

0 commit comments

Comments
 (0)