1.2.0 • Published 2 years ago

@anedomansky/ngx-toast v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

ngx-toast

npm version

An easy to use toast component.

Features

Dependencies

ngx-toastAngular
current>= 13

Installation

Requirements

npm install @angular/animations

Install

npm install @anedomansky/ngx-toast

Setup

Add BrowserAnimationsModule and NgxToastModule:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgxToastModule } from '@anedomansky/ngx-toast';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing/app-routing.module';

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

Usage

app.component.html:

<section class="btn-container">
    <button class="btn btn--success" (click)="createSuccessToast()">Success</button>
    <button class="btn btn--info" (click)="createInfoToast()">Info</button>
    <button class="btn btn--warning" (click)="createWarningToast()">Warning</button>
    <button class="btn btn--error" (click)="createErrorToast()">Error</button>
</section>
<ngx-toast-container [position]="position">
    <ng-template ngxToast></ng-template>
</ngx-toast-container>

app.component.ts:

import { Component, ViewChild } from '@angular/core';
import { Position, Severity, ToastDirective, ToastService } from '@anedomansky/ngx-toast';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  additionalClasses = 'test';
  position = Position.TOP_LEFT;
  severity = Severity.SUCCESS;

  @ViewChild(ToastDirective, {static: true}) toast!: ToastDirective;

  constructor(public toastService: ToastService) {}

  createSuccessToast() {
    this.toastService.create("Title", "Message text.", this.toast, { severity: Severity.SUCCESS });
  }

  createInfoToast() {
    this.toastService.create("Title", "Message text.", this.toast, { severity: Severity.INFO });
  }

  createWarningToast() {
    this.toastService.create("Title", "Message text.", this.toast, { severity: Severity.WARNING });
  }

  createErrorToast() {
    this.toastService.create("Title", "Message text.", this.toast, { severity: Severity.ERROR });
  }
}

Component Props

ToastContainer (ngx-toast-container):

NameTypeDefaultDescription
positionPosition'top-left'Specifies the position of the toast container.

ToastComponent (ngx-toast):

NameTypeDefaultDescription
additionalClassesstringAdditional CSS-classes that will be appended to the '.toast' (Separated by whitespace).
closeBtnbooleantrueDisplay the close button.
easeTimenumber300Animation time in 'ms'.
indexnumberThe Index is used in order to remove the toast via ToastService.
progressBarbooleantrueDisplay the progress bar.
severitySeverity'info'Specifies the theme of the toast.
timeoutnumber5000The time in 'ms' until the toast is automatically removed.
titlestringThe toast's title.

License

MIT

1.2.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago