
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
toaster-uii
Advanced tools
Toaster UI is a lightweight JavaScript library for displaying toast notifications on web pages. It provides a simple and customizable way to show temporary messages or notifications to users. This documentation will guide you through the installation process, usage examples, and customization options of the library.
To use Toaster UI in your project, you have multiple options:
<script src="https://unpkg.com/toaster-ui@1.0.0/dist/main.js"></script>
<script src="https://cdn.jsdelivr.net/npm/toaster-ui@1.0.0/dist/main.js"></script>
npm install toaster-ui
After installing Toaster UI, you can import the library in your JavaScript code and start using it.
import Toaster from "toaster-ui";
// Create a new instance of Toaster
const toaster = new Toaster.ToastManager();
// Show a toast notification
toaster.addToast("Hello, world!");
In the above example, we import the Toaster UI library and create a new instance of it. Then, we use the addToast
method to display a toast notification with the content "Hello, world!" and the type "success".
You can specify the type (string), there are four (4) avaiable options
// Set a custom duration of 5 seconds (5000 milliseconds)
toastManager.addToast("This is an error toast", "default");
toastManager.addToast("This is a warning toast", "warning", {options});
OPTIONS | VALUE | DEFAULT |
---|---|---|
duration | number | 3000 |
onClose | function | null |
styles | object | null |
You can specify the duration (in milliseconds) for how long the toast should be displayed .
// Set a custom duration of 5 seconds (5000 milliseconds)
toastManager.addToast("This is an error toast", "error", { duration: 5000 });
You can apply custom CSS styles to the toast element. Pass an object with CSS property-value pairs as an argument inside the options objects.
// Apply custom styles to the toast element
toastManager.addToast("This is an error toast", "error", {
duration: 5000,
styles: {
backgroundColor: "teal",
color: "#ffffff",
},
});
You can provide a custom callback function that will be executed when the toast is closed using the onClose
option.
// Define a custom callback function
const onCloseCallback = () => {
console.log("Toast closed!");
};
// Create a toast with custom onClose callback
toastManager.addToast("This is a warning toast", "warning", {
onClose: onCloseCallback,
});
For more information and examples, you can refer to the Toaster UI GitHub repository.
Please note that the provided code snippets and examples are simplified for demonstration purposes. Make sure to adapt the code to your specific project requirements.
Feel free to explore the Toaster UI library and leverage its features to enhance the user experience on your web pages.
Here are some usage examples to demonstrate different scenarios:
toastManager.addToast("This is a simple toast message", "info");
const onCloseCallback = () => {
console.log("Toast closed!");
};
toastManager.addToast("Custom duration and callback", "success", {
duration: 5000,
onClose: onCloseCallback,
});
toastManager.addToast("First toast", "info");
toastManager.addToast("Second toast", "warning");
setTimeout(() => {
toastManager.addToast("This is a warning toast", "default", {
onClose: handleToastClose,
});
}, 2000);
FAQs
A toast notification library
We found that toaster-uii demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.