Skip to content

Notify

The Notify component provides a flexible notification system for displaying messages, alerts, and notifications to users. It supports customizable appearance, positioning, and behavior.

  • Metro UI Core
  • DOM library
// Create a simple notification
Metro.notify.create("This is a notification message");
// Create a notification with title
Metro.notify.create("This is a notification message", "Notification Title");
// Create a notification with custom options
Metro.notify.create("This is a notification message", "Notification Title", {
width: 300,
keepOpen: true,
clsNotify: "alert"
});

By default, notifications appear in the top-right corner of the screen. You can change this by adding positioning classes to the container:

// Create a notification container at the top-left
const container = $("<div>").addClass("notify-container position-left");
$("body").prepend(container);
// Use this container for notifications
Metro.notify.setup({
container: container
});
// Remove all notifications
Metro.notify.killAll();
// Remove a specific notification (usually handled automatically)
Metro.notify.kill($("#notification-id"));

The Notify component accepts the following configuration options:

ParameterTypeDefaultDescription
containerelementnullContainer element for notifications (created automatically if null)
widthnumber220Width of notification in pixels
timeoutnumber3000Time in milliseconds before notification automatically closes
durationnumber200Animation duration in milliseconds
distancestring/number"max"Animation distance (“max” or specific pixel value)
animationstring"linear"Animation easing function
clsNotifystring""Additional CSS class(es) for notification element
EventDescription
onClickTriggered when notification is clicked
onCloseTriggered when notification is closed
onShowTriggered when notification is shown
onAppendTriggered when notification is appended to container
onNotifyCreateTriggered when notification is created

The Notify component provides the following methods:

MethodParametersDescription
setup(options)options: objectConfigure notification system with options
reset()-Reset options to default values
create(message, title, options)message: string, title: string, options: objectCreate and show a notification
kill(notify, callback)notify: element, callback: functionRemove a specific notification
killAll()-Remove all notifications

When using the create() method, you can pass the following options:

OptionTypeDescription
keepOpenbooleanIf true, notification won’t auto-close
clsNotifystringAdditional CSS class(es) for this notification
widthnumberWidth for this specific notification
durationnumberAnimation duration for this notification
animationstringAnimation type for this notification
distancestring/numberAnimation distance for this notification
onClickfunctionClick handler for this notification
onClosefunctionClose handler for this notification
onShowfunctionShow handler for this notification
onAppendfunctionAppend handler for this notification

The Notify component can be styled using the following CSS variables:

VariableDefault (Light)Dark ModeDescription
--notify-container-backgroundtransparenttransparentBackground color of the notification container
--notify-border-radius4px4pxBorder radius of notifications
--notify-border-color#e8e8e8#4a4d51Border color of notifications
--notify-background#ffffff#26282eBackground color of notifications
--notify-color#191919#dbdfe7Text color of notifications
/* Custom styling for notifications */
.custom-notify {
--notify-background: #e3f2fd;
--notify-color: #0d47a1;
--notify-border-color: #2196f3;
--notify-border-radius: 8px;
}
  • .notify-container - Container for notifications
  • .position-left - Position container on the left side
  • .position-top - Position container at the top (full width)
  • .position-bottom - Position container at the bottom (full width)
  • .notify - Base class for notifications
  • .notify-title - Title element of notification
  • .notify-message - Message element of notification
  1. Keep notification messages brief and clear
  2. Use titles for important notifications to draw attention
  3. Consider using different CSS classes for different notification types (info, warning, error)
  4. Set appropriate timeout values based on message importance and length
  5. For critical notifications, use the keepOpen: true option to require user interaction
  6. Consider accessibility by ensuring notifications have sufficient contrast and readable text