An Ember CLI addon that adds Atom inspired notification messages to your app.
Check out the demo.
ember install ember-cli-notifications
From within your controller or route.
actions: {
saveOptions() {
this.notifications.addNotification({
message: 'Saved successfully!',
type: 'success'
});
}
}
actions: {
saveOptions() {
this.get('model').save()
.then(() => {
this.notifications.addNotification({
message: 'Successfully saved your settings',
type: 'success',
autoClear: true
});
}),
.catch((err) => {
this.notifications.addNotification({
message: 'Something went wrong'
type: 'error'
});
});
}
}
actions: {
saveOptions() {
this.get('model').save()
.then(() => {
this.notifications.clearAll();
this.notifications.addNotification({
message: 'Successfully saved your settings',
type: 'success'
});
})
}
}
This code only needs to be called in one place such as your application route.
this.notifications.setDefaultClearNotification(1000);
Include this snippet in your Handlebars template to display the notifications.
Font Awesome is required as part of the addon to display the message type icons on the notifications.
If Font Awesome is not already included in the consuming application, add the following to your applications config/environment.js
file as a property of the ENV
object.
var ENV = {
'ember-cli-notifications': {
includeFontAwesome: true
}
}
Alternatively, you can use Glyphicons that are packaged with Bootstrap. Glyphicons are not added to your application via this addon.
var ENV = {
'ember-cli-notifications': {
icons: 'bootstrap'
}
}
The string that is displayed within the notification. This is the only required option.
this.notifications.addNotification({
message: 'Successfully saved your settings'
});
Define the type of notification that should be presented. This sets the CSS of the notification, as well as the Font Awesome icon.
Default value is info
error
info
success
warning
this.notifications.addNotification({
message: 'Successfully saved your settings',
type: 'success'
});
Boolean value that defines whether the notification message dismisses automatically, or whether it needs to be dismissed manually by the user.
If true, inherits the default clearDuration
value unless specified.
Default value is false
false
true
this.notifications.addNotification({
message: 'Successfully saved your settings',
type: 'success',
autoClear: true
});
The time in milliseconds that the notification will automatically dismiss after, if autoClear
is true
.
Default value is 3200
this.notifications.addNotification({
message: 'Successfully saved your settings',
type: 'success',
autoClear: true,
clearDuration: 1200
});