-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6ac4c7
commit 437a565
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from "react"; | ||
import * as ReactDOM from "react-dom"; | ||
|
||
export default class ModalPortal extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.portalElement = null; | ||
} | ||
|
||
componentDidMount() { | ||
var p = document.createElement('div'); | ||
p.id = this.props.portalId; | ||
document.body.appendChild(p); | ||
|
||
this.portalElement = p; | ||
|
||
this.componentDidUpdate(); | ||
} | ||
|
||
componentWillUnmount() { | ||
document.body.removeChild(this.portalElement); | ||
ReactDOM.unmountComponentAtNode(this.portalElement) | ||
} | ||
|
||
componentDidUpdate() { | ||
ReactDOM.render( | ||
<React.Fragment>{this.props.children}</React.Fragment>, | ||
this.portalElement | ||
); | ||
} | ||
|
||
render() { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from "react"; | ||
import ModalPortal from "./ModalPortal"; | ||
import Modal from "./Modal"; | ||
|
||
export default class MountedModal extends React.Component { | ||
render() { | ||
if (this.props.show === false) { | ||
return null; | ||
} | ||
|
||
return <ModalPortal portalId="react-modal-container"> | ||
<Modal style={{display: 'block'}} className="in"> | ||
{this.props.children} | ||
</Modal> | ||
|
||
<div className="modal__backdrop in" /> | ||
</ModalPortal> | ||
} | ||
} |