All Projects → flauc → Angular2 Notifications

flauc / Angular2 Notifications

Licence: mit
A light and easy to use notifications library for Angular.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Angular2 Notifications

Angular Notifier
A well designed, fully animated, highly customizable, and easy-to-use notification library for your Angular application.
Stars: ✭ 175 (-76.19%)
Mutual labels:  notifications, angular2
ngx-toasta
Simple and clean Toast notification library for AngularX (Angular2 and beyond)
Stars: ✭ 20 (-97.28%)
Mutual labels:  notifications, angular2
Ng Snotify
Angular 2+ Notification Center
Stars: ✭ 304 (-58.64%)
Mutual labels:  notifications, angular2
Swiftoverlays
SwiftOverlays is a Swift GUI library for displaying various popups and notifications
Stars: ✭ 621 (-15.51%)
Mutual labels:  notifications
Notify
File system event notification library on steroids.
Stars: ✭ 624 (-15.1%)
Mutual labels:  notifications
Aws Cognito Angular Quickstart
An Angular(v5)-based QuickStart single-page app utilizing Amazon Cognito, S3, and DynamoDB (Serverless architecture)
Stars: ✭ 685 (-6.8%)
Mutual labels:  angular2
Beeep
Go cross-platform library for sending desktop notifications, alerts and beeps
Stars: ✭ 716 (-2.59%)
Mutual labels:  notifications
Socket.io Push
整合了小米,华为,友盟,谷歌,苹果推送的统一解决方案
Stars: ✭ 605 (-17.69%)
Mutual labels:  notifications
Zabbix In Telegram
Zabbix Notifications with graphs in Telegram
Stars: ✭ 710 (-3.4%)
Mutual labels:  notifications
Terminal Notifier
Send User Notifications on macOS from the command-line.
Stars: ✭ 5,766 (+684.49%)
Mutual labels:  notifications
Vue Notifications
Vue.js agnostic library for non-blocking notifications
Stars: ✭ 644 (-12.38%)
Mutual labels:  notifications
Countly Sdk Android
Countly Product Analytics Android SDK
Stars: ✭ 626 (-14.83%)
Mutual labels:  notifications
Notify
Simplified notification construction and delivery for Android.
Stars: ✭ 691 (-5.99%)
Mutual labels:  notifications
Ng2 Validation
angular2 validation
Stars: ✭ 622 (-15.37%)
Mutual labels:  angular2
Opensource Socialnetwork
Open Source Social Network (OSSN) is a social networking software written in PHP. It allows you to make a social networking website and helps your members build social relationships, with people who share similar professional or personal interests. It is available in 16 international languages.
Stars: ✭ 710 (-3.4%)
Mutual labels:  notifications
Applozic Android Sdk
Android Real Time Chat & Messaging SDK
Stars: ✭ 611 (-16.87%)
Mutual labels:  notifications
Ngx Graph
Graph visualization library for angular
Stars: ✭ 704 (-4.22%)
Mutual labels:  angular2
Server
A simple server for sending and receiving messages in real-time per WebSocket. (Includes a sleek web-ui)
Stars: ✭ 6,858 (+833.06%)
Mutual labels:  notifications
Apicurio Studio
Open Source API Design
Stars: ✭ 638 (-13.2%)
Mutual labels:  angular2
Videogular2
The HTML5 video player for Angular 2
Stars: ✭ 678 (-7.76%)
Mutual labels:  angular2

Angular2-Notifications

A light and easy to use notifications library for Angular 2. It features both regular page notifications (toasts) and push notifications.

Build Status NPM Version NPM Downloads

Push Notifications have been moved to a separate library ng-push

Table of Contents

Example

Take a look at the live demo here: Live Demo

Setup

Install the library

npm install --save angular2-notifications
# Or using Yarn for a faster installation
yarn add angular2-notifications

SystemJS

Map the library in your system.config.js if you're using SystemJs.

var map = {
    'angular2-notifications': 'node_modules/angular2-notifications'
}

var packages = {
    'angular2-notifications': { main: './dist/index.js', defaultExtension: 'js' }
}

Webpack

If you're using Webpack >= 2, just include the library in your main.ts or vendor.ts file

import 'angular2-notifications';

Setup

Import the SimpleNotificationsModule in to your root AppModule (it will not work if you try to import it into a shared module)

import { SimpleNotificationsModule } from 'angular2-notifications';

