2.0.1 • Published 1 year ago

nested-modal v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

nested-modal (React) · GitHub license PRs Welcome

⚡️ Code Sandbox Interactive Example ⚡️

Nested Modal is a component that helps manage lots of modals shown at the same time.

  • Easy to use: Very easy to create all the modals you need by just wrapping the content nodes with the Nested Modal wrapper.
  • Full Control: Abstracts only the main parts, you can fully control visiblity with ids and callbacks.

Installation

npm install nested-modal

Documentation

We are still working on some proper docs.

Examples

Main example:

  • Use a useState hook to control Visibility.
  • Each node added will be a modal.
  • Ids have to be unique.
import { NestedModal, ModalChild } from "nested-modal";

interface Props {
  currentOpenedModal: string;
  setCurrentOpenedModal: (modalId: string) => void;
}

export const NestedModalTest = ({
  currentOpenedModal,
  setCurrentOpenedModal
}: Props) => {
  return (
    <NestedModal
      currentOpenedModal={currentOpenedModal}
      setCurrentOpenedModal={setCurrentOpenedModal}
    >
      <ModalChild
        id="first-modal"
        title="Nice! This is the first modal in the row (and this is the title hihi)"
      >
        <button onClick={() => setCurrentOpenedModal("third-modal")}>
          Click here to launch the third modal
        </button>
      </ModalChild>
      <ModalChild
        id="second-modal"
        title="Second modal title hehe"
        onClose={async () => {
          if (
            window.confirm(
              "You won't be able to close the second one if you don't return true in the async callback. This is to prevent losing data such as form data. Confirm dialog if you want to close this modal."
            )
          ) {
            return true;
          }
          return false;
        }}
      >
        Now you are on the second modal. Try closing this one!
      </ModalChild>
      <ModalChild id="third-modal" title="Third modal title">
        The content of the third modal is here. If you hover on the left you
        will also see the second modal was opened because it was declared before
        the third one. Click on it to go there or close this one by hitting the
        back button.
      </ModalChild>
    </NestedModal>
  );
};

Contributing

I made this package just for fun. Anyone who would like to contribute is welcomed to open PR's or post suggestions/issues.

Development

In order to work on this package you need to follow these steps:

  1. Create a react project. e.g. with CRA
  2. In nested-modal create a link: npm link
  3. Go to your project and link nested-modal with your project: npm link nested-modal
  4. One last thing, you need to link your projects react copy in the nested-modal codebase: npm link ../path-to-my-cra-project/node_modules/react
  • Before opening a pr please undo the last step as it will break the packge release workflow. npm unlink ../path-to-my-cra-project/node_modules/react

Code of Conduct

We will be using Facebook code of conduct. Please read the full text so that you can understand what actions will and will not be tolerated.

License

Nested Modal is MIT licensed.

1.0.0

1 year ago

0.3.0

1 year ago

2.0.1

1 year ago

2.1.0

1 year ago

2.0.0

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago