import Toast from typescript-toastify;
const toast = new Toast({
position: "top-right",
toastMsg: "π¦ TypeScript Toastify",
autoCloseTime: 2000,
canClose: true,
showProgress: true,
pauseOnHover: true,
pauseOnFocusLoss: true,
type: "default",
theme: "light"
});
Code snippet example
TypeScript-Toastify is a TypeScript library for creating customizable toast notifications in web applications. This documentation provides an overview of the available options, how to create a toast, and their respective types.
To use TypeScript-Toastify in your project, you can install it via npm:
npm i typescript-toastify
To create a toast using TypeScript Toastify, you need to instantiate the Toast class with the desired options. Here's how you can create a toast:
import Toast from 'typescript-toastify';
const toast = new Toast({
position: "top-right",
toastMsg: "π Hello, World!",
autoCloseTime: 4500,
canClose: true,
showProgress: true,
pauseOnHover: true,
pauseOnFocusLoss: true,
type: "default",
theme: "dark"
});
TypeScript-Toastify supports the following options:
Specifies the position where the toast notification will appear on the screen.
Options:
The message to be displayed in the toast notification.
Specifies the duration (in milliseconds) after which the toast will automatically close.
Determines whether the user can manually close the toast by clicking on it.
Specifies whether to show a progress bar indicating the time remaining before the toast closes automatically.
Determines whether the toast progress and auto-close timer pause when the mouse hovers over the toast.
Specifies whether to pause the toast progress and auto-close timer when the page loses focus.
Specifies the type of toast notification. Options include:
Specifies the theme of the toast notification. Options include:
Updates the toast notification with new options.
const toast = new Toast({ });
toast.update({ toastMsg: 'New message' });
Removes the toast notification from the screen.
const toast = new Toast({ });
toast.remove( );
A function that runs when the toast notification is closed.
const toast = new Toast({
onClose: () =>
console.log('Toast closed πΆβπ«οΈ')
});
import Toast from 'typescript-toastify';
const toast = new Toast({
position: "top-right",
toastMsg: "π Hello, World!",
onClose: () => { alert("Toast closed πΆβπ«οΈ") },
autoCloseTime: 3000,
canClose: true,
showProgress: true,
pauseOnHover: true,
pauseOnFocusLoss: true,
type: "info",
theme: 'light'
});
TypeScript-Toastify offers a simple and customizable way to implement toast notifications in your TypeScript web applications. With various options for positioning, styling, and behavior, you can tailor the toast notifications to suit your application's needs.
Licensed under MIT