1.0.10 • Published 5 years ago

react-chained-modals v1.0.10

Weekly downloads
46
License
-
Repository
-
Last release
5 years ago

React chained modals Tweet

React version

Allow you to add few chained modals or just single popup in your react app. Easy to use and customizing. Check the demo page

screencast-amodin github io-2018 12 09-21-00-37

Getting Started

Installation

Get the package from npm

npm i react-chained-modals

Usage

Import:

import ChainedModal from "react-chained-modals";
import "react-chained-modals/src/modal.css"
import "animate.css"

then place:

<ChainedModal
  animationNext="fadeInRight"
  animationPrev="fadeInLeft"
  visible={this.state.showModal}
  onRequestClose={this.toggleModal}
  closeOnBackground
  animationSpeed="faster"
  elements={[
   {
     component: Modal1,
     props: { title: "First modal" }
   },
   {
     component: Modal2,
     props: { title: "Second modal" }
   },
   {
     component: Modal3,
     props: { title: "Third modal" }
   }
 ]}
/>

Methods and options

NameTypeDescriptionDefault
animationNextstringTransition animation on showNext method call. View full list here Animate.css. This method will call also on popup first view.none
animationPrevstringTransition animation on showPrev method call. View full list here Animate.cssnone
visibleboolIs modals visible. Options: true, falsefalse
onRequestClosefunctionMethod that should set visible to false
closeOnBackgroundboolShould popup close on click at background. Options: true, falsefalse
animationSpeedstringDefine it if you want to change the animation speed. Options: "slow", "slower", "fast", "faster"none
elementsarrayEach item in the array should have the component that will show and optional parameter props which put all 'props' you want to use in this componentnone

Methods and options for each modal

In each component, that you added in elements you can get next next properties and methods from props:

NameTypeDescription
closeChainedModalfunctionThe onRequestClose function will be called
totalModalsnumberNumber of modals, length of array
showNextfunctionShow next modal function
showPrevfunctionShow prev modal function
currentModalnumberCurrent modal, index in array

Example of Modal1 component:

const Modal1 = props => {
  return (
    <div>
      {props.title} {props.currentModal}
      <div>{props.totalModals}</div>
      <div>
        <span onClick={props.showPrev()}>Go prev </span>
        <span onClick={props.showNext()}>Go next</span>
      </div>
      <button onClick={() => props.closeChainedModal()}>close modal</button>
    </div>
  );
};

Customizing:

Just replace your styles with styles from the module

Built With

1.0.10

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago