GithubHelp home page GithubHelp logo

claydiffrient / redux-flash-notification Goto Github PK

View Code? Open in Web Editor NEW

This project forked from posabsolute/redux-flash-notification

0.0 2.0 0.0 25 KB

An es6 growl notification plugin for redux

License: MIT License

JavaScript 85.40% CSS 14.60%

redux-flash-notification's Introduction

Redux Flash Notification Component for Redux

An es6 growl-like notification plugin for react and redux.

Demo: Live Example | Source

Better Documentation: http://posabsolute.github.io/redux-flash-notification

Integration

1 npm install 'flash-notification-react-redux' --save

2 Add redux-thunk middleware

npm install 'redux-thunk' --save
 import reduxThunk from 'redux-thunk'

 const createStoreWithMiddleware = applyMiddleware(reduxThunk)(createStore);
 const store = createStoreWithMiddleware()

3 Add the reducer to your root reducer

import { GrowlerReducer } from 'flash-notification-react-redux';

const rootReducer = combineReducers({
  growler: GrowlerReducer,
});

export default rootReducer;

4 Add the growler component to your app root component so it is always accessible

import { GrowlerContainer } from 'flash-notification-react-redux';

export class App extends Component {
  static propTypes = {
    children: React.PropTypes.any,
  }
  render() {
    return (
      <section>
        <GrowlerContainer />
        {this.props.children}
      </section>
    );
  }
}

5 Add webpack loaders to load es6 files.

  module: {
    loaders: [{
      test:[/\.jsx$/,  /\.js$/],
      loader: 'babel',
      query: {
        plugins: ['transform-decorators-legacy']
      },
      include: [
        path.resolve(__dirname, "src"),
        path.resolve(__dirname, "node_modules/flash-notification-react-redux")
      ],
    }, {
      test: [/\.scss$/, /\.css$/],
      loader: 'css?localIdentName=[path]!postcss-loader!sass',
    }],
  },
};

6 You're done.

Usage

With the reducer

You can change the store state to show the growler.

Example:

dispatch({
  type: 'GROWLER__SHOW',
  growler: {
    text: 'Please enter your JIRA url',
    type: 'growler--error',
  },
});
dispatch({
  type: 'GROWLER__SHOW',
  growler: {
    text: 'You have succesfully logged in',
    type: 'growler--success',
  },
});

With the actions

If made available in your components, you can use multiple actions to show the growler component,

Example:

import React from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import {GrowlerActions} from 'actions/sprints.action';

const mapStateToProps = state => ({});
const mapDispatchToProps = dispatch => {
  return {
    ...bindActionCreators(growlerActions, dispatch),
  };
};

@connect(mapStateToProps, mapDispatchToProps)
export default class SprintsListContainer extends React.Component {
  render() {
    return <SprintsListComponent {...this.props} />;
  }
}

Available Actions

showGrowlerSuccess(text)

showGrowlerError(text)

showGrowler(text, type)

Used when you want to show custom messages. The type will be added as a CSS class.

Options

Options are passed down when you add the component to your app root.

Option Default Value Default Value Description
shownFor 3000 Milliseconds Time the growler is shown
messages - Object Localization in every supported languages of your messages
currentLocale enUS String Locale used to retrieve messages
import { GrowlerContainer } from 'flash-notification-react-redux';
import growlerMessages from 'locales/growler.locale.js';

export class App extends Component {
  render() {
    return (
      <section>
        <GrowlerContainer messages={growlerMessages} currentLocale='enUS' shownFor="9000" />
        {this.props.children}
      </section>
    );
  }
}

Messages

By default the growler will show the text passed down by the action, however when mounting the component you can specify localized text. When shown, the component will verify if the text passed match a key.

import { GrowlerContainer } from 'flash-notification-react-redux';
import growlerMessages from 'locales/growler.locale.js';

// usage in render
<GrowlerContainer messages={growlerMessages} currentLocale='enUS' />

currentLocale (default: enUS)

You can specify the language used by using the currentLocale option.

Messages object Example

{
  enUS: {
    error: 'There was en error'
  },
  frCA: 
     error: 'Il y a eu une erreur'
}

shownFor (default: 3000)

Time the growler is shown in milliseconds

<GrowlerContainer shownFor="6000" />

Limitations

This component is based on the use of redux, react, es6 & es7 (decorators) and webpack for loading the css as an import module.

redux-flash-notification's People

Contributors

posabsolute avatar dawnywu avatar chriscarr avatar masad-frost avatar

Watchers

Clay Diffrient avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.