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

@flywine93/ngx-notification

v0.0.3

Published

Angular 2+ message notification component.

Downloads

7

Readme

ngx-notification

It is a flexible and usable component.

Demo

Demo

Installation

1.You need install @flywine93/ngx-notification by npm

npm install @flywine93/ngx-notification --save

2.You need install @flywine93/ngx-autounsubscrb

npm i @flywine93/ngx-autounsubscrb --save

ngx-autounsubscrb Introduction

3.You need install @angular/animations

npm install --save @angular/animations

Import

You need to import NgxNotificationModule, BrowserAnimationsModule.

import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import { NgxNotificationModule } from '@flywine93/ngx-notification';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    AppRoutingModule,
    CommonModule,
    NgxNotificationModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Usage

1.Add ngx-notification to the component, which should be global.

eg. app.component.html

<ngx-notification></ngx-notification>

2.The message is triggered through the NgxNotificationService service.

import { NgxNotificationService } from '@flywine93/ngx-notification';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  constructor(private notification: NgxNotificationService) {
  }
}
  1. Send message by service.
  sendInfo() {
    this.notification.notify(NotificationType.INFO, 'Hello World', 'This is an information', 0);
  }

  sendSuccess() {
    this.notification.notify(NotificationType.SUCCESS, 'Hello World', 'This is a success !', 3000);
  }

  sendWarning() {
    this.notification.notify(NotificationType.WARNING, 'Hello World', 'This is a warning !');
  }

  sendError() {
    this.notification.notify(NotificationType.ERROR, 'Hello World', 'This is an error :(');
  }

It's that simple!!!

Advanced usage

Component Options

options: NotifyOptions

export type NotificationPosition = 't' | 'b' | 'lt' | 'lb' | 'rt' | 'rb';
export interface NotifyOptions {
    position?: NotificationPosition;
    startDistance?: number; 
    animation?: boolean;
    shadow?: boolean;
    title?: {
        infoFontColor?: string,
        successFontColor?: string,
        warningFontColor?: string,
        errorFontColor?: string,
        background?: string;
        bold?: boolean;
    };
    msg?: {
        infoFontColor?: string,
        successFontColor?: string,
        warningFontColor?: string,
        errorFontColor?: string,
        background?: string;
        maxHeight?: number;
    };
    infoBgColor?: string;
    successBgColor?: string;
    warningBgColor?: string;
    errorBgColor?: string;
}

| Option | Description | Default Value | | ----------- | ------------------------------------------------------ | ------------- | | position | The position of the notification message box, 't' | 'b' | 'lt' | 'lb' | 'rt' | 'rb' | rt | | startDistance | The distance between the starting position of the notification box and the top or bottom.number | 0 animation | Whether to turn on the appear and disappear animations.boolean | true shadow | Whether to turn on shadow effects.boolean | true title | The theme of the title in the notification box. | material theme msg | The theme of the message in the notification box. | material theme infoBgColor | general notification box background color | material theme successBgColor | success notification box background color | material theme warningBgColor | warning notification box background color | material theme errorBgColor | error notification box background color | material theme

  • position--t: top,b: bottom, lt: left top, lb: left bottom, rb: right bottom, rt: right top

Component Theme

There are now two themes available, material theme and darkWindstorm theme.

  1. material theme

2.darkWindstorm theme

Component Usage

1.change notification box position to b.

app.component.html

<button mat-raised-button color="basic" (click)="sendInfo()">Info</button>
<button mat-raised-button color="primary" (click)="sendSuccess()">Success</button>
<button mat-raised-button color="accent" (click)="sendWarning()">Warning</button>
<button mat-raised-button color="warn" (click)="sendError()">Error</button>

<ngx-notification [options]="options"></ngx-notification>

app.component.ts

import {
  NgxNotificationService,
  NotificationType,
  NotificationThemes, NotifyOptions, ThemeName } from '@flywine93/ngx-notification';
export class AppComponent {

  theme = ThemeName.MATERILA;
  options: NotifyOptions;

  constructor(private notification: NgxNotificationService) {
    this.options = {
      position: 'b'
    };
  sendInfo() {
    this.notification.notify(NotificationType.INFO, 'Hello World', 'This is an information', 0);
  }

  sendSuccess() {
    this.notification.notify(NotificationType.SUCCESS, 'Hello World', 'This is a success !');
  }

  sendWarning() {
    this.notification.notify(NotificationType.WARNING, 'Hello World', 'This is a warning !');
  }

  sendError() {
    this.notification.notify(NotificationType.ERROR, 'Hello World', 'This is an error :(');
  }
  }
}

2.change theme

app.component.html

<ngx-notification [theme]="theme" [options]="options"></ngx-notification>

app.component.ts

import {
  NgxNotificationService,
  NotificationType,
  NotificationThemes,
  NotifyOptions,
  ThemeName } from '@flywine93/ngx-notification';
export class AppComponent {

  theme = ThemeName.DARK_WINDSTORM;
  options: NotifyOptions;

  constructor(private notification: NgxNotificationService) {
    this.options = {
      position: 'b'
    };
  }
}

You can also customize colors by options property.

eg.

export class AppComponent {

  theme = ThemeName.MATERILA;
  options: NotifyOptions;

  constructor(private notification: NgxNotificationService) {
    this.options = {
      title: {
        infoFontColor: '#fff',
        successFontColor: '#fff',
        warningFontColor: '#fff',
        errorFontColor: '#fff',
        background: 'rgba(0, 0, 0, 0.6)',
        bold: true
      },
      msg: {
        infoFontColor: '#fff',
        successFontColor: '#fff',
        warningFontColor: '#fff',
        errorFontColor: '#fff',
        background: 'rgba(0, 0, 0, 0.4)'
      },
      infoBgColor: 'rgba(189, 189, 189, 0.9)',
      successBgColor: 'rgba(27, 158, 119, 0.9)',
      warningBgColor: 'rgba(217, 95, 2, 0.9)',
      errorBgColor: 'rgba(246, 71, 71, 0.9)'
    };
  }
}

The custom configuration will override the default configuration.

notification service

method

  • notify --- Send a message. notify(type: NotificationType, title: string, message: string, timeout = 3000): void
    • type: NotificationType enum, SUCCESS|WARNING|ERROR|INFO
    • title: message title
    • message: text
    • timeout: delay closing time,If it is 0ms, it will not close actively, it needs to close manually.
  • update --- Forced update options, eg. change position.
  • changeTheme --- change notification box theme
  • changeOptions --- change notification options then update

Usage

1.send a info notification.

You need inject NgxNotificationService service.

import {
  NgxNotificationService,
  NotificationType,
  ThemeName } from '@flywine93/ngx-notification';
export class AppComponent {

  theme = ThemeName.MATERILA;
  options: NotifyOptions;

  constructor(private notification: NgxNotificationService) {
  }

  sendInfo() {
    this.notification.notify(NotificationType.INFO, 'Hello World', 'This is an information', 1000);
  }
}

2.change options

export class AppComponent {

  theme = ThemeName.MATERILA;
  options: NotifyOptions = {position: 'rt'};

  constructor(private notification: NgxNotificationService) {
  }

  changeOptions(): void  {
    this.options.position = 'b';
    this.notification.update();
  }
}

If the update is not forced, it will be updated at the next change.

3.change options or theme by service

changePosition(dir: NotificationPosition): void {
  this.notification.changeOptions({position: dir});
}
changeTheme(theme: ThemeName): void {
  this.notification.changeTheme(theme);
}

TODO

  • [x] add update options by service
  • [x] add change theme by service

License

The MIT License (see the LICENSE file for the full text)