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-toastified

v3.0.16

Published

An easy-to-use, customizable toast notification system for React apps

Downloads

42

Readme

React Toastified

An easy-to-use, customizable toast notification system for React apps.

Features

  • Multiple toast types: Success, Error, Warning, Info
  • Customizable positions: top-center, top-right, top-left, bottom-center, bottom-right, bottom-left
  • Customizable themes: light, dark, colored
  • Progress bar for toasts with durations
  • Right-to-left (RTL) support
  • Multiple animations for toast entrance and exit
  • Queueing system for displaying multiple toasts
  • Option to display newest toast on top
  • Default and custom icons for each toast type

Installation

npm install react-toastified

Usage

Basic Setup

Wrap your application with the ToastProvider:

import React from "react";
import { ToastProvider } from "react-toastified";
import "react-toastified/styles/Toast.min.css";

function App() {
  return (
    <ToastProvider theme="dark" newestOnTop={true}>
      <MyComponent />
    </ToastProvider>
  );
}

Creating a Toast

Use the toast object to create toasts:

import React from "react";
import { toast } from "react-toastified";
import "react-toastified/styles/Toast.min.css";

function MyComponent() {
  const showToast = () => {
    toast.success("This is a success message!", {
      duration: 3000,
      position: "top-right",
      theme: "light",
    });
  };

  return (
    <div>
      <button onClick={showToast}>Show Toast</button>
    </div>
  );
}

Custom Icons

You can provide custom icons for your toasts:

import React from "react";
import { toast } from "react-toastified";
import "react-toastified/styles/Toast.min.css";
import { ReactComponent as CustomSuccessIcon } from "./path/to/custom-success-icon.svg";

function MyComponent() {
  const showToast = () => {
    toast.success("This is a success message!", {
      duration: 3000,
      position: "top-right",
      theme: "light",
      icon: <CustomSuccessIcon />,
    });
  };

  return (
    <div>
      <button onClick={showToast}>Show Toast</button>
    </div>
  );
}

Customization

Toast Types

Available toast types are defined in toast:

  • toast.success
  • toast.error
  • toast.warning
  • toast.info

Positions

Toasts can be positioned in the following areas:

  • top-center
  • top-right
  • top-left
  • bottom-center
  • bottom-right
  • bottom-left

Themes

Toasts can have different themes:

  • dark (default)
  • light
  • colored

Right-to-Left (RTL) Support

Enable RTL support by setting the rtl option to true:

toast.success("This is a success message!", {
  duration: 3000,
  position: "top-right",
  rtl: true,
});

Custom Class Names

Add custom class names to the toast for additional styling:

toast.info("Custom styled toast", {
  classNames: "custom-toast",
});

Progress Bar

Toasts with a duration will automatically show a progress bar:

toast.info("Toast with progress bar", {
  duration: 5000,
});

Animations

Toasts can have different animations based on their position:

  • slide-fade-out-up
  • slide-right-fade-out
  • slide-left-fade-out
  • slide-fade-out-down

These are automatically applied based on the toast's position.

Complete Example

import React from "react";
import { ToastProvider, toast } from "react-toastified";
import "react-toastified/styles/Toast.min.css";

function App() {
  const showSuccessToast = () => {
    toast.success("This is a success message!", {
      duration: 3000,
      position: "top-right",
      theme: "light",
      classNames: "custom-toast",
      rtl: true,
    });
  };

  const showErrorToast = () => {
    toast.error("This is an error message!", {
      duration: 3000,
      position: "bottom-left",
      theme: "colored",
    });
  };

  return (
    <ToastProvider theme="dark" newestOnTop={true}>
      <div>
        <button onClick={showSuccessToast}>Show Success Toast</button>
        <button onClick={showErrorToast}>Show Error Toast</button>
      </div>
    </ToastProvider>
  );
}

export default App;

CSS Customization

You can further customize the toasts using CSS. The following class names are available for styling:

  • .toast-container
  • .toast
  • .toast-success
  • .toast-error
  • .toast-warning
  • .toast-info
  • .toast-success-colored
  • .toast-error-colored
  • .toast-warning-colored
  • .toast-info-colored
  • .progress-bar

This documentation provides a comprehensive overview of how to use and customize the React Toastified package. If you have any questions or encounter issues, please refer to the GitHub repository for further information and support.