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

@glomllc/toastr

v0.0.4

Published

> **A React library for displaying toast notifications.**

Downloads

1

Readme

@glomllc/toastr

A React library for displaying toast notifications.

Author

This project is brought to you by Tchakoumi Lorrain Kouatchoua ✨

Repository

For more details, contribution, issue repors or support, please visit the repository.

Installation

To install the library, run:

npm install @glomllc/toastr

Usage

Step 1: Configure the Provider at the Root of Your Project

In your root file (e.g., index.tsx or index.js), wrap your application with the ToastrProvider and configure the necessary props.

import ReactDOM from 'react-dom/client';
import { ToastrProvider } from '@glomllc/toastr';
import App from './App';

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(
  <ToastrProvider
    configs={{
      disableDismissAll: false,
      disableDecendantStyle: false,
      timeout: 2000,
      restartTimeoutAferHover: false,
    }}
  >
    <App />
  </ToastrProvider>
);

Step 2: Use the useToastr Hook in Your Components

Call the useToastr hook and destructure the toast, clearToast and notifications function to manage notifications.

import React from 'react';
import { useToastr } from '@glomllc/toastr';
import { Button } from '@mui/material';

export function App() {
  const { toast, clearToast } = useToastr();

  return (
    <div>
      <Button
        color="primary"
        variant="contained"
        onClick={() =>
          toast(`This is a demo toast message with this awesome library!`, {
            type: 'error',
            hasCloseButton: true,
            title: 'Demo Toast',
            restartTimeoutAferHover: true,
            timeout: 'infinite',
            action: () => alert('Action triggered'),
          })
        }
      >
        Show Toast
      </Button>
      <Button
        color="secondary"
        variant="contained"
        onClick={() => clearToast()} // Clears all toasts
      >
        Clear All Toasts
      </Button>
    </div>
  );
}

export default App;

Configuration

ToastrProvider Configurations

The ToastrProvider accepts a configs prop with the following options:

  • disableDismissAll: (boolean) Disables the "Dismiss All" button if set to true.
  • disableDecendantStyle: (boolean) Disables default styles applied to descendants if set to true.
  • timeout: (number | 'infinite') Sets the duration (in milliseconds) before the toast automatically disappears. Use 'infinite' to keep the toast visible indefinitely.
  • restartTimeoutAferHover: (boolean) Restarts the timeout when the toast is hovered if set to true.

Example:

<ToastrProvider
  configs={{
    disableDismissAll: false,
    disableDecendantStyle: false,
    timeout: 2000,
    restartTimeoutAferHover: false,
  }}
>
  {children}
</ToastrProvider>

Toast Configurations

The toast function accepts a message and an optional configuration object with the following options:

  • type: (string) Specifies the type of toast ('success', 'info', 'error').
  • title: (string) The title of the toast notification.
  • hasIcon: (boolean) If true, an icon will be displayed in the toast.
  • hasCloseButton: (boolean) If true, a close button will be displayed in the toast.
  • timeout: (number | 'infinite') Duration before the toast automatically disappears.
  • restartTimeoutAferHover: (boolean) Restarts the timeout when the toast is hovered.
  • action: (function) A callback function to execute when the action button is clicked.
  • actionButton: (JSX.Element) Custom action button component.
  • actionText: (string) Text for the action button.

Example:

toast('This is a demo toast message with this awesome library!', {
  type: 'error',
  hasCloseButton: true,
  title: 'Demo Toast',
  restartTimeoutAferHover: true,
  timeout: 'infinite',
  action: () => alert('Action triggered'),
});

Clear Toasts

The clearToast method can be used to clear all currently displayed toasts. You can also pass an optional id to clear a specific toast.

Example:

clearToast(); // Clears all toasts
clearToast('htc'); // Clears toast with id htc

Keywords

  • react
  • toastr
  • notification
  • alert
  • push
  • information
  • react-component
  • react-toastr
  • toastr
  • glomllc/toastr

License

This project is licensed under the MIT License.