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-toaster-lib

v1.0.5

Published

toasts library

Downloads

9

Readme

React toast library

🏠 Homepage

Demo

Install

npm install react-toaster-lib

Usage:

Add container component to your App:

import { ToastContainer } from "react-toaster-lib";
...
<ToastContainer />

Container has default position "top-right", but you could use the next variants:

<ToastContainer position="top-left"/>
<ToastContainer position="top-center"/>
<ToastContainer /> //default position="top-right"
<ToastContainer position="bottom-left"/>
<ToastContainer position="bottom-center"/>
<ToastContainer position="bottom-right"/>

By default renders into div element with id="toasts-root" (it appends by library to document.body). But you could define your custom id for root element by using rootId ToastContainer attribute:

<ToastContainer position="top-left" rootId="your-custom-id" />

To create a Toast: import "toaster" library instance and use its addToast() method:

import { toaster } from "react-toaster-lib";
toaster.addToast("Toast text"); //minimum params required
toaster.addToast("Some text to show (required)", "Toast header (optional)", {
  type: "success", //"default" (predefined) | "info" | "success" | "warning" | "danger"
  lifeTime: 2000, // time in milliseconds, if used - toast will automatically close in this time
  animationType: "ease", //"ease" |"ease-in" | "ease-out" | "ease-in-out" (predefined) | "linear" | "cubic-bezier"
  showFrom: "left", // "left" | "right" | "top" | "bottom"
  hideTo: "left", // "left" | "right" | "top" | "bottom"
  bgColor: "#ffffff", //any valid color format
  fontColor: "rgb(179, 56, 56)", //any valid color format
  iconColor: "blue", //any valid color format
  margin: "md lg sm 12", //use constants "md", "lg", "sm" and digits without "px"
  padding: "md 7", //use constants "md", "lg", "sm" and digits without "px"
});

The signature of addToast method is: addToast(toastText [, toastHeader [, optionsObject]]) The single parameter required is toastText, other params are optional. You could use optionsObj as the second param if you do not need toast header.

addToast() options available:

  • type - Toast type determines its Icon type and default background, font and Icon colors. Types available: "default" (predefined) | "info" | "success" | "warning" | "danger"
  • lifeTime - time in milliseconds. If option not used or equals "0" - you could close Toast only manually by click on the cross or by swipe. If you use lifeTime with value > 0 (ms) - Toast will disappear automatically after time milliseconds
  • animationType - effect using on toast show / hide. Types available: "ease" | "ease-in" | "ease-out" | "ease-in-out" (predefined) | "linear", "cubic-bezier" (use cubic-bezier(0.1, 0.7, 1, 0.1) function)
  • showFrom - determine where from Toast will appear on the screen. Types available: "left" | "right" | "top" | "bottom" . showFrom param has predefined values according to ToastContainer positions: "left" if ToastContainer has "top-left" or "bottom-left" position, "right" if position is "top-right" or "bottom-right", "top" if position is "top-center" and "bottom" if position is "bottom-center"
  • hideTo - determine direction where Toast disappear from the screen. Types available: "left" | "right" | "top" | "bottom" . hideTo param has predefined values according to ToastContainer positions: "left" if ToastContainer has "top-left" or "bottom-left" position, "right" if position is "top-right" or "bottom-right", "top" if position is "top-center" and "bottom" if position is "bottom-center"
  • bgColor - custom background color, use any valid format. If not used or wrong value - library use default bg color according to Toast type
  • fontColor - custom font color, use any valid format. If not used or wrong value - library use default font color according to Toast type
  • iconColor - custom Icon color, use any valid format. If not used or wrong value - library use default Icon color according to Toast type
  • margin - set custom Toast margins - match standard CSS margin value (1-4 values divided with spaces), but you could use ONLY digits (without "px") and constants "sm" (=5px), "md" (=10px) or "lg"(=15px).
  • padding - set custom Toast paddings - match standard CSS padding value (1-4 values divided with spaces), but you could use ONLY digits (without "px") and constants "sm" (=5px), "md" (=10px) or "lg"(=15px).

Swipe to remove Toast feature available

Author

👤 treyer [email protected]

Give a ⭐️ if this project helped you!