![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
react-modal-dialog
Advanced tools
Readme
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.
React modal dialog was built with a few fundamental assumptions and constraints in mind:
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.
class Button extends React.Component {
state = {
isShowingModal: false,
}
handleClick = () => this.setState({isShowingModal: true})
handleClose = () => this.setState({isShowingModal: false})
render() {
return <a onClick={this.handleClick}>
<span>Button Text</span>
{
this.state.isShowingModal &&
<ModalComponentHere onClose={this.handleClose}/>
}
</a>;
}
}
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.
import React, {PropTypes} from 'react';
import {ModalContainer, ModalDialog} from 'react-modal-dialog';
class View extends React.Component {
state = {
isShowingModal: false,
}
handleClick = () => this.setState({isShowingModal: true})
handleClose = () => this.setState({isShowingModal: false})
render() {
return <div onClick={this.handleClick}>
{
this.state.isShowingModal &&
<ModalContainer onClose={this.handleClose}>
<ModalDialog onClose={this.handleClose}>
<h1>Dialog Content</h1>
<p>More Content. Anything goes here</p>
</ModalDialog>
</ModalContainer>
}
</div>;
}
}
import React, {PropTypes} from 'react';
import {ModalContainer, ModalDialog} from 'react-modal-dialog';
import ReactSpinner from 'react-spinjs';
class View extends React.Component {
static propTypes = {
// This view takes a isLoading property
isLoading: PropTypes.bool,
}
state = {
isShowingModal: false,
}
handleClick = () => this.setState({isShowingModal: true})
handleClose = () => this.setState({isShowingModal: false})
render() {
const {
props: {
isLoading,
},
} = this;
return <div onClick={this.handleClick}>
{
this.state.isShowingModal &&
<ModalContainer onClose={this.handleClose}>
{
isLoading ?
<ReactSpinner/> :
<ModalDialog onClose={this.handleClose}>
<h1>Dialog Content</h1>
<p>More Content. Anything goes here</p>
</ModalDialog>
}
</ModalContainer>
}
</div>;
}
}
In version 1.0+, react-modal-dialog
relies on JSS and SVG to create all the styles and images.
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
.
Feel free to send pull requests, or help document this project more.
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
.
FAQs
A simple, idiomatic, and declarative way to launch modal dialogs in ReactJS
We found that react-modal-dialog demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.