3.1.0 • Published 4 years ago

@opuscapita/react-alerts v3.1.0

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

react-alerts

Description

React alerts component to show global notifications.

Installation

npm install @opuscapita/react-alerts

Demo

View the DEMO

Builds

UMD

The default build with compiled styles in the .js file. Also minified version available in the lib/umd directory.

CommonJS/ES Module

You need to configure your module loader to use cjs or es fields of the package.json to use these module types. Also you need to configure sass loader, since all the styles are in sass format.

API

OCAlertsProvider

Prop nameTypeDefaultDescription
containerStyleobject{ bottom: '5px', maxWidth: '650px' }Override container default CSS styles

OCAlerts

Prop nameTypeDefaultDescription
containerStyleobject{ bottom: '5px', maxWidth: '650px' }Override container default CSS styles

OCAlert

FunctionParametersReturnsDescription
alertSuccessmessage, options, onDismissAlert Id: numberShow success alert
alertInfomessage, options, onDismissAlert Id: numberShow info alert
alertWarningmessage, options, onDismissAlert Id: numberShow warning alert
alertErrormessage, options, onDismissAlert Id: numberShow error alert
closeAlertidClose one alert with id
closeAlertsClose all alerts

Options

AttributesDescription
timeOutTime in milliseconds in which the alert is closed automatically.

Code example

Simple usage with built-in Redux store

Include the OCAlertsProvider component somewhere in your main component once.

import { OCAlertsProvider } from '@opuscapita/react-alerts';

<div id="myApp">
  <OCAlertsProvider />
</div>

Use alerts anywhere in your application.

import { OCAlert } from '@opuscapita/react-alerts';

// Message can be text or an react element
OCAlert.alertSuccess('The operation was success!');
OCAlert.alertInfo('Click the button to continue.');
OCAlert.alertWarning('Make sure you save the changes before leaving.');
OCAlert.alertError('Something went wrong.');
OCAlert.alertSuccess(<FormattedMessage id="AlertSuccess" />);
// Alerts can have custom timeout, after which the alert is closed
OCAlert.alertInfo('Alert will disappear in 3 seconds', { timeOut: 3000 });

OCAlert.closeAlert(id);
OCAlert.closeAlerts();

Usage with your own Redux store

Instead of using react-alerts' built-in Redux store, you can also use your own store. Like this:

import { OCAlert } from '@opuscapita/react-alerts';
OCAlert.setStore(yourStore)

After this you need to include OCAlerts component somewhere in your application (Note that we're not using the OCAlertsProvider like we did in the previous example)

import { OCAlerts } from '@opuscapita/react-alerts';

// ...

<div className="my-react-application">
  {this.props.children}
  <OCAlerts />
</div>

And lastly, you need to import and initialize the alertsReducer:

import { alertsReducer } from '@opuscapita/react-alerts';
import { combineReducers } from 'redux';

const combinedReducers = {
  // your reducers
  alerts: alertsReducer,
}
3.1.0

4 years ago

3.0.6

5 years ago

3.0.5

5 years ago

3.0.4

5 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.1

7 years ago

1.1.0

7 years ago