React sAlert component
sAlert is a React component which provides alerts or notifications with rich configuration possibilities. This is a rewritten version of Meteor/Blaze sAlert package which you can find here: s-alert.meteor.com.
Usage with React
Here is what you need to do to make it work.
Of course you need to have React and ReactDOM installed in your project.
1. Install the package
npm install react-s-alert --save
2. Import component
With ES2015:
import Alert from 'react-s-alert';
With ES5:
var Alert = require('react-s-alert').default;
3. Import (or copy) CSS files
All you need to do is to import (or copy) a default CSS file and some or all CSS files with effects which you want to use. A default CSS file is mandatory. With Webpack you could do something like:
With ES2015:
With ES5:
You can also copy the files and include it another way in your app. It depends on your workflow.
If you are using CSS Modules for now you need to import these files globally. (You can check the demo website Webpack config file).
4. Place sAlert component in you main app component
You need to place the main sAlert container. The best place for it is at the end of your main app component. For Example:
5. Make calls to activate alerts
You can activate your alerts in many different places in the app. You need to call proper methods. For Example:
Methods which you can use:
- Alert.warning(message, configObj)
- Alert.error(message, configObj)
- Alert.info(message, configObj)
- Alert.success(message, configObj)
- Alert.close(alertId)
- Alert.closeAll()
sAlert methods will return the already created alertId.
Example usage:
You always need to provide a message
. For example
You can also provide a react component:
You don't need to provide the configuration object here, just remember to provide it globally.