Giter Club home page Giter Club logo

react-toasts's Introduction

License Version

Lightweight react toasts manager

react-toasts is a very simple and lightweight component to create toasts.

alt text

Demo url : https://vashnak.co/react-toasts/

How to use

$ npm install -S react-toasts

You have to import 2 modules : ToastContainer and ToastStore

import {ToastContainer, ToastStore} from 'react-toasts';

function render(){
    return <div>
        <button onClick={() => ToastStore.error("There is an error :'(")}>Click me !</button>
        <ToastContainer store={ToastStore}/>
    </div>
}

ToastContainer is the container and ToastStore is the toasts manager.

You have to set the ToastStore as parameter of ToastContainer (example just before), it won't work if you forget it.

Now you can simply call one of the 4 functions of the ToastStore :

  • success(message: string, timer?: number = 3000, classNames?: string) : green toast.
  • info(message: string, timer?: number = 3000, classNames?: string) : white toast.
  • warning(message: string, timer?: number = 3000, classNames?: string) : yellow toast.
  • error(message: string, timer?: number = 3000, classNames?: string) : red toast.

Like this:

ToastStore.success('Hey, it worked !');

The timer parameter is optional and its default value is 3000ms. The classNames parameter is also optional, if you have multiple classes to add, please separate them with a space ("class1 class2 ...").

The container can have 6 positions, TOP_RIGHT, TOP_LEFT, TOP_CENTER, BOTTOM_RIGHT, BOTTOM_LEFT, BOTTOM_CENTER. By default its position is BOTTOM_RIGHT. You can change it by using the property "position" on the ToastContainer element

<ToastContainer position={ToastContainer.POSITION.TOP_LEFT}/>

If you want toasts to have light color background, add lightBackground true property on the ToastrContainer element

<ToastContainer position={ToastContainer.POSITION.TOP_LEFT} lightBackground />

Updates

2.0.7

Now support line break in toasts (\n).

2.0.8

Added a class on each toasts.

2.0.9

Can now add custom classes to toasts.

react-toasts's People

Contributors

vashnak avatar nainxo13 avatar kasongoyo avatar

Watchers

James Cloos avatar ryankim avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.