react-modal-dom
Lightweight and customizable react modal
We do not limit you with html markup. You can create responsive modal windows of absolutely any format and manage them from anywhere in your react application.
Installation
npm i react-modal-dom# oryarn add react-modal-dom
Demo
Check out the demo here https://react-modal-dom.netlify.app/

Usage
Step 1 - add "ModalComponent" into your index.js file.
Note!
Use only one 'ModalComponent' component in the app.
;;; ; ReactDOM;
Step 2 - create your custom modal window
const MyModal = { return <div className='modal'> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit</p> </div> ;}; ;
What you will get:

Step 3 - use css to create styles for your modal
/* example */
What you will get:

modal
obj methods to close or open your modal window
Step 4 - use ;; ; const MyApp = { const handleOpenModal = { modal } return <> <button type="button" onClick=handleOpenModal> Open modal </button> <button type="button" onClick=modalclose> Close modal </button> </> ;}; ;
modal object
This object has only 2 methods: close
and open
modalmodal
<CustomModal />
- valid react component. Use only jsx sintaxis
callback
- provide callback that will call immediately after your modal close or open
Use modal obj methods even in your redux actions
; const myAction = async { ; try ... ; // close modal here modal;
; { try ... ; // close modal here modal;
Create function to open your custom modal in redux files
; const MyModal = { return <div className='modal'> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit</p> </div> ;}; const openMyModal = { modal} ;
; const myAction = async { ; try ... ; // open your custom modal ;
; { try ... ; // open your custom modal ;
Customize modal backdrop with css
Just write some styles for class .react-modal-backdrop
. Your styles will be prioritized over library styles.
/* example */
What you will get:

Use with reacr-router-dom
By default, the modal does not close when the route is changed. To fix this you need to write this code in your App.js component.
;; { const pathname = thispropslocation; if locationpathname !== pathname modal; }App; // or with hooks ;; const App = { const history = ; history;...
TODO
- Animations
- Write tests
- TypeScript
- Close modals on route change
- Other