npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-snackbar

v2.0.1

Published

Snackbar implementation in Angular 7.

Downloads

808

Readme

ngx-snackbar

Angular 7 component for Snackbar (AKA Toast) notifications.

Demo

Installation

npm install --save ngx-snackbar

Usage

Import default styles

Import styles.css into your app. This step is optional, feel free to theme the snackbars to your liking.

index.html

<link rel="stylesheet" href="node_modules/ngx-snackbar/bundles/style.css">

Angular CLI

.angular-cli.json

...
  "styles": [
   "styles.css",
   "../node_modules/ngx-snackbar/bundles/style.css"
  ],
...

Import SnackbarModule

import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {AppComponent} from './app.component';
import {SnackbarModule} from 'ngx-snackbar';

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

SystemJS

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

Place the ngx-snackbar tag on your template

<ngx-snackbar></ngx-snackbar>

Options

Use these properties to customize the snackbar component.

| Name | Description | Type | Default | Optional | | --- | --- | --- | --- | --- | | position | The position where the snackbar appears | top-left, top-center, top-right, bottom-left, bottom-center, bottom-right | bottom-right | true | | max | The maximum number of snackbars allowed on screen | number | (Infinite) | true | | timeout | Number of milliseconds before the snackbar closes | number | (Infinite) | true | | color | Text color in hex | string | auto | true | | background | Background color in hex | string | #343434 | true | | customClass | Custom class to append to the snackbar | string | | true | | accent | Action button color. Requires action.text | string | #2196f3 | true |

Events

| Name | Description | Return | | --- | --- | --- | | onAdd | Callback gets triggered on snackbar add | Object | | onRemove | Callback gets triggered on snackbar remove | Object | | onClear | Callback gets triggered on snackbar clear | boolean |

Object: add method options plus id string.

Use the SnackbarService to control snackbars

Import SnakckbarService from ngx-snackbar:

import {Component} from '@angular/core';
import {SnackbarService} from 'ngx-snackbar';

@Component({
  selector: 'app-root',
  template: `
    <ngx-snackbar></ngx-snackbar>
  `
})
export class AppComponent {
  constructor(private snackbarService: SnackbarService) {}
}

Methods

  • add(options: Object)

All options will override global values set on ngx-snackbar.

| Name | Description | Type | Default | Optional | | --- | --- | --- | --- | --- | | msg | Message to display in the snackbar (HTML accepted) | string | | false | | timeout | Number of milliseconds before the snackbar closes | number | (Infinite) | true | | color | Text color in hex | string | auto | true | | background | Background color in hex | string | #343434 | true | | customClass | Custom class to append to the snackbar | string | | true | | action.text | Action button text. Snackbar will automatically dismiss on click | string | | true | | action.color | Action button color. Requires action.text | string | #2196f3 | true | | action.onClick | Action button callback. Requires action.text | Function | | true | | onAdd | Callback gets triggered on snackbar add | Function | | true | | onRemove | Callback gets triggered on snackbar remove | Function | | true |

  • remove(id: string)

Remove snackbar on screen by ID.

  • clear()

Clears all snackbars on screen.

Example

import {Component} from '@angular/core';
import {SnackbarService} from 'ngx-snackbar';

@Component({
  selector: 'app-root',
  template: `
      <button (click)="add()">Add Snackbar</button>
      <br>
      <button (click)="clear()">Clear</button>
      
      <ngx-snackbar [position]="'bottom-center'" [max]="3"></ngx-snackbar>
  `
})
export class AppComponent {
  constructor(private snackbarService: SnackbarService) {
  }

  add() {
    const _this = this;
    this.snackbarService.add({
      msg: '<strong>Message sent.</strong>',
      timeout: 5000,
      action: {
        text: 'Undo',
        onClick: (snack) => {
          console.log('dismissed: ' + snack.id);
          
          _this.undo();
        },
      },
      onAdd: (snack) => {
        console.log('added: ' + snack.id);
      },
      onRemove: (snack) => {
        console.log('removed: ' + snack.id);
      }
    });
  }

  clear() {
    this.snackbarService.clear();
  }
  
  undo() {
    ...
  }
}

Credits

Thanks angular-library-starter for the compilation scripts.

License

MIT