1.0.0 • Published 2 years ago

react-noti v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
2 years ago

Build Status Code Coverage version downloads MIT License

Table of Contents

Demo

A demo is worth a thousand words

Installation

$ npm install react-noti styled-components@5
$ yarn add react-noti styled-components@5

Usage

import React from 'react'
// POSITION is a helper variable that provides available position values to avoid typos
import { ReactNoti, notify, POSITION } from 'react-noti'

function App() {
  const handleSuccessClick = () => {
    notify.success('You can put almost anything here.')
  }
  const handleInfoClick = () => {
    notify.info('Info message', { title: 'Title here' })
  }
  const handleWarningClick = () => {
    notify.warning('Warning message', {
      title: 'Do not auto dismiss',
      autoDismiss: false,
    })
  }
  const handleErrorClick = () => {
    notify.error('Error message', {
      title: 'Close after 9000ms',
      timeOut: 9000,
    })
  }

  return (
    <div className="App">
      <ReactNoti position={POSITION.TOP_RIGHT} />

      <div>
        <button onClick={handleSuccessClick}>Success!</button>
        <button onClick={handleInfoClick}>Info!</button>
        <button onClick={handleWarningClick}>Warning!</button>
        <button onClick={handleErrorClick}>Error!</button>
      </div>
    </div>
  )
}

export default App

API

ReactNoti container

PropsTypeDefaultRequiredDescription
positionstringtop-rightDefines location of the ReactNoti component on the screen. Available options: top-right, top-left, top-center, bottom-right, bottom-left, bottom-center.
autoDismissbooleantrueAuto dismisses notification after the timeOut. Can be overridden individually.
timeOutnumber5000The default time in ms for the all toast notifications in the container tray. Can be overridden individually.
singlebooleanfalseSingle notification mode. Show only the last notification.
iconsbooleantrueShow default toast notifications icons or not.
pauseOnHoverbooleantruePause auto-dismissing countdown on mouse hover. Can be overridden individually.
showProgressbooleantrueShow countdown progress-bar on toast notifications. Can be overridden individually.
classNamestringundefinedAdds a class to the ReactNoti container for custom styling.

notify toast options

ParamsTypeDefaultRequiredDescription
contentstring | element-A text string or a component containing the content of the Toast notification.
optionsobject{}Options are listed bellow.

Optional notify methods parameters

OptionsTypeDefaultDescription
titlestringundefinedText string containing the title of the Toast notification.
autoDismissbooleantrueAuto dismiss notification after the timeOut. Overrides global ReactNoti autoDismiss.
timeOutnumber5000Time in ms for individual Toast in the tray. Overrides global ReactNoti timeOut.
pauseOnHoverbooleantruePause auto-dismissing countdown on mouse hover. Overrides global ReactNoti pauseOnHover.
showProgressbooleanfalseShow countdown progress-bar on toast notifications. Overrides global ReactNoti showProgress.

:warning:️ Toast options supersede ReactNoti container props :warning:

const Img = ({ src }) => <span><img width={48} src={src} /></span>
const options = {
  title: 'Toast title'
  autoDismiss: true,
  timeOut: 5000,
  pauseOnHover: true,
  showProgress: false
}

// Success.
notify.success('Hello')
// Info. Pass optional params that overwrites the default ones
notify.info('World', options)
// Warning. Passes React Component as a message content
notify.warning(<Img />)
// Error. Passes optional param that disables toast auto dismiss
notify.error('Oops!', { autoDismiss: false })

// Removes all toasts!
notify.closeAll()

License

MIT

1.0.0

2 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago