1.0.2 • Published 5 years ago

minimal-react-modal v1.0.2

Weekly downloads
8
License
MIT
Repository
github
Last release
5 years ago

minimal-react-modal

A minimalistic react modal component.

Installation

npm i minimal-react-modal

Usage

The bare minimal usage of this library is as follows:

import * as React from 'react';
import {ModalContainer, Modal} from 'minimal-react-modal';

React.render(
  <ModalContainer>
    {(openModal, closeModal, isActive) => (
      <div>
        <button onClick={openModal}>click me!</button>
        <Modal
          isActive={isActive}     // required
          closeModal={closeModal} // required
        >
          <h1>modal content</h1>
        </Modal>
      </div>
    )}
  </ModalContainer>
);

demo_minimal

ModalContainer

The area where you can call the open/close functions (openModal / closeModal) and access the modal's state (isActive).

Props

propNametyperequireddefaultdescription
activeOnLoadbooleanxfalsewhether the modal should be active on load

Modal

The modal component itself. You must pass the close function (closeModal) and the modal status (isActive) provided by the parent ModalContainer component as props.

Props

propNametyperequireddefaultdescription
isActivebooleano-(provided by ModalContainer)
closeModal() => voido-(provided by ModalContainer)
classNamestringxnullclassname(s) to append to the modal box
showCloseButtonbooleanxfalsewhether to show the close button on the top right corner
showAnimationbooleanxfalsewhether to animate modal opening
modalBoxStyleReact.CSSPropertiesx{}overrides modal styles
closeButtonStyleReact.CSSPropertiesx{}overrides default close button style (make sure showCloseButton is true)
overlayStyleReact.CSSPropertiesx{}overrides modal background overlay style

Here is another demo utilizing these optional props:

<ModalContainer>
  {(openModal, closeModal, isActive) => (
    <>
      <button onClick={openModal}>click me!</button>
      <Modal
        isActive={isActive}     // required
        closeModal={closeModal} // required
        className="demo"
        showCloseButton={true}
        showAnimation={true}
        modalBoxStyle={{
          width: 500,
          height: 300,
          padding: 30,
        }}
      >
        <h1>modal content</h1>
      </Modal>
    </>
  )}
</ModalContainer>

demo