All Projects → emonney → ngx-toasta

emonney / ngx-toasta

Licence: MIT License
Simple and clean Toast notification library for AngularX (Angular2 and beyond)

Programming Languages

typescript
32286 projects
HTML
75241 projects
javascript
184084 projects - #8 most used programming language
SCSS
7915 projects

Projects that are alternatives of or similar to ngx-toasta

Angular Notifier
A well designed, fully animated, highly customizable, and easy-to-use notification library for your Angular application.
Stars: ✭ 175 (+775%)
Mutual labels:  notifications, angular2, toast
Ng Snotify
Angular 2+ Notification Center
Stars: ✭ 304 (+1420%)
Mutual labels:  notifications, angular2, toast
Notie
🔔 a clean and simple notification, input, and selection suite for javascript, with no dependencies
Stars: ✭ 6,170 (+30750%)
Mutual labels:  notifications, growl, toast
Bitprophet
Node crypto trading platform for Binance exchange.
Stars: ✭ 166 (+730%)
Mutual labels:  notifications, alerts
Notyf
👻 A minimalistic, responsive, vanilla JavaScript library to show toast notifications.
Stars: ✭ 2,093 (+10365%)
Mutual labels:  notifications, toast
Notistack
Highly customizable notification snackbars (toasts) that can be stacked on top of each other
Stars: ✭ 2,562 (+12710%)
Mutual labels:  notifications, toast
Jquery Toast Plugin
Highly customizable jquery plugin to show toast messages
Stars: ✭ 1,237 (+6085%)
Mutual labels:  notifications, toast
Notiflix
Notiflix is a JavaScript library for client-side non-blocking notifications, popup boxes, loading indicators, and more that makes your web projects much better.
Stars: ✭ 172 (+760%)
Mutual labels:  notifications, toast
Ember Cli Notifications
⚛ Atom inspired notification messages for ember-cli
Stars: ✭ 168 (+740%)
Mutual labels:  notifications, alerts
React Notify Toast
Toast notifications for React.js
Stars: ✭ 176 (+780%)
Mutual labels:  notifications, toast
Toasted Notes
simple, flexible toast notifications for react
Stars: ✭ 241 (+1105%)
Mutual labels:  notifications, toast
growl
🐯 Growl Notifications with PHP
Stars: ✭ 14 (-30%)
Mutual labels:  notifications, growl
Svelte Notifications
Svelte toast notifications component that can be used in any JS application
Stars: ✭ 146 (+630%)
Mutual labels:  notifications, toast
React Toast Notifications
🍞 A toast notification system for react
Stars: ✭ 2,103 (+10415%)
Mutual labels:  notifications, toast
Laravel Messenger
Notifying your users doesn't have to be a lot of work.
Stars: ✭ 135 (+575%)
Mutual labels:  notifications, alerts
Overlay support
a flutter toast and notification library
Stars: ✭ 232 (+1060%)
Mutual labels:  notifications, toast
vue-dk-toast
Lightweight toast-notification plugin for Vue 3 🍞
Stars: ✭ 23 (+15%)
Mutual labels:  notifications, toast
SteamAchievementNotifier
Steam Achievement Notifier is an Electron application that shows a customisable notification when you unlock any Steam Achievement! It uses the Steam Web API to track achievement stats in real time, and displays an achievement summary within the notification.
Stars: ✭ 77 (+285%)
Mutual labels:  notifications, toast
Burnttoast
Module for creating and displaying Toast Notifications on Microsoft Windows 10.
Stars: ✭ 796 (+3880%)
Mutual labels:  notifications, toast
Reapop
📮 A simple and customizable React notifications system
Stars: ✭ 1,155 (+5675%)
Mutual labels:  notifications, toast

ngx-toasta npm version npm monthly downloads

An angularX toast component that shows growl-style alerts and messages for your application. This is a port of ng2-toasty with the latest package versions and additional enhancements.

Follow me Twitter Follow to be notified about new releases.

Installation

npm install ngx-toasta

Demo

Online demo available here

Usage

If you use SystemJS to load your files, you might have to update your config:

System.config({
    map: {
        'ngx-toasta': 'node_modules/ngx-toasta/bundles/index.umd.js'
    }
});

