react-popper-modal
v0.1.2
Published
This component adds a modal dialog to your react project.
Downloads
4
Readme
React Popper Modal
This component adds a modal dialog to your react project.
Usage
The modal is divided into three components:
- ModalHeader - displays the header contents of the modal
- ModalBody - displays the body contents of the modal
- ModalFooter - displays the footer contents of the modal
import React, { useState } from 'react';
import {Modal, ModalHeader, ModalBody, ModalFooter } from 'react-popper-modal';
const App = () => {
const [showModal, setShowModal] = useState(false);
return (
<>
<button onClick={() => setShowModal(true)}>Open Modal</button>
<Modal showModal={showModal} onClose={() => setShowModal(false)} centerVertically={true}>
<ModalHeader styles={{textAlign: "center"}}>
<button onClick={() => setShowModal(false)}>Close</button>
</ModalHeader>
<ModalBody>
<h2>Modal</h2>
<p>
Body content
</p>
</ModalBody>
<ModalFooter>
<p>
Footer content
</p>
</ModalFooter>
</Modal>
</>)
}
Breakdown
As shown in the component above, the modal contents are wrapped in a the "Modal" component.
This component takes in props:
- className - for adding custom styles
- styles - for adding custom styles as objects
- showModal - takes in a boolean that shows the modal when true.
- onClose - tales in a function that is called when the modal is being closed.
The child components also support syle customizations via props:
- className
- styles
Happy hacking!