This API can be used to display notifications that pop-down from the top of the editor.
As these notifications interrupt the user, they should be used sparingly.
RED.notify(message, [options])
message
- the text to be displayed in the notificationoptions
- configuration options for the notificationThe function returns a notification
object that can be used to interact with
the notification.
The following properties can be provided in the options
argument. All are optional.
Option | Description |
---|---|
type |
Sets the appearance of the notification. Available values are: compact , success , warning , error . If this value is not set, the notification uses the default ‘info’ appearance. |
timeout |
How long the notification should be shown for, in milliseconds. Default: 5000 . This is ignored if the fixed property is set. |
fixed |
Do not hide the notification after a timeout. This also prevents the click-to-close default behaviour of the notification. |
modal |
If set to true , the notification should prevent interaction with any other UI element until the notification has been dismissed. |
buttons |
An array of buttons to display on the notification to allow user interaction. |
The buttons
option can be used to provide a set of buttons that should be displayed on the notification.
For example, to have a ‘cancel’ and ‘okay’ button, the following can be used (see further below for a fuller example that explains myNotification.close()
).
buttons: [
{
text: "cancel",
click: function(e) {
myNotification.close();
}
},
{
text: "okay",
class:"primary",
click: function(e) {
myNotification.close();
}
}
The class
property can be used to specify an additional CSS class for the button. If the notification has multiple buttons, there should be one with the class set to primary
to indicate the primary button for the user to click.
The RED.notify()
call returns a notification
object. This object provides the following functions:
Function | Description |
---|---|
notification.close() |
Close the notification and dispose of it. |
notification.update( message, options ) |
Replace the contents of the notification. |
RED.notify("Hello World");
RED.notify("Something has happened", { type: "warning", timeout: 10000 });
This example shows how the returned myNotification
object is then used in the button event handlers to close the notification.
let myNotification = RED.notify("This is the message to display",{
modal: true,
fixed: true,
type: 'warning',
buttons: [
{
text: "cancel",
click: function(e) {
myNotification.close();
}
},
{
text: "okay",
class:"primary",
click: function(e) {
myNotification.close();
}
}
]
});
Node-RED: Low-code programming for event-driven applications.
Copyright OpenJS Foundation and Node-RED contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of trademarks of the OpenJS Foundation, please see our Trademark Policy and Trademark List. Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.
The OpenJS Foundation | Terms of Use | Privacy Policy | OpenJS Foundation Bylaws | Trademark Policy | Trademark List | Cookie Policy