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-bj-toaster

v0.0.7

Published

A simple Toast library for Angular

Downloads

415

Readme

Toaster for Angular

BJ Toaster is a customizable toast notification library for Angular applications, allowing you to display beautiful and responsive toast messages with animations.

Features

  • Customizable toast positions.
  • Supports multiple toast types (success, error, info).
  • Configurable maximum number of visible toasts.
  • Auto-dismiss functionality with customizable duration.
  • Smooth entry and exit animations.
  • Floating or fixed toast modes.

Preview

Installation

Install the library via npm:

npm install ngx-bj-toaster

Usage

1. Import the ToastService and TOAST_CONFIG into your Angular application

app.conf

import {
  ApplicationConfig,
  importProvidersFrom,
  InjectionToken
} from '@angular/core';
...

import { TOAST_CONFIG } from 'ngx-bj-toaster';

export const appConfig: ApplicationConfig = {
  providers: [
   ...,
    {
      provide: TOAST_CONFIG,
      useFactory: () => ({
        position: 'top-right',
        maxToasts: 3,
        duration: 5000,
        floating: false,
      }),
    },
  ],
};

2. Use the ToastService

Inject the ToastService in your component and use it to display toasts:

ExampleComponent

import { Component } from "@angular/core";
import { ToastService } from "ngx-bj-toaster";

@Component({
  selector: "app-example",
  template: `<button (click)="showSuccessToast()">Show Success Toast</button>`,
})
export class ExampleComponent {
  constructor(private toastService: ToastService) {}

  showSuccessToast() {
    this.toastService.success({
      title: "Operation Successful",
      message: "Your operation was completed successfully!",
    });
  }
}

3. Add the Toast Component to Your Application

Add the <bj-toaster/> selector to your application's root component or wherever you want the toasts to appear.

AppComponent Template

<bj-toaster /> <router-outlet></router-outlet>

4. Customize Toast Configurations (Optional)

You can customize the default behavior by providing a configuration object to the TOAST_CONFIG token.

Example

{ provide: TOAST_CONFIG, useValue: { position: 'bottom-left', maxToasts: 3, duration: 3000, floating: true } }

Toast Options

| Option | Type | Default | Description | | --------- | -------------------------------------------------------------------------------------------------------- | ------------- | ------------------------------------------- | | position | string ('top-right', top-left, 'bottom-right', 'bottom-left', 'top-center', 'bottom-center') | 'top-right' | Position of the toasts. | | maxToasts | number | 5 | Maximum number of visible toasts at a time. | | duration | number | 5000 | Duration (ms) before auto-dismiss. | | floating | boolean | false | Whether the toast should remain visible. |

ToastService API

| Method | Parameters | Description | | | ------------- | --------------------------------- | --------------------------------------------- | ------------------------- | | success | `toast: Omit<ToastMessage, 'id' | 'type'>, floating?: boolean` | Displays a success toast. | | error | `toast: Omit<ToastMessage, 'id' | 'type'>, floating?: boolean` | Displays an error toast. | | info | `toast: Omit<ToastMessage, 'id' | 'type'>, floating?: boolean` | Displays an info toast. | | addToast | toast: Omit<ToastMessage, 'id'> | Adds a custom toast message. | | | removeToast | id: string | Removes a toast by its ID. | | | getPosition | - | Retrieves the current position configuration. | |

License

This library is open-source and available under the MIT License.