NS-Lib toasts are a quick way to set up alerts and notifications using Bootstrap toasts. Click the button below to try one out.
To set up toast notifications, first run the Toasts.Setup
function to enable toasts on your page.
NSLib.Toasts.Setup();
Next, create a toast using the Toasts.Show
function. It takes five arguments:
primary
, secondary
, success
, info
, warning
, danger
, light
, and dark
bi-
prefix). Example: exclamation-triangle
NSLib.Toasts.Show(
"secondary", /* Bootstrap color */
"bell", /* Bootstrap icon */
"Toast title text",
"Toast body text",
3000 /* Timeout */
);
By default, toasts will be aligned to the top right corner of the screen. You can change this when running the Toasts.Setup
function by passing two booleans. The first boolean will align the toasts to the top of the screen if true or the bottom of the screen if false, and the second boolean will align toasts to the right side of the screen if true or to the left side of the screen if false.
// Align top right - the default
NSLib.Toasts.Setup(true, true);
// Align top left
NSLib.Toasts.Setup(true, false);
Try it out:
You can also use toasts for a yes/no prompt.
NSLib.Toasts.ShowPrompt(
'secondary',
'bell',
'Hello world',
'This is an example prompt notification',
function() { alert('You clicked yes!'); }, /* Function to run when yes is clicked */
function() { alert('You clicked no!'); }, /* Function to run when no is clicked */
'danger', /* Color of the yes button */
'outline-dark' /* Color of the no button */
);