• Stars
    star
    687
  • Rank 65,351 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 4 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🍞 Smoking hot Notifications for Angular. Lightweight, customizable and beautiful by default.


npm MIT commitizen PRs styled with prettier styled with prettier All Contributors ngneat cypress semantic-release

Smoking hot Notifications for Angular. Lightweight, customizable and beautiful by default. Inspired from react-hot-toast

Compatibility with Angular Versions

@ngneat/hot-toast Angular
3.x >= 9.1.13 < 13
4.x >= 13 < 15
5.x >= 15

Features

  • πŸ”₯ Hot by default
  • β˜• Easy to use
  • 🐍 Snackbar variation
  • β™Ώ Accessible
  • πŸ–οΈ Reduce motion support
  • 😊 Emoji Support
  • πŸ›  Customizable
  • ⏳ Observable API
  • βœ‹ Pause on hover
  • πŸ” Events
  • πŸ”’ Persistent

Installation

You can install it through Angular CLI:

ng add @ngneat/hot-toast

or with npm:

# For Angular version >= 9.1.13 < 13
npm install @ngneat/[email protected] @ngneat/hot-toast@3

# For Angular version >= 13 < 15
npm install @ngneat/[email protected] @ngneat/hot-toast@4

# For Angular version >= 15
npm install @ngneat/[email protected] @ngneat/hot-toast@5

When you install using npm or yarn, you will also need to import HotToastModule in your app.module. You can also set global toast options (Partial<ToastConfig>) here.:

import { HotToastModule } from '@ngneat/hot-toast';

@NgModule({
  imports: [HotToastModule.forRoot()],
})
class AppModule {}

Basic Usage

import { HotToastService } from '@ngneat/hot-toast';

@Component({})
export class AppComponent {
  constructor(private toast: HotToastService) {}

  showToast() {
    this.toast.show('Hello World!');
    this.toast.loading('Lazyyy...');
    this.toast.success('Yeah!!');
    this.toast.warning('Boo!');
    this.toast.error('Oh no!');
    this.toast.info('Something...');
  }

  update() {
    saveSettings
      .pipe(
        this.toast.observe({
          loading: 'Saving...',
          success: 'Settings saved!',
          error: 'Could not save.',
        })
      )
      .subscribe();
  }
}

You can pass ToastOptions while creating the toast to customize the look and behavior:

import { HotToastService } from '@ngneat/hot-toast';

@Component({})
export class AppComponent {
  constructor(private toast: HotToastService) {}

  customToast() {
    this.toast.success('Look at my styles, and I also need more time!', {
      duration: 5000,
      style: {
        border: '1px solid #713200',
        padding: '16px',
        color: '#713200',
      },
      iconTheme: {
        primary: '#713200',
        secondary: '#FFFAEE',
      },
    });
  }
}

You can also set global ToastConfig options while importing:

import { HotToastModule } from '@ngneat/hot-toast';

@NgModule({
  imports: [
    HotToastModule.forRoot({
      reverseOrder: true,
      dismissible: true,
      autoClose: false,
    }),
  ],
})
class AppModule {}

Examples

You can checkout examples at: https://ngneat.github.io/hot-toast#examples.

ToastConfig

All options, which are set Available in global config? from ToastOptions are supported. Below are extra configurable options:

Name Type Description
reverseOrder boolean Sets the reverse order for hot-toast stacking
Default: false

ToastOptions

Configuration used when opening an hot-toast.

Name Type Description Available in global config?
id string Unique id to associate with hot-toast. There can't be multiple hot-toasts opened with same id.
Example
No
duration number Duration in milliseconds after which hot-toast will be auto closed. Can be disabled via autoClose: false
Default: 3000, error = 4000, loading = 30000
Yes
autoClose boolean Auto close hot-toast after duration
Default: true
Yes
position ToastPosition The position to place the hot-toast.
Default: top-center
Example
Yes
dismissible boolean Show close button in hot-toast
Default: false
Example
Yes
role ToastRole Role of the live region.
Default: status
Yes
ariaLive ToastAriaLive aria-live value for the live region.
Default: polite
Yes
theme ToastTheme Visual appearance of hot-toast
Default: toast
Example
Yes
persist {ToastPersistConfig} Useful when you want to keep a persistance for toast based on ids, across sessions.
Example
No
icon Content Icon to show in the hot-toast
Example
Yes
iconTheme IconTheme Use this to change icon color
Example
Yes
className string Extra CSS classes to be added to the hot toast container. Yes
attributes Record<string, string> Extra attributes to be added to the hot toast container. Can be used for e2e tests. Yes
style style object Extra styles to apply for hot-toast.
Example
Yes
closeStyle style object Extra styles to apply for close button Yes
data DataType Allows you to pass data for your template and component. You can access the data using toastRef.data.
Examples: Template with Data, Component with Data
No
injector Injector Allows you to pass injector for your component.
Example
No

Supported Browsers

Latest versions of Chrome, Edge, Firefox and Safari are supported, with some known issues.

Accessibility

Hot-toast messages are announced via an aria-live region. By default, the polite setting is used. While polite is recommended, this can be customized by setting the ariaLive property of the ToastConfig or ToastOptions.

Focus is not, and should not be, moved to the hot-toast element. Moving the focus would be disruptive to a user in the middle of a workflow. It is recommended that, for any action offered in the hot-toast, the application offers the user an alternative way to perform the action. Alternative interactions are typically keyboard shortcuts or menu options. When the action is performed in this way, the hot-toast should be dismissed.

Hot-toasts that have an action available should be set autoClose: false, as to accommodate screen-reader users that want to navigate to the hot-toast element to activate the action.

Breaking Changes

