Users who have used the block copy button are no stranger to the Snackbar, which informs the user of the results of the application’s execution. This article will give an example of how to use Snackbar to meet the user’s need for custom interaction.


show(body: String, duration: number = 2000)body: the body of the message, duration: the duration of the message, in milliseconds.


Thanks to assets/main/js/custom.ts, we can customize the JavaScript, here we export the whole Snackbar as a global variable:

1import Snackbar from 'js/snackbar';
3// Show a message via JavaScript.'a message with 3s duration from pure JavaScript', 3000)
6// Export the Snackbar as a global variable, so that you can send a message from a HTML.
7// Such as: <button onclick="'message from a button')">Snackbar</button>.
8const _global = (window || global ) as any
9_global.Snackbar = Snackbar


Then we can call it up in HTML or JavaScript:

1<button onclick="'message from a button')">Snackbar</button>

See Hooks for how to inject custom HTML.