open-nomad/ui/app/services/notifications.js
Phil Renaud 93574ce085
[ui, helios] Toast Component (#16099)
* Template and styles

* @type to @color on flash messages

* Notifications service as wrapper

* Test cases updated for new notifs
2023-03-02 13:52:16 -05:00

46 lines
1.2 KiB
JavaScript

// @ts-check
import { default as FlashService } from 'ember-cli-flash/services/flash-messages';
/**
* @typedef {Object} NotificationObject
* @property {string} title
* @property {string} [message]
* @property {string} [type]
* @property {string} [color = 'neutral']
* @property {boolean} [sticky = true]
* @property {boolean} [destroyOnClick = false]
* @property {number} [timeout = 5000]
*/
/**
* @class NotificationsService
* @extends FlashService
* A wrapper service around Ember Flash Messages, for adding notifications to the UI
*/
export default class NotificationsService extends FlashService {
/**
* @param {NotificationObject} notificationObject
* @returns {FlashService}
*/
add(notificationObject) {
// Set some defaults
if (!('type' in notificationObject)) {
notificationObject.type = notificationObject.color || 'neutral';
}
if (!('sticky' in notificationObject)) {
notificationObject.sticky = true;
}
if (!('destroyOnClick' in notificationObject)) {
notificationObject.destroyOnClick = false;
}
if (!('timeout' in notificationObject)) {
notificationObject.timeout = 5000;
}
return super.add(notificationObject);
}
}