0.2.1 • Published 2 years ago

modern-react-modal v0.2.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Modern React Modal

A lightweight and customisable Modal component for modern React apps

Installation

Using npm

npm install modern-react-modal

Using yarn

yarn add modern-react-modal

Usage

import { Modal, ModalBody, ModalHeader, ModalFooter } from "modern-react-modal";
import { useState } from "react";

const MyComponent = (props) => {
  const [show, setShow] = useState(false);

  const onClose = () => {
    setShow(false);
  };

  return (
    <div>
      <button onClick={() => setShow(true)}>Subscribe to Newsletter</button>
      <Modal show={show} onClose={onClose}>
        <ModalHeader>
          <h2>Subscribe To Newsletter</h2>
        </ModalHeader>
        <ModalBody>
          <p>Enter email in which you want to receive updates</p>
          <input placeholder="Enter email" />
        </ModalBody>
        <ModalFooter>
          <button onClick={onClose}>Close</button>
          <button>Subscribe</button>
        </ModalFooter>
      </Modal>
    </div>
  );
};

Props

Modal

PropDescriptionValueRequired
showDetermines whether to show the modalbooleanYes
onCloseFunction called when modal is closedFunctionYes
sizeDetermines size of modalsm or md or lg or xl or fullscreenNo
clickOverlayToCloseIf true,the modal closes when overlay is clickedbooleanNo
blurOverlayIf true, blur filter is applied to overlaybooleanNo
scrollContentIf true, then modal maintains a fixed height in case of content overflow. The modal body becomes scrollable. If false, then modal assumes entire height of content and the overlay is scrollablebooleanNo
animationDetermines the entry animation of the modalfade or slideNo

ModalHeader

PropDescriptionValueRequired
classNameCustom classname applied to the header componentstringNo

ModalBody

PropDescriptionValueRequired
classNameCustom classname applied to the body componentstringNo

ModalFooter

PropDescriptionValueRequired
classNameCustom classname applied to the footer componentstringNo