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

react-zaptoast

v0.0.4

Published

React Toast Snap is a simple and customizable toast notification component for React applications.

Downloads

20

Readme

React Zap Toast

React Zap Toast is a simple, customizable, and accessible toast notification component for React applications.

Installation

Install React Zap Toast via npm:

npm install react-zaptoast

Usage

To use React Zap Toast in your React application, follow these steps:

  1. Import the useNotification hook:
import useNotification from "react-zaptoast";
  1. Initialize the useNotification hook:
const { NotificationContainer, toast } = useNotification();
  1. Add the NotificationContainer to your JSX:
return (
  <div className="App">
    {NotificationContainer}
    {/* Your other JSX content */}
  </div>
);
  1. Trigger notifications using the toast function:
toast("This is a default message");
toast.success("This is a success message!");
toast.error("This is an error message!");
toast.info("This is an info message!");
toast.warning("This is a warning message!");

API

useNotification()

This hook returns an object with the following properties:

  • NotificationContainer: React element representing the notification container.
  • toast: Function to trigger notifications with various methods.
  • dismiss(id: string): Function to dismiss a specific notification.
  • dismissAll(): Function to dismiss all notifications.

toast(message: string, options?: ToastOptions)

The main function to trigger notifications. It returns a unique ID for the created notification.

ToastOptions

  • type: Type of the notification ("success" | "error" | "info" | "warning" | "default").
  • duration: Duration in milliseconds for which the notification should be displayed (default: 3000).
  • position: Position of the notification ("top-left" | "top-right" | "bottom-left" | "bottom-right").
  • animation: Animation type for the notification ("fade" | "pop" | "slide").

Shorthand Methods

  • toast.success(message: string, options?: Partial<ToastOptions>)
  • toast.error(message: string, options?: Partial<ToastOptions>)
  • toast.info(message: string, options?: Partial<ToastOptions>)
  • toast.warning(message: string, options?: Partial<ToastOptions>)

These methods are shortcuts for creating specific types of notifications.

Example

Here's a basic example of how to use React Zap Toast:

import React from "react";
import useNotification from "react-zaptoast";

function App() {
  const { NotificationContainer, toast } = useNotification();

  const showNotifications = () => {
    toast("Default notification");
    toast.success("Success!", { position: "top-right", animation: "pop" });
    toast.error("Error occurred", { duration: 5000 });
    toast.info("Just so you know...");
    toast.warning("Be careful!");
  };

  return (
    <div className="App">
      {NotificationContainer}
      <h1>React Zap Toast Demo</h1>
      <button onClick={showNotifications}>Show Notifications</button>
    </div>
  );
}

export default App;

Accessibility

React Zap Toast is designed with accessibility in mind:

  • Notifications use appropriate ARIA roles and live regions.
  • Error and warning notifications are announced immediately to screen readers.
  • Notifications can be dismissed using the keyboard.

License

This project is licensed under the MIT License - see the LICENSE file for details.