plugin.toast()
Allow plugins to send toasts. A toast is a small message in the corner of the page. The footer shows the name of your plugin.
Syntax
plugin.toast(text);
plugin.toast({ text, … });
- text
- What the toast says. It can contain HTML.
Options
- text:
string - The message, required
- title:
string - Title shown above the message
- footer:
string - Text shown in front of your plugin’s name in the footer
- timeout:
number - Milliseconds before the toast closes on its own
- error:
boolean - Show the toast as an error
- className:
stringorstring[]or{ toast, button } - Classes to add to the toast, or to its buttons
- buttons:
objectorobject[] - Buttons to show, each with
text(required),className,onClick(event, toast), anddismiss. Clicking a button closes the toast, setdismiss: falseor callevent.preventDefault()inonClickto keep it open. - onClose:
function(reason, toast) - Called after the toast closes.
reasonistimeout,dismissed, or what was passed toclose(). - Return Value
- Returns a
Toastobject
Toast {
exists(), // true if the toast is still showing
element, // the toast's element
setText(text), // change the message
setTitle(title), // change the title
setFooter(text), // change the text shown in front of your plugin's name
close(reason), // close the toast
}Examples
plugin.toast('Hello!');
const toast = plugin.toast({
title: 'Working',
text: 'Please wait...',
timeout: 5000,
});
toast.setText('Almost done...');
plugin.toast({
text: 'Saved. Undo?',
buttons: {
text: 'Undo',
onClick(event, toast) {
toast.close('undone');
},
},
onClose(reason) {
console.log(reason);
},
});