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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@filip.mazev/toastr

v1.0.10

Published

**Blocks** is a powerful Angular component library. The **Toastr** package provides a highly customizable, component-driven toast notification system. It features robust queue management, swipe-to-dismiss gestures for mobile, flexible screen positioning,

Readme

@filip.mazev/toastr

Blocks - Toastr Library

Blocks is a powerful Angular component library. The Toastr package provides a highly customizable, component-driven toast notification system. It features robust queue management, swipe-to-dismiss gestures for mobile, flexible screen positioning, and full type safety for dynamic content.

Features

  • Service-Driven & Component-Based: Queue toasts from anywhere using ToastrService while rendering your own custom Angular components inside the toast wrappers.
  • Smart Queue Management: Automatically limits the number of visible toasts on screen (configurable) and queues the rest.
  • Flexible Positioning: Supports top/bottom and left/right/center placements, adjusting automatically for mobile viewports.
  • Mobile Optimized: Native-feeling vertical swipe-to-dismiss gestures built-in.
  • Auto-Dismiss: Configurable timeouts to automatically close notifications.
  • Dynamic Data: Pass strictly typed data to your toast components and return results.

Installation

npm i @filip.mazev/toastr@latest

Or with the global blocks ng command which adds all blocks packages and sets up your styles.scss

ng add @filip.mazev/blocks@latest

Theme Configuration

To ensure the library's stylization works correctly, import the core theme provider in your global styles (styles.scss). The toast notifications utilize standard CSS variables for styling.

@use '@filip.mazev/blocks-core/src/lib/styles/index' as blocks;
@use '@filip.mazev/toastr/lib/styles/index' as toastr;

@layer base {
    :root {
        @include blocks.core-theme(blocks.$default-light-theme-config);

        // if you dont want to override themes, just use: 
        // @include toastr.toastr-theme(());

        @include toastr.toastr-theme((
            /* Optional: Override default Toast style variables */
          '--toast-bg': #ffffff,
          '--toast-text': #000000
        ));
    }

    [data-theme='dark'] {
        @include blocks.core-theme(blocks.$default-dark-theme-config);

        @include toastr.toastr-theme((
          /* Optional: Override default Toast wrapper variables */
          '--toast-bg': #000000,
          '--toast-text': #ffffff
        ));
    }
}

Note: If you provide a custom wrapperClass in your toast configuration, you can bypass the default wrapper styling entirely and apply your own custom CSS classes.

Usage

Create a Toast Component

Your custom toast components must extend the Toast<TData, TResult> base class (which implements IToast<D, R>).

Typescript:

import { Component } from '@angular/core';
import { Toast } from '@filip.mazev/toastr';
import { INotificationView } from '@interfaces/ui/inotification-view.interface';

@Component({
  selector: 'app-custom-toast',
  templateUrl: './custom-toast.html',
  styleUrl: './custom-toast.scss'
})
export class CustomToastComponent extends Toast<INotificationView, undefined> {
  
  // Example method to close the toast from within the component
  protected onDismiss(): void {
    this.close(); 
  }
}

HTML (Template):

<div class="notification">
    <button class="notification-close-button" (click)="onDismiss()">✕</button>
    <div class="notification-content">
        <h3>{{ data.title }}</h3>
        <p [class]="'notification-' + data.type">{{ data.message }}</p>
    </div>
</div>

About ToastRef<R>

Accessible via this.toast inside any component that extends Toast. This reference provides programmatic control over the active toast instance.

Methods & Observables

  • close(): Triggers the exit animation and safely removes the toast from the DOM, allowing the next queued toast to appear.
  • afterClosed$: An Observable<void> that emits once the toast has fully closed and animations have finished.

2. Opening the Toast

Use the ToastrService to launch your component. Unlike modals, toasts are "queued", meaning if you exceed the maxOpened limit, they will wait their turn before displaying.

import { Component, inject } from '@angular/core';
import { ToastrService } from '@filip.mazev/toastr';

@Component({ ... })
export class MyFeatureComponent {
    private readonly toastr = inject(ToastrService);

    public showNotification(view: INotificationView) {
        const toastRef = this.toastr.queueToast(CustomToastComponent, {
            data: view, // Strictly typed to INotificationView
            position: 'top-right',
            durationInMs: 5000,
            swipeToDismiss: true
        });

        toastRef.afterClosed$.subscribe(() => {
            console.log('Toast finished and removed from screen.');
        });
    }
}

Configuration Options

