Skip to content

Toast

The Toast component creates non-intrusive notification messages that appear temporarily on the screen before automatically disappearing.

None

<!-- No HTML markup required for toast -->
// Basic usage
Metro.toast.create("Your message here");
// With options
Metro.toast.create("Task completed successfully", {
timeout: 5000,
position: "top"
});
// With callback
Metro.toast.create("Operation completed", function(){
console.log("Toast was closed");
});
// Using the shorthand method
Metro.createToast("Hello World!");
// With custom styling
Metro.toast.create("Custom styled toast", {
clsToast: "alert"
});
ParameterTypeDefaultDescription
callbackFunctionMetro.noopFunction called after toast is closed
timeoutNumber3000Time in milliseconds before toast auto-closes
distanceNumber20Distance from the edge of the screen in pixels
positionString"bottom"Position of the toast: “bottom”, “top”, or “center”
clsToastString""Additional CSS class(es) for toast element
  • Metro.toast.create(message, options) - Creates and displays a toast notification.
  • Metro.createToast(message, options) - Alias for Metro.toast.create().
  • Metro.toast.remove(toast, callback) - Manually remove a toast element (generally used internally).
// Create a toast with options
Metro.toast.create("Hello World!", {
timeout: 3000,
position: "center",
clsToast: "primary"
});
// Create a toast with callback function
Metro.toast.create("Hello World!", function(){
console.log("Toast closed");
});
// Manually remove a toast
const toastElement = $(".toast");
Metro.toast.remove(toastElement, function(){
console.log("Toast manually removed");
});

You can globally configure default toast options using the Metro.toastSetup method:

Metro.toastSetup({
position: "top",
timeout: 10000,
distance: 50,
clsToast: "info-toast"
});
VariableDefault (Light)Dark ModeDescription
--toast-background#323232#2b2d30Toast background color
--toast-color#ffffff#ffffffToast text color
--toast-border-radius6px6pxToast border radius
--toast-closer-backgroundinheritinheritClose button background
--toast-closer-colorinheritinheritClose button color
--toast-closer-background-hovervar(--color-alert)var(--color-alert)Close button background on hover
--toast-closer-color-hovervar(--color-light)var(--color-light)Close button text color on hover
:root {
--toast-background: rgba(0, 0, 0, 0.8);
--toast-color: #ffffff;
--toast-border-radius: 10px;
}
  • .toast - The main toast container
  • .show-top - Positions the toast at the top of the screen
  • .show-center - Positions the toast in the center of the screen
// Bottom (default)
Metro.toast.create("Toast at the bottom", {
position: "bottom"
});
// Top
Metro.toast.create("Toast at the top", {
position: "top"
});
// Center
Metro.toast.create("Toast in the center", {
position: "center"
});

You can add custom styles to your toast notifications using the clsToast option:

Metro.toast.create("Custom styled toast", {
clsToast: "my-custom-toast bg-red fg-white"
});

Make sure to define the corresponding CSS classes in your stylesheet.