re-modal-ctx
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

Re Modal CTX

Latest Release

Introduction

re-modal-ctx controls the state of your React modal components using react context.

Installation

npm i --save re-modal-ctx

or

yarn add re-modal-ctx

Usage

1. Add <ModalProvider> to your root component.

import ModalProvider from 're-modal-ctx';

<>
  <App />
  <ModalProvider />
</>;

2. Add modal creation code.

// app.jsx
import { showModal } from 're-modal-ctx';
import { AwesomeModal } from './AwesomeModal';

export default (props) => (
  <div>
    <p>Hello world</p>
    <button
      type='button'
      onClick={() => showModal(AwesomeModal, { message: 'Hello' })}
    >
      Present modal
    </button>
  </div>
);

4. Handle modal closing.

// AwesomeModal.jsx
import { Modal } from 'react-bootstrap';

export const AwesomeModal = (props) => (
  <Modal show={props.show} onHide={props.hideModal}>
    <Modal.Body>{props.message}</Modal.Body>

    <Modal.Footer>
      <Button onClick={props.hideModal}>Ok</Button>
    </Modal.Footer>
  </Modal>
);

Implementations

StackableModalProvider (default)

This is the default ModalProvider implementation. Each new modal stacks up on top of previous one.

import { StackableModalProvider } from 're-modal-ctx';

<>
  <App />
  <StackableModalProvider />
</>;

SingleModalProvider

One modal at a time. Each new modal triggers hideModal on previous one.

import { SingleModalProvider } from 're-modal-ctx';

<>
  <App />
  <SingleModalProvider />
</>;

How is it different from react-redux-modal-provider?

  1. You don't need to install redux.

  2. TypeScript added.

  3. Implemented some bug fixes.

Acknowledgements

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i re-modal-ctx

Weekly Downloads

0

Version

1.0.7

License

MIT

Unpacked Size

36.6 kB

Total Files

55

Last publish

Collaborators

  • ivanodintsov