Giter Site home page Giter Site logo

flavioespinoza / react-redux-modals Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nickjag/react-redux-modals

0.0 1.0 0.0 1.52 MB

React-Redux component-based modals system that support auto-layering.

Home Page: https://nickjag.github.io/react-redux-modals/

License: MIT License

HTML 4.96% JavaScript 89.13% CSS 5.90%

react-redux-modals's Introduction

react-redux-modals (demo)

React-Redux modals for drop-in modal support with components and auto-stacking.

Features

  • Use your own style (or copy the example css)
  • Use your own components as modals
  • Modals on top of modals (auto-layering/stacking)
  • Custom hooks/props for passing data
  • Separate DOM tree
  • Custom z-indexing
  • Control over individual modal closing methods
  • Fade-in transition option

Install

npm install --save react-redux-modals

Usage

Check out the demo in the example folder.

Step 1. Call ModalRoot with your store and add the resulting component to your root component.

Step 2. Pass in your modal components as a prop.

// ./index.js

import { ModalRoot } from 'react-redux-modals';
import * as modalComponents from './modal_components';

const ModalRootWithStore = ModalRoot(store);

const Root = () => (
  <div>
    <Provider store={store}>
      <App />
    </Provider>
    <ModalRootWithStore modalComponents={modalComponents} />
  </div>
);
// ./modal_components.js

import Signup from './components/modal/signup';
import Delete from './components/modals/delete';
import Terms from './components/modals/terms';

export const MODAL_SIGNUP = Signup;
export const MODAL_DELETE = Delete;
export const MODAL_TERMS = Terms;

Step 3. Add the modals reducer.

// ./reducers/index.js

import { reducer as modals } from 'react-redux-modals';

export default combineReducers({
  modals,
});

Step 4. Create your modal by using the Modal wrapper component. Add your own style.

// ./components/modals/delete.js

import Modal, { actions } from 'react-redux-modals';
import './modal.css';

class ModalDelete extends Component {

  render() {
    return (
      <Modal
        config={this.props.modalConfig} // required
        handleEscape={() => this.props.hideModal('MODAL_DELETE')} 
      >

        <div className="modal-body">
          <p>{`Are you sure you want to delete ${this.props.title}?`}</p>
          <button onClick={this.props.confirmDelete}>Yes</button>
          <button onClick={() => this.props.hideModal('MODAL_DELETE')}>No</button>
        </div>

      </Modal>
    );
  }
}

export default connect(
  null,
  { hideModal: actions.hideModal },
)(ModalDelete);

Step 5. Call your modal (with optional props).

// ./components/files.js

import { actions } from 'react-redux-modals';

class Files extends Component {

  render() {
    return (
      <div>
        <h3>My Files</h3>
        <div className="file">
          <label>{`File: ${filename}`}</label>
          <button onClick={() => this.props.showModal('MODAL_DELETE', {
            title: filename,
            confirmDelete: () => this.deleteFile(id)
          })}>
            delete
          </button>
        </div>
      </div>
    );
  }
}

export default connect(
  null,
  { showModal: actions.showModal },
)(Files);

Components

Component: Modal

Props:

Property Type Required Default Description
config object Required undefined Pass this.props.modalConfig (auto-injected).
handleEscape function Optional undefined Fires when clicking outside of modal.
animate boolean Optional false Adds a class of animate to the modal.
fadeIn boolean Optional true Uses the provided fadeIn animation if animate is true.

Component: ModalRootWithStore

Props:

Property Type Required Default Description
modalComponents object Required undefined Pass a module of your exported modal components.
config object Optional undefined Optionally pass a starting z-index.

Example of passing a starting z-index (defaults to 1000).

// ./index.js

<ModalRootWithStore
  modalComponents={modalComponents}
  config={{ zIndex: 5 }}
/>

Action Creators

Available action creators.

  • showModal(name, props)
  • hideModal(name)
  • resetModals()

License

MIT

react-redux-modals's People

Contributors

nickjag avatar

Watchers

James Cloos 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.