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

toast-controller

v0.11.6

Published

Vanilla JS implementation of the Toast alert

Downloads

39

Readme

ToastController.js

Build Status npm version

Example Gif of Toast Animating

Vanilla JS, performant implementation of the Toast, a popular UI element used primarily by Google and material design applications. Built to be plug-and-play, but you can easily extend and modify the JS and CSS to your liking.

Basic useage and examples are provided below. If you require additional documentation, please check out the project wiki. If you are still having trouble/questions, feel free to open an issue.

Major Features:

  • Vanilla JS, CSS; no frameworks/plugins required
  • Follows the Material Design spec for Toasts/Snackbars
  • Performant (uses proper layers and transformations)
  • #a11y (accessibility friendly)
  • Integrates with existing build systems/projects
  • No inline JS

Installation

You can either download the latest release of the project, or install it from NPM using:

npm i --save toast-controller

Importing into Your Project

To import this into your project/website, download the lastest copy of the ToastController, then import the ToastController.min.js into your site wherever needed.

If you use webpack, you can import the ToastController into your output using:

import * as ToastController from "toast-controller";

In addition, you'll need the styles associated with it. You can either import the included sass/toast.scss into your SASS/SCSS, the included less/toast.less, or just import the prebuilt stylesheet in the dist/css/ folder, which is called toast-controller.min.css.

Useage

This is just a sample of how to use the ToastController, check out the wiki to get more detailed information on methods and options.

Basics

To open a Toast, just call ToastController.openToast(). The Toast will automatically close after 5 seconds (or a delay of your specification):

ToastController.openToast({
    name: "hello.world",
    text: "Hello, World!"
});

To close a Toast manually, just call ToastController.closeToast() with the name of the Toast you specified when you opened it:

ToastController.closeToast("hello.world");

You can also close the toast by calling the close() method on the actual Toast object, which is returned from the openToast() method:

var toast = ToastController.openToast({
   name: "hello.world",
   text: "Hello, World!"
});

// Later, when you want to close the toast
toast.close();

Options

You can also specify different options to control the behavior of the Toast. For example, you can specify how long of a delay before the Toast automatically closes itself. This is by default 5 seconds.

ToastController.openToast({
    name: "delayed",
    text: "Hello, World!",
    delay: 10000 // the Toast will stay open for 10 seconds
});

Icons

A Toast can also optionally have an icon. By default, this comes from the Google Material Icons, and you will have to import the Material Icons stylesheet in order to use those icons.

To add an icon to a Toast, when you open it, you can specify the icon parameter, and the name of the icon. For example:

ToastController.openToast({
    name: "success.with-icon",
    text: "Success",
    icon: "done" // adds a checkmark icon
});

Please see the Wiki for more information on how to configure support for custom icons/other icon sets.

Feedback, Bugs, Etc.

If you encounter any bugs, wish there was some feature that I didn't think of, or just wish to provide feedback, feel free to open an issue, or contact me directly. I'm more than happy to help.

Legal

This code is open source, and licensed under the popular ISC license for you to use at your discretion. TL;DR: you can use it however you want, just make sure to mention my name somewhere in your project.

The name Google is a trademark of Google Inc.