Giter Club home page Giter Club logo

redux-dialog's Introduction

Travis NPM

redux-dialog

A Higher Order Component using react-redux to keep dialog state in a Redux store.

Using in your project

The easiest way to use redux-dialog is to install it from NPM and include it in your own React build process

npm install --save react react-dom react-modal redux react-redux redux-dialog

or use yarn

yarn add --save react react-dom react-modal redux react-redux redux-dialog

Usage

The first step is to combine the redux-dialog reducer with your own application reducers

Step 1

import { createStore, combineReducers } from "redux";
import { dialogReducer } from "redux-dialog";
const reducers = {
  // Other reducers here
  dialogReducer
};
const reducer = combineReducers(reducers);
const store = createStore(reducer);

Step 2

Decorate your component with reduxDialog.

import reduxDialog from "redux-dialog";

const BasicDialog = () => <div>My awesome modalbox!</div>;

const Dialog = reduxDialog({
  name: "Sign up dialog" // unique name - you can't have two dialogs with the same name (will be used as aria-label as well)
})(BasicDialog);

Step 3

Use redux-dialog's actions to show and hide the dialog

import { openDialog, closeDialog } from "redux-dialog";
const MyComponent = () => (
  <a href="#" onClick={() => dispatch(openDialog("Sign up dialog"))} />
);

Options

The reduxDialog method only requires the name property to work. The rest of the optional properties can be Any valid react-modal options.

name: string

A unique id for this dialog

Passing a payload to the modal

When dispatching the action to open the dialog, adding a payload as the second parameter to openDialog will be available within the dialog as the payload property.

dispatch(openDialog('accountDialog', { accountName: 'My Account' }));

const BasicDialog = ({ payload }) => (
  <div>
    { payload.accountName }
  </div>
  <div>
    My awesome modalbox!
  </div>
)

Working on the source code

Clone this repo then run:

yarn install
yarn start

Then open http://localhost:8080 to see a working example.

Building a release

yarn build should do the trick.

Tests

yarn run test

redux-dialog's People

Contributors

alexicum avatar jakedluhy avatar kendagriff avatar negomi avatar pawelniewie avatar suciuvlad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

redux-dialog's Issues

How do I style this dialog?

I love this component. It was really easy to set up. My question is can I provide class names to style this component with css and not a javascript object?

Can we add a closeAll method?

I have a need in my current project to close the dialogs when the route changes (for example). I can do it by getting the opened dialog from the state and dispatch a closeDialog() action.

My question is, can we add a closeAll method for this library or this is something each application should on their side?

Option to pass in properties when dispatching the action

I was wondering what your thoughts are on adding the option to pass in properties to a modal when dispatching the action to open it. We have a case where the information within the modal is contextual to the previous event.

Added a PR for it as well =)

OPEN_DIALOG action fired twice

Firstly, thanks for this component!

I noticed that it dispatches openDialog in the onAfterOpen callback, which results in a second dispatch:

screen shot 2017-05-22 at 2 45 33 pm

As onAfterOpen is called after opening, we don't need to dispatch the action again here. This is the problematic line: https://github.com/suciuvlad/redux-dialog/blob/master/src/redux-dialog.js#L34

As well as a redundant dispatch, this also breaks react-modal's body class functionality, ReactModal__Body--open. If I comment out the line in question, a single action is dispatched and that body class is applied as expected. But with this current design, the body class gets removed with the second action.

Could you remove the line? I started to make a PR but the build came out differently (I'm guessing due to dependency versioning) so I thought you might want to check that out first :)

Redux 4

Any chance you could change the peer dependency to include redux 4?

"redux": "^3.5.2 || ^4.0.0-0"
while you are there could update these
``
react-redux 5.0.7
react-modal 3.5.1

``

Publish to npm please

The last version published was 0.9 from 8 months ago.
Can you please publish your latest code?

New release

Hi,

is there any chance for an update to the newest react or is this project abandoned :( ?

Test coverage?

Any ideas on how to test this?
Since this project is fairly small, I was hoping to use it as a guideline on how to test an HOC at a small scale.

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.