Installations
npm install boss-react-modal-dialog
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
7.8.0
NPM Version
4.2.0
Score
46.1
Supply Chain
87
Quality
73.3
Maintenance
25
Vulnerability
98.9
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (93.94%)
CSS (5.19%)
Shell (0.87%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
1,237
Last Day
2
Last Week
4
Last Month
18
Last Year
113
GitHub Statistics
MIT License
104 Commits
1 Forks
3 Watchers
4 Branches
3 Contributors
Updated on Jun 08, 2017
Bundle Size
161.55 kB
Minified
50.47 kB
Minified + Gzipped
Package Meta Information
Latest Version
4.0.7
Package Id
boss-react-modal-dialog@4.0.7
Size
33.56 kB
NPM Version
4.2.0
Node Version
7.8.0
Total Downloads
Cumulative downloads
Total Downloads
1,237
Last Day
100%
2
Compared to previous day
Last Week
0%
4
Compared to previous week
Last Month
38.5%
18
Compared to previous month
Last Year
-32.7%
113
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
8
Peer Dependencies
3
Dev Dependencies
2
React Modal Dialog
React modal dialog is an idiomatic way to represent modal dialogs in react. It is nested inside the components that require them, and can themselves nest other dialogs. There are no global switches or state, and the contents of the dialog are defined where you need it.
Design Considerations
React modal dialog was built with a few fundamental assumptions and constraints in mind:
- When you have two dialogs, the ESC key will only close the top level one (there is an event manager implemented like a stack)
- The package needs to support dialogs that bounce in with a spring animation (not just standard ease-in, ease-out), but still be flexible enough for other designs
- Dialogs that are too long will scroll in their viewport
- Dialogs need to be able to show a loading spinner, that means the background and the content need to be separate components
Idiomatic Syntax
From the very beginning, the goal was a syntax very similar to the one below, where the modal component is held within a button or the view with the closest common ancestor of two buttons.
1class Button extends React.Component { 2 state = { 3 isShowingModal: false, 4 } 5 handleClick = () => this.setState({isShowingModal: true}) 6 handleClose = () => this.setState({isShowingModal: false}) 7 render() { 8 return <a onClick={this.handleClick}> 9 <span>Button Text</span> 10 { 11 this.state.isShowingModal && 12 <ModalComponentHere onClose={this.handleClose}/> 13 } 14 </a>; 15 } 16}
Actual Usage
This is how react-modal-dialog works. You can create a component that wraps ModalContainer and ModalDialog into one CustomDialog, but the reason I have separated is so that I can add a loading spinner above the background but below the dialog.
1import React from 'react'; 2import PropTypes from 'prop-types'; 3import {ModalContainer, ModalDialog} from 'react-modal-dialog'; 4 5class View extends React.Component { 6 state = { 7 isShowingModal: false, 8 } 9 handleClick = () => this.setState({isShowingModal: true}) 10 handleClose = () => this.setState({isShowingModal: false}) 11 render() { 12 return <div onClick={this.handleClick}> 13 { 14 this.state.isShowingModal && 15 <ModalContainer onClose={this.handleClose}> 16 <ModalDialog onClose={this.handleClose}> 17 <h1>Dialog Content</h1> 18 <p>More Content. Anything goes here</p> 19 </ModalDialog> 20 </ModalContainer> 21 } 22 </div>; 23 } 24}
Loading Spinners
1import React from 'react'; 2import PropTypes from 'prop-types'; 3import {ModalContainer, ModalDialog} from 'react-modal-dialog'; 4import ReactSpinner from 'react-spinjs'; 5 6class View extends React.Component { 7 static propTypes = { 8 // This view takes a isLoading property 9 isLoading: PropTypes.bool, 10 } 11 state = { 12 isShowingModal: false, 13 } 14 handleClick = () => this.setState({isShowingModal: true}) 15 handleClose = () => this.setState({isShowingModal: false}) 16 render() { 17 const { 18 props: { 19 isLoading, 20 }, 21 } = this; 22 23 return <div onClick={this.handleClick}> 24 { 25 this.state.isShowingModal && 26 <ModalContainer onClose={this.handleClose}> 27 { 28 isLoading ? 29 <ReactSpinner/> : 30 <ModalDialog onClose={this.handleClose}> 31 <h1>Dialog Content</h1> 32 <p>More Content. Anything goes here</p> 33 </ModalDialog> 34 } 35 </ModalContainer> 36 } 37 </div>; 38 } 39}
Styles (CSS and Images)
In version 4.0+ react-modal-dialog has finally shifted to using narcissus, narcissus makes inline css styles sane, and also works in pure javascript so you don't have to spend time requiring css files awkwardly with NPM and packaging them in webpack with custom loaders yourself.
For a similar reason of not having to deal with external dependencies or awkward loaders/hacked require statements, starting in 4.0+, react-modal-dialog uses hand-written svg for the one "image" that comes with the package, the close button.
For Your Own Implementation
For now, I recommend you check out the source code of this project, as it is quite simple, to really get an understanding of how this dialog works. I've spent a lot of time trying many paradigms (you can read about all that here), and I've settled on this one for good reasons.
The hardest part about dialogs is their architecture, not the UI or specific implementation. Feel free to swap out your own ModalDialog class into my existing ModalContainer, or disassemble ModalContainer into your own portal and background class.
To get the esc key to only close the top dialog when there are two modal dialogs, I employed the use of an event controller. However, you may find this to be peculiar or you may want to attach your dialogs to your own event controller. If that's true, you may want to branch this project to edit the code in componentDidMount
and componentWillUnmount
of ModalPortal
.
Contributing
Feel free to send pull requests, or help document this project more.
A Note on package.json
package.json points to src/index.js
, so that it is easy to develop against. However, this folder does not exist in the npm distribution, so the whole thing falls back to the /index.js
at the root, which points to the compiled /lib/index.js
.

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
45 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-hr2v-3952-633q
- Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-xf7w-r453-m56c
- Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq
- Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm
- Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-hxm2-r34f-qmc5
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-566m-qj78-rww5
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-6g33-f262-xjp4
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-2m39-62fm-q8r3
- Warn: Project is vulnerable to: GHSA-mf6x-7mm4-x2g7
- Warn: Project is vulnerable to: GHSA-j44m-qm6p-hp7m
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-g7q5-pjjr-gqvp
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
Score
1.7
/10
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More