1. Update the markup

  • Import style into your web page. Choose one of the following files;
    • style-default.css - Contains DEFAULT theme
    • style-bootstrap.css - Contains Bootstrap 3 theme
    • style-material.css - Contains Material Design theme
  • Assign the selected theme name [default, bootstrap, material] to the theme property of the instance of ToastaConfig.
  • Add <ngx-toasta></ngx-toasta> tag in template of your application component.

2. Import the ToastaModule

Import ToastaModule.forRoot() in the NgModule of your application. The forRoot method is a convention for modules that provide a singleton service.

import {BrowserModule} from "@angular/platform-browser";
import {NgModule} from '@angular/core';
import {ToastaModule} from 'ngx-toasta';

@NgModule({
    imports: [
        BrowserModule,
        ToastaModule.forRoot()
    ],
    bootstrap: [AppComponent]
})
export class AppModule {
}

If you have multiple NgModules and you use one as a shared NgModule (that you import in all of your other NgModules), don't forget that you can use it to export the ToastaModule that you imported in order to avoid having to import it multiple times.

@NgModule({
    imports: [
        BrowserModule,
        ToastaModule.forRoot()
    ],
    exports: [BrowserModule, ToastaModule],
})
export class SharedModule {
}

3. Use the ToastaService for your application

  • Import ToastaService from ngx-toasta in your application code:
import {Component} from '@angular/core';
import {ToastaService, ToastaConfig, ToastOptions, ToastData} from 'ngx-toasta';

@Component({
    selector: 'app',
    template: `
        <div>Hello world</div>
        <button (click)="addToast()">Add Toast</button>
        <ngx-toasta></ngx-toasta>
    `
})
export class AppComponent {
    
    constructor(private toastaService:ToastaService, private toastaConfig: ToastaConfig) { 
        // Assign the selected theme name to the `theme` property of the instance of ToastaConfig. 
        // Possible values: default, bootstrap, material
        this.toastaConfig.theme = 'material';
    }
    
    addToast() {
        // Just add default Toast with title only
        this.toastaService.default('Hi there');
        // Or create the instance of ToastOptions
        var toastOptions:ToastOptions = {
            title: "My title",
            msg: "The message",
            showClose: true,
            timeout: 5000,
            theme: 'default',
            onAdd: (toast:ToastData) => {
                console.log('Toast ' + toast.id + ' has been added!');
            },
            onRemove: function(toast:ToastData) {
                console.log('Toast ' + toast.id + ' has been removed!');
            }
        };
        // Add see all possible types in one shot
        this.toastaService.info(toastOptions);
        this.toastaService.success(toastOptions);
        this.toastaService.wait(toastOptions);
        this.toastaService.error(toastOptions);
        this.toastaService.warning(toastOptions);
    }
}

4. How to dynamically update title and message of a toast

Here is an example of how to dynamically update message and title of individual toast:

import {Component} from '@angular/core';
import {ToastaService, ToastaConfig, ToastaComponent, ToastOptions, ToastData} from 'ngx-toasta';
import {Subject, Observable, Subscription} from 'rxjs/Rx';

@Component({
    selector: 'app',
    template: `
        <div>Hello world</div>
        <button (click)="addToast()">Add Toast</button>
        <ngx-toasta></ngx-toasta>
    `
})
export class AppComponent {
    
    getTitle(num: number): string {
        return 'Countdown: ' + num;
    }

    getMessage(num: number): string {
        return 'Seconds left: ' + num;
    }
    
    constructor(private toastaService:ToastaService) { }
    
    addToast() {
        let interval = 1000;
        let timeout = 5000;
        let seconds = timeout / 1000;
        let subscription: Subscription;
        
        let toastOptions: ToastOptions = {
            title: this.getTitle(seconds),
            msg: this.getMessage(seconds),
            showClose: true,
            timeout: timeout,
            onAdd: (toast: ToastData) => {
                console.log('Toast ' + toast.id + ' has been added!');
                // Run the timer with 1 second iterval
                let observable = Observable.interval(interval).take(seconds);
                // Start listen seconds beat
                subscription = observable.subscribe((count: number) => {
                    // Update title of toast
                    toast.title = this.getTitle(seconds - count - 1);
                    // Update message of toast
                    toast.msg = this.getMessage(seconds - count - 1);
                });

            },
            onRemove: function(toast: ToastData) {
                console.log('Toast ' + toast.id + ' has been removed!');
                // Stop listenning
                subscription.unsubscribe();
            }
        };

        switch (this.options.type) {
            case 'default': this.toastaService.default(toastOptions); break;
            case 'info': this.toastaService.info(toastOptions); break;
            case 'success': this.toastaService.success(toastOptions); break;
            case 'wait': this.toastaService.wait(toastOptions); break;
            case 'error': this.toastaService.error(toastOptions); break;
            case 'warning': this.toastaService.warning(toastOptions); break;
        }
    }
}

