Popup Notification / Toast
Overview
Notifications are used to inform the user of an event occurring or a special status.
Notifications come in four different types:
- Success: Indicates a successful or positive action.
- Information: Indicates a neutral informative change or action.
- Warning: Indicates a warning that might need attention. Warnings typically do not halt forward progress with the current action.
- Error: Indicates an error or potentially negative action. Errors often halt forward progress with the current action.
Notifications display in one of 3 formats: inline notifications, popup notifications and banner notifications.
This document describes popup notifications.
Popup notifications display in a small popup window in a corner of the screen, then fade away. They do not take up any real estate in the screen, briefly displaying above the screen in a popup.
Popup notifications can be used if the message is less important for the user to see.
You can optionally take action if the user clicks the popup notification.
![Popup notification on desktop](./PopupNotificationDesktop.png?v=2)
![Popup notification on mobile](./PopupNotificationMobile.png?v=2)
Development
Web component development
Component reference
rui-popup-notification
Notification message that displays in a popup
Name | Type | Default | Description |
---|---|---|---|
type | string | 'information' | Specifies the type of popup notification styling to display. One of “information”, “success”, “error”, or “warning”. |
text | string | '' | The text to display in the popup notification. |
showNotification | boolean | false | This is a boolean trigger property. Bind this property to a backing boolean value in your controller, then set the backing value to true whenever you want to display the popup notification. |
rui-popup-notification-show-notification-change | event | Event fired when the showNotification property value resets within the component. You must reset the backing boolean value in your controller to which the showNotification property is bound when this event fires. | |
autoDismiss | boolean | true | By default, popup notifications automatically dismiss themselves after displaying for a few seconds. Bind this property to a value of false if you want the popup notification to stay displayed until the user manually clicks it. |
rui-click | event | Event fired when the user clicks the popup notification. The popup notification closes when the user clicks it. | |
closeButtonText | string | '' | If you want to display a special button within the popup notification, use this property to specify the text for this button. The rui-close-button-click event fires when the user presses this close button, as opposed to the rui-click event that fires when the user clicks anywhere else in the popup notification. This can be useful if you want to provide the user with an extra option, in addition to the ability to clicking the notification to close it. For example, you might want to include an “UNDO” button within the popup notification. If the user presses the “UNDO” button, the rui-close-button-click event fires, at which point your app could undo the previous action. If the user clicks anywhere outside the “UNDO” button, the rui-click event fires, at which point your app would not undo the previous action. |
rui-close-button-click | event | Event fired when the user clicks the close button within the popup notification. |
Implementation
Use rui-popup-notification
to display a popup notification.
- Specify the notification text with the
text
property. - Specify the type of notification to display with the
type
property. - Bind the
showNotification
property to a boolean value in your TypeScript, then set the backing value to true whenever you want to display the popup notification. - Optionally bind
autoDismiss
to false to require the user to click to dismiss the notification. - Optionally handle the
rui-click
event if you want to perform an action when the user clicks the notification. - Optionally define a separate button within the popup notification by specifying text for the button using the
closeButtonText
property and handling therui-close-button-click
event.
Begin by importing the rui-notifications
module into your application.
We start by defining a showSuccessPopupNotification
boolean property in our TypeScript, initializing that to a value of false. This property will control when the popup displays.
Next we add the rui-popup-notification
to the HTML with a type of success and an appropriate message to display. We bind the showNotification
property to the backing showSuccessPopupNotification
boolean property in the TypeScript. We handle the rui-popup-notification-show-notification-change
event by resetting the showSuccessPopupNotification
backing value.
In this example, we use a button to trigger the display of the popup notification. This button’s click event handler simply sets the showSuccessPopupNotification boolean property to a value of true when pressed. This displays the popup notification.
We defined popupNotificationClicked()
as the event handler for the popup notification’s jhaNotificationClick
event. In this example we’re just logging the console message whenever the user clicks the popup notification.
Angular wrapper development
Wrapper reference
jha-popup-notification
Notification message that displays in a popup
Name | Type | Default | Description |
---|---|---|---|
jhaType | string | 'information' | Specifies the type of popup notification styling to display. One of “Information”, “Success”, “Error”, or “Warning”. The default is “Information”. |
jhaText | string | '' | The text to display in the popup notification. |
jhaShowNotification | boolean | false | This is a boolean trigger property. Bind this property to a backing boolean value in your controller, then set the backing value to true whenever you want to display the popup notification. |
jhaAutoDismiss | boolean | true | By default, popup notifications automatically dismiss themselves after displaying for a few seconds. Bind this property to a value of false if you want the popup notification to stay displayed until the user manually clicks it. |
jhaNotificationClick | event | Event fired when the user clicks the popup notification. The popup notification closes when the user clicks it. |
Implementation
Use jha-popup-notification
to display a popup notification.
- Specify the notification text with the
jhaText
property. - Specify the type of notification to display with the
jhaType
property. - Bind the
jhaShowNotification
property to a boolean value in your TypeScript, then set the backing value to true whenever you want to display the popup notification. - Optionally bind
jhaAutoDismiss
to false to require the user to click to dismiss the notification. - Optionally handle the
jhaNotificationClick
event if you want to perform an action when the user clicks the notification.
Include noty in package.json, where x.y.z is the currently supported version number for this framework specified here. Use npm install
to install this framework.
Once the package has been installed, add it to your scripts bundle in the angular.json file.
Begin by importing the JhaNotificationsModule
module into your application.
We start by defining a showSuccessPopupNotification
boolean property in our TypeScript, initializing that to a value of false. This property will control when the popup displays.
Next we add the jha-popup-notification
to the HTML with a type of success and an appropriate message to display. We bind the showNotification
property to the backing showSuccessPopupNotification
boolean property in the TypeScript. We handle the jha-popup-notification-show-notification-change
event by resetting the showSuccessPopupNotification
backing value.
In this example, we use a button to trigger the display of the popup notification. This button’s click event handler simply sets the showSuccessPopupNotification boolean property to a value of true when pressed. This displays the popup notification.
We defined popupNotificationClicked()
as the event handler for the popup notification’s jhaNotificationClick
event. In this example we’re just logging the console message whenever the user clicks the popup notification.
Popup Notification Using a Service
In most scenarios you’ll use the jha-popup-notification element described above. But in some cases it may make more sense to display popup notifications programmatically without using a visual element. For these cases, you can use the JhaNotificationService
service.
To do this, first include the JhaNotificationService
service.
Call jhaNotificationService.DisplayPopupNotification(notificationText, notificationType)
to display a popup notification.
notificationText
is the string message to display.notificationType
is one of Information, Success, Warning, or Error, all values in the JhaNotificationTypes enum.
Call jhaNotificationService.DisplayPopupNotificationClick(notificationText, notificationType, clickCallback, notificationAutoDismiss)
to display a popup notification and do something if the user clicks the notification.
notificationText
is the string message to display.notificationType
is one of Information, Success, Warning, or Error, all values in the JhaNotificationTypes enum.clickCallback
is JavaScript to execute when the user clicks the notification.notificationAutoDismiss
(optional) allows you to require the user to click the notification to dismiss it, when set to false. The popup notification hides when the user clicks it.
Design
Figma design
Dev Component | Design Component Name |
---|---|
Popup notification | RUI / Notifications / Popup Available values for the Type property:
|
Popup notifications (a.k.a. “toast” notifications) display at the bottom-right of the screen for a few seconds, then disappear.
Do not change the size of a popup notification as these are fixed in the dev components.
Adobe XD design
- Sample App - Notifications
Dev Component | Design Component Name |
---|---|
Popup notification - Success | JHA / Notifications / Popup / Success |
Popup notification - Information | JHA / Notifications / Popup / Information |
Popup notification - Warning | JHA / Notifications / Popup / Warning |
Popup notification - Error | JHA / Notifications / Popup / Error |
Popup notifications (a.k.a. “toast” notifications) display at the bottom-right of the screen for a few seconds, then disappear.
Do not change the size of a popup notification as these are fixed in the dev components.