@NgModule({
    imports: [
        BrowserModule,
        // Animations need to be imported in to your project to use the library
        BrowserAnimationsModule, 
        SimpleNotificationsModule.forRoot()
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }

Add the SimpleNotificationsComponent in to the component where you want to use the notifications. Or in your top level component for use in child components.

...
template: '<simple-notifications></simple-notifications>'
...

You will also need to use the NotificationsService in your component to create or remove the notifications.

...
constructor( private _service: NotificationsService ) {}
...

The create and destroy Event Emitters emit the notification that was created or destroyed you can utilise this functionality like this:

<simple-notifications [options]="options" (create)="created($event)" (destroy)="destroyed($event)"></simple-notifications>

If your app cannot find the built JS files for this package, you may need to tell your build script to scan the angular2-notifications directory. See the related issue #25. Example:

'angular2-notifications/*.+(js|js.map)',
'angular2-notifications/lib/*.+(js|js.map)'

Creating Notifications

This are the currently available access methods:

  • The access methods return the constructed notification along with the created id.
Method Description
success(title: any, content?: any, override?: any, context?: any) Creates a success notification with the provided title and content.
error(title: any, content?: any, override?: any, context?: any) Creates an error notification with the provided title and content.
alert(title: any, content?: any, override?: any, context?: any) Creates an alert notification with the provided title and content.
warn(title: any, content?: any, override?: any, context?: any) Creates a warn notification with the provided title and content.
info(title: any, content?: any, override?: any, context?: any) Creates an info notification with the provided title and content.
bare(title: any, content?: any, override?: any, context?: any) Creates a bare notification with the provided title and content. This notification type is best used when adding custom html.
create(title: any, content: any = '', type: string = 'success', override?: any, context?: any) Use this method to create any notification type ['success', 'error', 'alert', 'info', 'bare'].
html(html: any, type: string = 'success', override?: any, icon: string = 'bare', context?: any) Use this method to create a notification with custom html. By specifying an icon (success, error, alert, info or warn) you can use the default icons in addition to your custom html. If you do not explicitly pass an icon param no icon will be shown by default.
remove(id?: string) Removes the notification that has the provided id or removes all currently open notifications if no id was provided.

The title, content and html arguments can be a string, html string or TemplateRef. Now it's also possible to pass the datas (context) to the TemplateRef by using the optional context argument.

Example using TemplateRef

To use a TemplateRef in the title or content you need to create it in a component template:

<ng-template #example let-title="title">
    <p>{{title}}</p>
</ng-template>

Then you need to somehow get it to the component:

  title: string = 'Winter is coming';
  @ViewChild('example') example: TemplateRef<any>;

  open() {
    let context: any = {title: this.title};
    this._service.html(this.example, null, null, null, context);
  }

You could also pass the template through the open() method:

    open(temp: TemplateRef<any>) {
        this._service.html(temp, null, null, null, context);
    }

Subscribing to clicks

If you are interested in the clicks that happen on a notification you have the possibility to subscribe to a EventEmitter. The methods (success, error, alert, warn, info, bare, create and html) from the NotificationsService return an Object of type Notification.

const toast = this.notificationsService.success('Item created!', 'Click to undo...', {
      timeOut: 3000,
      showProgressBar: true,
      pauseOnHover: true,
      clickToClose: true
    });

The returned object has a click property with an EventEmitter on it which you can subscribe to. Your callback then gets notified with the click event at each click that happens on your Notification.

toast.click.subscribe((event) => {
    doSomething(event)
});

If you have configured the notification to close when the icon is clicked, an EventEmitter exists to listen for those clicks as well.

const toast = this.notificationsService.success('Item created!', 'Click to undo...', {
      timeOut: 3000,
      showProgressBar: true,
      pauseOnHover: true,
      clickToClose: false,
      clickIconToClose: true
    });

With the corresponding clickIcon property as above.

toast.clickIcon.subscribe((event) => {
    doSomething(event)
});

Options

Global options can be added in two ways. They can be passed through the forRoot() method on the module.

SimpleNotificationsModule.forRoot({
    ...options
})

You can also pass them in to the root component.

<simple-notifications [options]="options"></simple-notifications>

This are the current options that can be set globally:

Option Type Default Description
position ["top" or "bottom" or "middle", "right" or "left" or "center"] ["bottom", "right"] Set the position on the screen where the notifications should display. Pass an array with two values example: ["top", "left"].
timeOut int 0 Determine how long a notification should wait before closing. If set to 0 a notification won't close it self.
showProgressBar boolean true Determine if a progress bar should be shown or not.
pauseOnHover boolean true Determines if the timeOut should be paused when the notification is hovered.
lastOnBottom boolean true Determines if new notifications should appear at the bottom or top of the list.
clickToClose boolean true Determines if notifications should close on click.
clickIconToClose boolean false Determines if notifications should close when user clicks the icon.
maxLength int 0 Set the maximum allowed length of the content string. If set to 0 or not defined there is no maximum length.
maxStack int 8 Set the maximum number of notifications that can be on the screen at once.
preventDuplicates boolean false If true prevents duplicates of open notifications.
preventLastDuplicates boolean or string false If set to "all" prevents duplicates of the latest notification shown ( even if it isn't on screen any more ). If set to "visible" only prevents duplicates of the last created notification if the notification is currently visible.
theClass string null A class that should be attached to the notification. (It doesn't exactly get attached to the selector but to the first div of the template.)
rtl boolean false Adds the class .rtl-mode to the notification aligning the icon to the left and adding direction: rtl
animate "fade" or "fromTop" or "fromRight" or "fromBottom" or "fromLeft" or "scale" or "rotate" or null "fromRight" Choose the type of animation or set the value to null not to display animations.
icons Icons DefaultIcons Overrides the default icons

Icons

Option Type Default Description
alert string Clock html string for alert icon
error string Exclamation Point html string for alert icon
info string Info html string for alert icon
warn string Warning html string for warning icon
success string Check html string for alert icon

Here is an example of passing the options to the component. You only pass the options you want changed. Options passed to the component are global. They apply to all of the notifications the get created.

...
template: '<simple-notifications [options]="options"></simple-notifications>'
...
public options = {
    position: ["bottom", "left"],
    timeOut: 5000,
    lastOnBottom: true
    ...
}

If you want a specific notification to have different options you can override them when calling any of the access methods by passing them to the override object. The following options can be overridden:

  • id
  • animate
  • timeOut
  • showProgressBar
  • pauseOnHover
  • clickToClose
  • clickIconToClose
  • maxLength
  • theClass
  • icon

This is an example of overriding global options:

this._notificationsService.success(
    'Some Title',
    'Some Content',
    {
        timeOut: 5000,
        showProgressBar: true,
        pauseOnHover: false,
        clickToClose: false,
        maxLength: 10
    }
)

Development

To generate all *.js, *.d.ts and *.metadata.json files:

$ npm run build

To lint all *.ts files:

$ npm run lint

License

MIT © Filip Lauc

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].