1.0.1 • Published 5 years ago

react-one-toast v1.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

react-one-toast

NPM version

Easily show notification from buttom to top with React. The main differnet with other libraries is that only one Toast will displayed with multiple notifacations, the later notification will replace the previous one. See demo here

Installation

npm i react-one-toast

Usage

Implement your toast component

// Toast.js
import React from 'react'

function Toast({ message }){
  const { link, text } = action

  return (
    <div className={style.toast}>{message}</div>
  )
}

Show toast when button clicked

// App.js
import React from 'react'
import Toast from './Toast'
import {useToast, ToastContainer } from 'react-one-toast'
import from 'react-one-toast/css/style.css'

function App(){
  const {showToast, props} = useToast()

  return (
    <>
      <button
        onClick={()=>{showToast(<Toast message="success !"/>)}}
      >
        Add to wishlist
      </button>
      <ToastContainer {...props}/>
    </>
  )
}

Modules

  • ToastContainer

    React element for showing toast

    propstyperequireddefaultdescription
    heightnumbertrue-Height of ToastContainer
    classNamestringfalse-Custom class name of ToastContainer
    contentReactNodetrue-ReactNode of Toast content
    timeoutTimeoutfalse-See type definetion bellow
    replaceDurationnumberfalse200traisition duration in milliseconds for replace taost content
    • Timeout

      propstyperequireddefaultdescription
      durationnumberfalse500traisition duration in milliseconds for showing ToastContainer
      appearnumberfalse2000timeout in milliseconds to hidding ToastContainer
  • useToast

    React hooks to generate props for ToastContainer

    argumentstyperequireddefaultdescription
    contentReactNodetrue-toast content
    optionsobjectfalse{}other props exclude content for ToastContainer