2.0.0 • Published 4 years ago

react-modal-controller v2.0.0

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

react-modal-controller

It helps you to manage any of your modals from anywhere in your code.

  • React hooks
  • Light
  • Easy to fork

How to use

Just wrap your app into ModalsProvider and setup initial modals:

//App.jsx/tsx
import { ModalsProvider } from 'react-modal-controller';
import modals from './modals';
...
    <ModalsProvider initialModals={modals}>
        <Layout>
            <Switch>
                <Route path="/" exact>
                    <MainPageContainer />
                </Route>
            </Switch
        </Layout>
    </ModalsProvider>
// modals.jsx/tsx
import SignInModal from './SignInModal';
export default {
    SIGN_IN: SignInModal,
}
//SignInModal.jsx/tsx (Example with @material-ui Dialog)
import { Dialog } from '@material-ui/core';
import { useModals } from 'react-modal-controller';
...
const SignInModal = (props) => {
    const { closeModal } = useModals();
    const { anyProp } = props;
    return (
        <Dialog onClose={() => closeModal('SIGN_IN')} open>
            Some modal content
            { anyProp }
        </Dialog>
    );
}
export default SignInModal;

Then just open modals from enywhere

//HomePage.jsx/tsx
import { useModals } from 'react-modal-controller';
...

const HomePage = () => {
  const { openModal } = useModals();
  return (
      <div>
          <Button onClick={() => openModal('SIGN_IN', { anyProp: 'value' })}>
            Sign In
          </Button>
      </div>
  );
};

Installation

$ npm install --save react-modal-controller

API

openModal(<model_key>) Open any of specified modals

closeModal() Close all modals

closeModal(<modal_key>) Close modal with specific key

2.0.0

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.3

4 years ago

1.0.0

4 years ago