2.0.2 -> 3.0.0

  • Content inside .hot-toast-message were wrapped into dynamic-content, now they are wrapped into div > dynamic-view
  • Use optional chaining while access toastRef in template. E.g. toastRef?.data
  • Add @Optional() decorator in components' constructor while injecting tokens which are used by toast's injector

4.1.0 -> 5.0.0

For this version you will also need to import the styles from the library like this if you're not using NgAdd

if you use SCSS add this line to your main styles.scss:

@use 'node_modules/@ngneat/hot-toast/src/styles/styles.scss';

or if you use CSS add this to your styles inside your angular.json:

"styles": [
     "node_modules/@ngneat/hot-toast/src/styles/styles.css",
],

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Dharmen Shah
Dharmen Shah

πŸ’» πŸ–‹ 🎨 πŸ“– πŸ’‘
Netanel Basal
Netanel Basal

πŸ› πŸ’Ό πŸ€” 🚧 πŸ§‘β€πŸ« πŸ“† πŸ”¬ πŸ‘€
Timo Lins
Timo Lins

🎨 πŸ€”
Patrick Miller
Patrick Miller

🚧 πŸ“¦
Gili Yaniv
Gili Yaniv

πŸ’»
Artur Androsovych
Artur Androsovych

🚧
Luis Castro
Luis Castro

πŸ’»

This project follows the all-contributors specification. Contributions of any kind welcome!

Icons made by Freepik from www.flaticon.com

More Repositories

1

falso

All the Fake Data for All Your Real Needs πŸ™‚
TypeScript
3,098
star
2

spectator

🦊 πŸš€ A Powerful Tool to Simplify Your Angular Tests
TypeScript
2,060
star
3

transloco

πŸš€ 😍 The internationalization (i18n) library for Angular
TypeScript
1,856
star
4

until-destroy

🦊 RxJS operator that unsubscribe from observables on destroy
TypeScript
1,733
star
5

elf

πŸ§™β€β™€οΈ A Reactive Store with Magical Powers
TypeScript
1,527
star
6

content-loader

βšͺ️ SVG component to create placeholder loading, like Facebook cards loading.
TypeScript
733
star
7

cashew

🐿 A flexible and straightforward library that caches HTTP requests in Angular
TypeScript
677
star
8

reactive-forms

(Angular Reactive) Forms with Benefits πŸ˜‰
TypeScript
609
star
9

tailwind

πŸ”₯ A schematic that adds Tailwind CSS to Angular applications
TypeScript
608
star
10

query

πŸš€ Powerful asynchronous state management, server-state utilities and data fetching for Angular Applications
TypeScript
555
star
11

forms-manager

πŸ¦„ The Foundation for Proper Form Management in Angular
TypeScript
517
star
12

error-tailor

πŸ¦„ Making sure your tailor-made error solution is seamless!
TypeScript
478
star
13

helipopper

🚁 A Powerful Tooltip and Popover for Angular Applications
TypeScript
392
star
14

nx-serverless

πŸš€ The Ultimate Monorepo Starter for Node.js Serverless Applications
TypeScript
388
star
15

dialog

πŸ‘» A simple to use, highly customizable, and powerful modal for Angular Applications
TypeScript
371
star
16

hotkeys

πŸ€– A declarative library for handling hotkeys in Angular applications
TypeScript
325
star
17

edit-in-place

A flexible and unopinionated edit in place library for Angular applications
TypeScript
252
star
18

svg-icon

πŸ‘» A lightweight library that makes it easier to use SVG icons in your Angular Application
TypeScript
251
star
19

inspector

πŸ•΅οΈ An angular library that lets you inspect and change Angular component properties
TypeScript
218
star
20

dirty-check-forms

🐬Detect Unsaved Changes in Angular Forms
TypeScript
199
star
21

input-mask

🎭 @ngneat/input-mask is an angular library that creates an input mask
TypeScript
199
star
22

lib

πŸ€– Lets you focus on the stuff that matters
TypeScript
180
star
23

transloco-keys-manager

πŸ¦„ The Key to a Better Translation Experience
TypeScript
174
star
24

dag

🐠 An Angular service for managing directed acyclic graphs
TypeScript
153
star
25

bind-query-params

Sync URL Query Params with Angular Form Controls
TypeScript
147
star
26

from-event

🦊 ViewChild and FromEvent β€” a Match Made in Angular Heaven
TypeScript
137
star
27

overview

πŸ€– A collection of tools to make your Angular views more modular, scalable, and maintainable
TypeScript
118
star
28

aim

Angular Inline Module Schematics
TypeScript
97
star
29

cmdk

Fast, composable, unstyled command menu for Angular. Directly inspired from pacocoursey/cmdk
TypeScript
91
star
30

copy-to-clipboard

βœ‚οΈ Modern copy to clipboard. No Flash.
TypeScript
78
star
31

variabless

JS & CSS - A Match Made in Heaven πŸ’Ž
HTML
78
star
32

loadoff

🀯 When it comes to loaders, take a load off your mind...
TypeScript
78
star
33

effects

πŸͺ„ A framework-agnostic RxJS effects implementation
TypeScript
63
star
34

avvvatars

Beautifully crafted unique avatar placeholder for your next angular project.
TypeScript
46
star
35

react-rxjs

πŸ”Œ "Plug and play" for Observables in React Apps!
TypeScript
37
star
36

subscribe

Subscription Handling Directive
TypeScript
34
star
37

elf-ng-router-store

Bindings to connect Angular router to Elf
TypeScript
24
star
38

ng-standalone-nx

TypeScript
24
star
39

lit-file-generator

🎁 A lit generator for a component, directive, and controller.
JavaScript
19
star
40

storage

TypeScript
18
star
41

material-schematics

TypeScript
3
star
42

svg-icon-demo

TypeScript
1
star