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 🙏

© 2024 – Pkg Stats / Ryan Hefner

toaster-uii

v1.0.5

Published

A toast notification library

Downloads

8

Readme

Toaster UI Library Documentation

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.

Table of Contents

Installation

To use Toaster UI in your project, you have multiple options:

  1. Script Tag: You can include the Toaster UI library directly in your HTML file using a script tag.
<script src="https://unpkg.com/[email protected]/dist/main.js"></script>
  1. CDN: Alternatively, you can use a CDN link in your HTML file.
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/main.js"></script>
  1. npm: If you prefer using npm, you can install Toaster UI as a dependency in your project.
npm install toaster-ui

Usage

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".

Customization

Changing Toast TYpe

You can specify the type (string), there are four (4) avaiable options

  • success
  • error
  • warning
  • info
// Set a custom duration of 5 seconds (5000 milliseconds)
toastManager.addToast("This is an error toast", "default");

Toaster UI provides several customization options for toast notifications. Here are some examples:

toastManager.addToast("This is a warning toast", "warning", {options});

| OPTIONS | VALUE | DEFAULT | | -------- | -------- | ------- | | duration | number | 3000 | | onClose | function | null | | styles | object | null |

Changing Toast Duration

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 });

Applying Custom Styles

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.

  • The custom style will overide the type of the toast
// Apply custom styles to the toast element
toastManager.addToast("This is an error toast", "error", {
  duration: 5000,
  styles: {
    backgroundColor: "teal",
    color: "#ffffff",
  },
});

Adding Custom Callback on Close

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,
});

Additional Resources

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.

Examples

Here are some usage examples to demonstrate different scenarios:

Example 1: Simple Toast

toastManager.addToast("This is a simple toast message", "info");

Example 2: Custom Duration and Callback

const onCloseCallback = () => {
  console.log("Toast closed!");
};

toastManager.addToast("Custom duration and callback", "success", {
  duration: 5000,
  onClose: onCloseCallback,
});

Example 3: Multiple Toasts

toastManager.addToast("First toast", "info");
toastManager.addToast("Second toast", "warning");

setTimeout(() => {
  toastManager.addToast("This is a warning toast", "default", {
    onClose: handleToastClose,
  });
}, 2000);