5. How to close specific toast

Here is an example of how to close an individual toast:

import {Component} from '@angular/core';
import {ToastaService, ToastaConfig, ToastaComponent, ToastOptions, ToastData} from 'ngx-toasta';
import {Subject, Observable, Subscription} from 'rxjs/Rx';

@Component({
    selector: 'app',
    template: `
        <div>Hello world</div>
        <button (click)="addToast()">Add Toast</button>
        <ngx-toasta></ngx-toasta>
    `
})
export class AppComponent {
    
    getTitle(num: number): string {
        return 'Countdown: ' + num;
    }

    getMessage(num: number): string {
        return 'Seconds left: ' + num;
    }
    
    constructor(private toastaService:ToastaService) { }
    
    addToast() {
        let interval = 1000;
        let subscription: Subscription;
        
        let toastOptions: ToastOptions = {
            title: this.getTitle(0),
            msg: this.getMessage(0),
            showClose: true,
            onAdd: (toast: ToastData) => {
                console.log('Toast ' + toast.id + ' has been added!');
                // Run the timer with 1 second iterval
                let observable = Observable.interval(interval);
                // Start listen seconds beat
                subscription = observable.subscribe((count: number) => {
                    // Update title of toast
                    toast.title = this.getTitle(count);
                    // Update message of toast
                    toast.msg = this.getMessage(count);
                    // Extra condition to hide Toast after 10 sec
                    if (count > 10) {
                        // We use toast id to identify and hide it
                        this.toastaService.clear(toast.id);
                    }
                });

            },
            onRemove: function(toast: ToastData) {
                console.log('Toast ' + toast.id + ' has been removed!');
                // Stop listenning
                subscription.unsubscribe();
            }
        };

        switch (this.options.type) {
            case 'default': this.toastaService.default(toastOptions); break;
            case 'info': this.toastaService.info(toastOptions); break;
            case 'success': this.toastaService.success(toastOptions); break;
            case 'wait': this.toastaService.wait(toastOptions); break;
            case 'error': this.toastaService.error(toastOptions); break;
            case 'warning': this.toastaService.warning(toastOptions); break;
        }
    }
}

6. Customize the ngx-toasta for your application in template

You can use the following properties to customize the ngx-toasta component in your template:

  • position - The window position where the toast pops up. Default value is bottom-right. Possible values: bottom-right, bottom-left, bottom-fullwidth top-right, top-left, top-fullwidth,top-center, bottom-center, center-center Example:
<ngx-toasta [position]="'top-center'"></ngx-toasta>

7. Options

Use these options to configure individual or global toasts

Options specific to an individual toast:

ToastOptions
{
    "title": string,      //A string or html for the title
    "msg": string,        //A string or html for the message
    "showClose": true,    //Whether to show a close button
    "showDuration": true, //Whether to show a progress bar
    "theme": "default",   //The theme to apply to this toast
    "timeout": 5000,      //Time to live until toast is removed. 0 is unlimited
    "onAdd": Function,    //Function that gets called after this toast is added
    "onRemove": Function  //Function that gets called after this toast is removed
}

Configurations that affects all toasts:

ToastaConfig
{
    "limit": 5,                 //Maximum toasts that can be shown at once. Older toasts will be removed. 0 is unlimited
    "showClose": true,          //Whether to show the 'x' icon to close the toast
    "showDuration": true,       //Whether to show a progress bar at the bottom of the notification
    "position": "bottom-right", //The window position where the toast pops up
    "timeout": 5000,            //Time to live in milliseconds. 0 is unlimited
    "theme": "default"          //What theme to use
}

Credits

Original work by ng2-toasty

License

MIT

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].