react-redux-toast
react-redux-toastr is a React toastr message implemented with Redux, primary consists of three things: a reducer, toastr emitter and a React component.
The reducer listens to dispatched actions from the component to maintain the toastr state in Redux.
Implementation Guide
1. Installation
npm install --save react-redux-toastr
2. Add the styles
-
import the scss file into to your project.
-
or import the css file.
- or include the css file from the demo site (NOTE: This can be change at anytime)
3. Add the reducer.
NOTE: The default mount point for react-redux-toastr
is toastr
.
4. Add the component into an app root
The default configuration is:
NOTE: transitionIn
and transitionOut
will affect the confirm animation as well
Here is the full list of available configurations:
-
position:
top-left
top-center
top-right
bottom-left
bottom-center
andbottom-right
-
transitionIn:
bounceIn
bounceInDown
andfadeIn
-
transitionOut:
bounceOut
bounceOutUp
andfadeOut
5. Use the emitter
The toastr
method use eventemitter3 to dispatch the actions
Or you can bind the actions
to your component if you prefer.
Toastr methods
Toastr accepts the following methods: success
info
warning
light
error
confirm
message
, remove
and removeByType
Toastr: success
info
warning
light
error
remove
and removeByType
Each of these methods can take up to three arguments the title
a message
and options
.
In options
you can specify timeOut
icon
onShowComplete
onHideComplete
className
component
removeOnHover
,removeOnHoverTimeOut
,showCloseButton
, onCloseButtonClick
, onToastrClick
, progressBar
, transitionIn
, position
, attention
, onAttentionClick
, transitionOut
and closeOnToastrClick
.
Toastr methods light
The light
method is like the other toastr
except that the background-color
is white
and you can add a top
border on top of the toastr
by passing the status
option
icon
can be one of the following:
'success'
'info'
'warning'
'error'
Toastr: message
This one is in case you wanna show a large amount of information, unlike the other methods above this will not close automatically unless you provide a timeout
in the message
options.
Toastr: confirm
The confirm method takes two arguments, the first is the message the second is a object where you can specify what will happen when the user clicks on ok
and cancel
button or by keypress
enter/esc
NOTE: You can only have one at a time, right now if you have one confirm
and you fire another it will be ignored.
You can change the ok
and cancel
text by:
- Passing the
confirm
props to theReduxToastr
component
- Passing the
okText
andcancelText
props to thetoasterConfirmOptions
object:
You can make it so ok
is the only button by:
- Passing the
disableCancel
prop to thetoasterConfirmOptions
object:
You can add custom buttons by:
-
Passing the
buttons
prop to thetoasterConfirmOptions
object.
The buttons are inserted after the OK and the cancel button.Each button config can have a
text
,handler
and aclassName
property.If you want to move the original OK or cancel button to a different place, just
insert a button config with a boolean flagok
orcancel
at the desired position
(note that all other properties are ignored in this button config).
The following config leads to 3 buttons in this order:
- "Apply" (original OK button)
- "Do not apply" (our custom button)
- "Cancel" (original cancel button)
You can render your custom message component instead of the simple string message by:
- Passing the
component
prop to thetoasterConfirmOptions
object:
Avatar: in case you wanna use the same avatar as the example
Run a local demo
git clone https://github.com/diegoddox/react-redux-toastr.git
cd react-redux-toastr
npm install
npm start
open your browser at http://localhost:3000