npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-redux-modal-flex

v2.0.3

Published

Make easy a modal/popup with Redux

Downloads

9

Readme

[DEPRECATED] REACT-REDUX-MODAL-FLEX

NPM version NPM monthly download

Make easy a modal/popup with Redux.

:warning: This will work only with React 16.3+ :warning:

If you're looking for a version for React 16.2 (for individual pages) use 1.x branch branch.

Demo

https://react-redux-modal-flex.netlify.com

Features

Installation

To install the stable version you can use:

$ yarn add react-redux-modal-flex

Example

Step 1:

rootReducer.js

import { combineReducers } from "redux";
import { reducer as modal } from "react-redux-modal-flex";
import todos from "./todos";

export default combineReducers({
  todos,
  modal: modal({
    classContent: "modal-content",
    animation: "zoomIn",
    duration: 200,
    mask: true,
    /* initial state, see API reference */
  }),
});

Step 2:

App.js

import Modal from "react-redux-modal-flex";

class App extends React.Component {
  render() {
    return (
      <Router>
        <div className="App">
          <Switch>
            <Route path="/" exact component={Home} />
            <Route path="/auth" component={Auth} />
          </Switch>
          <Modal />
        </div>
      </Router>
    );
  }
}

Step 3:

Any Container you want to use

import { connect } from "react-redux";
import { actions as ModalActions } from "react-redux-modal-flex";

class LoginModal extends React.Component {
  render() {
    return (
      <form>
        <div>
          <label>Username</label>
          <input type="text" name="username" />
        </div>
        <div>
          <label>Password</label>
          <input type="password" name="password" />
        </div>
      </form>
    );
  }
}

class Auth extends React.Component {
  render() {
    return (
      <div>
        <h3>Auth</h3>
        <button
          onClick={() =>
            this.props.toggleModal({
              component: LoginModal,
              ok: {
                text: "Login",
                action: () => alert("submit form"),
              },
            })
          }
        >
          Open modal login
        </button>
      </div>
    );
  }
}

export default connect(null, { toggleModal: ModalActions.toggleModal })(Auth);

API

  • initState: you can overwrite default initial state
const initState = {
  classContent: "modal-content",
  animation: "zoomIn",
  duration: 300,
  mask: true,
  closeByMask: true,
  component: ModalDefault,
  title: "This is a title",
  closeBtn: true,
  textCancel: "Cancel",
  ok: {
    text: "OK",
    classOk: "modal-btn-ok",
    disabled: false,
    action: () => console.log("OK clicked"),
  },
};
  • API
import Modal, {
  reducer as modal,
  actions as ModalActions,
} from "react-redux-modal-flex";
const { toggleModal, modifyOkModal } = ModalActions;
  • <Modal /> is component, using in our App.js
  • reducer using in our rootReducer.js you can custom default initial state
export default combineReducers({
  todos,
  modal: modal({
    textCancel: "Close",
    title: "My default title",
  }),
});
  • toggleModal and modifyOkModal is action

Usage

  • Open Modal by action toggleModal(options)
    • options: is object and look like the initState above
    • Example:
...
render() {
  return (
    <button onClick={() => this.props.toggleModal({
      textCancel: 'Hide',
      component: () => <div>content modal</div>,
      title: 'My title',
      ok: {
        text: 'Login',
        action: () => alert('click OK')
      }
    })}>Click me</button>
  );
}
...
  • Close Modal toggleModal(false) or any value excepted object
  • Modify button OK: modifyOkModal(options) usage like toggleModal
    • Example:
onClick={() => this.props.modifyOkModal({
  text: 'Sign up',
  disabled: true
})}
  • Hide Header if the title is null
  • Hide Cancel button if the textCancel is null
  • Hide Ok button if ok: {text: null}
  • Hide Footer if the Cancel and Ok are hidden

License

MIT