Smoking hot Notifications for Angular. Lightweight, customizable and beautiful by default.
npm install @ngxpert/hot-toast


![commitizen]()







> Smoking hot Notifications for Angular. Lightweight, customizable and beautiful by default. Inspired from react-hot-toast
https://github.com/ngxpert/hot-toast/assets/6831283/ae718568-d5ea-47bf-a41d-6aabc7d4a044
Sponsorships aid in the continued development and maintenance of ngxpert libraries. Consider asking your company to sponsor ngxpert as its core to their business and application development.
| @ngxpert/hot-toast | Angular |
|---|---|
1.x, 2.x | >= 17 < 18 |
3.x | >= 18 < 19 |
4.x | >= 19 < 20 |
5.x | >= 20 < 21 |
6.x | >= 21 |
- 🔥 Hot by default
- ☕ Easy to use
- 🐍 Snackbar variation
- ♿ Accessible
- 🖐️ Reduce motion support
- 😊 Emoji Support
- 🛠 Customizable
- ⏳ Observable API
- ✋ Pause on hover
- 🔁 Events
- 🔒 Persistent
- 🎭 Grouping
- 🔒 CSP Compatible
- 📦 Customizable Toast Container
- 💬 Popover API
Using Angular CLI:
``bash`
ng add @ngxpert/hot-toast
With npm:
`bash`
npm install @ngneat/overview@7.0.0 @ngxpert/hot-toast
or yarn
`bash`
yarn add @ngneat/overview@7.0.0 @ngxpert/hot-toast
For older versions
`bashFor Angular version >= 9.1.13 < 13
npm install @ngneat/overview@2.0.2 @ngneat/hot-toast@3
Setup
$3
`typescript
import { AppComponent } from './src/app.component';import { provideHotToastConfig } from '@ngxpert/hot-toast';
bootstrapApplication(AppComponent, {
providers: [
provideHotToastConfig(), // @ngxpert/hot-toast providers
],
});
`$3
Add
provideHotToastConfig() to your app.module.ts providers section. Toast options (Partial) here.:`typescript
import { provideHotToastConfig } from '@ngxpert/hot-toast';@NgModule({
providers: [provideHotToastConfig()],
})
class AppModule {}
`$3
if you use SCSS add this line to your main styles.scss:
`scss
@use '@ngxpert/hot-toast/src/styles/styles.scss';
`or if you use CSS add this to your styles inside your angular.json:
`json
"styles": [
"node_modules/@ngxpert/hot-toast/src/styles/styles.css",
],
`Basic Usage
`typescript
import { HotToastService } from '@ngxpert/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();
}
}
`ToastOptions while creating the toast to customize the look and behavior:`typescript
import { HotToastService } from '@ngxpert/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',
},
});
}
}
`ToastConfig options while importing:`typescript
import { provideHotToastConfig } from '@ngxpert/hot-toast';@NgModule({
providers: [
provideHotToastConfig({
reverseOrder: true,
dismissible: true,
autoClose: false,
}),
],
})
class AppModule {}
`Additionally, you have the option of using a standalone function to provide a global toast configuration within your app's configuration file:
`typescript
// app.config.ts
import { provideHotToastConfig } from '@ngxpert/hot-toast';export const appConfig: ApplicationConfig = {
providers: [provideHotToastConfig({ ... })],
};
`Examples
You can checkout examples at: .
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_ |
| visibleToasts | number | Sets the number of toasts visible. 0 will set no limit.
_Default: 5_ |
| stacking | "vertical"\|"depth" | Sets Sets the type of stacking
_Default: "vertical"_ |
| usePopover | boolean | Sets whether to use the popover API
_Default: undefined_ |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 | 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 |
| group | group | Allows you to set group options.
Examples: Pre-Grouping, Post-Grouping | No |Injection Tokens
$3
Injection token to provide a custom container selector for the toast container. The value will be used as a selector to find the container element using
document.querySelector.`typescript
import { HOT_TOAST_CONTAINER_TOKEN, provideHotToastConfig } from '@ngxpert/hot-toast';bootstrapApplication(AppComponent, {
providers: [
provideHotToastConfig(),
{
provide: HOT_TOAST_CONTAINER_TOKEN,
useValue: '#toast-container',
},
],
}).catch((err) => console.error(err));
`---
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
$3
The
surrounding is removed from .hot-toast-message` to better and easy structure of layout. User may need to check their templates after updating to v2.None
Thanks goes to these wonderful people (emoji key):
Dharmen Shah 💻 🖋 🎨 📖 💡 | Netanel Basal 🐛 💼 🤔 🚧 🧑🏫 📆 🔬 👀 | Timo Lins 🎨 🤔 | Patrick Miller 🚧 📦 | Gili Yaniv 💻 | Artur Androsovych 🚧 | Luis Castro 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!