IToastConfig<D>

Controls the behavior, data, and placement of an individual toast:

  • data |D|: (optional) The typed payload passed into the toast component.
  • position |ToastPosition|: (optional) Where the toast should appear on the screen ('top-right', 'top-left', 'top-center', 'bottom-right', 'bottom-left', 'bottom-center'). Defaults to 'top-right'.
  • durationInMs |number|: (optional) The time in milliseconds before the toast automatically closes. Defaults to 5000.
  • swipeToDismiss |boolean|: (optional) Whether the user can swipe vertically to dismiss the toast. Defaults to true.
  • animate |boolean|: (optional) Whether the toast should animate in and out. Defaults to true.
  • wrapperClass |string|: (optional) A custom CSS class to apply to the toast's outer wrapper container. If omitted, it uses 'default-wrapper'.
  • hasDefaultBackground |boolean|: (optional) If set to false, the default background color will be removed from the default wrapper

Global Toastr Settings

Similar to the modal library (@filip.mazev/modal), you can manage application-wide defaults using the ToastrGlobalSettingsService. These defaults apply automatically unless overridden by the IToastConfig during the queueToast call. It also is the place where maxOpened is configured since this is a global configuration.

Example Usage

import { Component, inject } from '@angular/core';
import { ToastrGlobalSettingsService } from '@filip.mazev/toastr';

@Component({ ... })
export class AppComponent {
  private readonly toastrGlobalSettings = inject(ToastrGlobalSettingsService);

  constructor() {
    // Update global defaults at runtime
    this.toastrGlobalSettings.update({
      position: 'bottom-right',   // Move all toasts to the bottom right
      durationInMs: 7500,         // Keep toasts open longer by default
      maxOpened: 3,               // Only show 3 toasts at a time; queue the rest
      swipeToDismiss: true
    });
  }
}

How It Works

  • The ToastrGlobalSettingsService utilizes Angular Signals (signal<T>) for its internal state.
  • Whenever ToastrService.queueToast() is called, it resolves missing configuration options against these global signals.
  • You can dynamically alter these settings at any point in your application's lifecycle, affecting all subsequent toast notifications.

Quick Status Toasts (SimpleToast)

While toastr excels at rendering highly customized components, it also provides a built-in SimpleToast component for standard status notifications. You don't need to create your own components to display basic success, info, warning, or error messages.

The ToastrService exposes four convenience methods: queueSuccess, queueInfo, queueWarning, and queueError.

SimpleToast Usage

These methods accept an IQueueSimpleToastRequest object. They automatically inherit your global settings unless overridden.

import { Component, inject } from '@angular/core';
import { ToastrService } from '@filip.mazev/toastr';

@Component({ ... })
export class MyFeatureComponent {
    private readonly toastr = inject(ToastrService);

    public saveDocument() {
        // ... save logic ...

        // Fire a quick success toast
        this.toastr.queueSuccess({
            message: 'Your document was saved successfully.',
            title: 'Save Complete' // Optional
        });
    }

    public reportIssue() {
        // Fire a quick error toast with an overridden position
        this.toastr.queueError({
            message: 'Failed to connect to the server. Please try again later.',
            position: 'bottom-center', // Optional override
            durationInMs: 10000 // Optional override
        });
    }
}

The IQueueSimpleToastRequest Interface

When using the quick status methods, the configuration is streamlined to focus on the text content:

  • message |string|: The main text body of the toast. If no title is provided, this text is automatically scaled up slightly for better visibility.
  • title |string|: (optional) A bolded header for the toast.
  • position |ToastPosition|: (optional) Overrides the globally configured screen position.
  • durationInMs |number|: (optional) Overrides the globally configured auto-close timeout.

Styling the Simple Toasts

The SimpleToast component uses specific CSS variables for its status colors. To ensure they look correct in your application, define these variables in your global styles.scss theme configuration:

@use '@filip.mazev/blocks-core/src/lib/styles/index' as blocks;
@use '@filip.mazev/toastr/lib/styles/index' as toastr;

@layer base {
    :root {
        @include blocks.core-theme(blocks.$default-light-theme-config);

        @include toastr.toastr-theme((
          /* Optional: Override default Toast wrapper variables */
          '--simple-toast-info': #e3f2fd,
          '--simple-toast-success': #e8f5e9,
          '--simple-toast-warn': #fff3cd,
          '--simple-toast-error': #fdecea,
          'toast-text-warn': #d32f2f
        ));
    }
}