react-alert-receptiv
A simple react alert (toaster style) component for specific use by Receptiv. Modified slighly from https://www.npmjs.com/package/react-alert
Installation
$ npm install react-alert-receptiv
Usage
To use it, you have to import the AlertContainer
component, like this:
alertOptions = offset: 14 position: 'bottom left' theme: 'dark' time: 5000 transition: 'scale' { thismsg } { return <div> <AlertContainer ref= thismsg = a ...thisalertOptions /> <button onClick=thisshowAlert>Show Alert</button> </div> }
Api
Once you have the reference of the AlertContainer
you can call the following methods:
// show an alertthismsg// show an info alertthismsg// show a success alertthismsg// show an error alertthismsg// removes all alerts from the pagethismsg
Options
The AlertContainer
component accepts the following props:
// defaults offset: 14 // the offset of the alert from the page border, can be any number position: 'bottom left' // the position of the alert, can be [bottom left, bottom right, top left, top right] theme: 'dark' // the color theme of the alert, can be [dark, light] time: 5000 // the time in miliseconds to the alert close itself, use 0 to prevent auto close (apply to all alerts) transition: 'scale' // the transition animation, can be [scale, fade]
When you call show
, info
, success
and error
method, you can include the following options as a second parameter:
time: 0 // the time in miliseconds to the alert close itself, use 0 to prevent auto close (apply to this alert only), default is 5000 icon: <img src="path/to/some/img/32x32.png" /> // the icon to show in the alert, if none is given the default of each type will be showed {} // the function called when message is closed {} // the function called when message is opened
When you call the show
method, you can additionally include the info
option:
type: 'info' // the alert type, can be [info, success, error], default is info
Using React Components as alert content
You can also use a React Component to show an alert message, like this:
// show an alert with a React Component as contentthismsg