Last active
January 10, 2019 22:48
-
-
Save joshuarule/96ace8e5aac6d4e976f7f62525bb1e27 to your computer and use it in GitHub Desktop.
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
import React, { Component, Fragment } from 'react'; | |
import ReactDOM from 'react-dom' | |
const modalRoot = document.getElementById('modal-root') | |
export default class Modal extends Component { | |
render() { | |
const {isVisible} = this.props | |
return ReactDOM.createPortal( | |
<Fragment> | |
<div className={isVisible ? `modal--container modal--show` : `modal--container`}> | |
<div className='modal--background' onClick={this.props.onClose} /> | |
<div className='modal--content'> | |
<div className='modal--header'> | |
<h1 className='modal--title'>{this.props.title}</h1><button className='modal--close' onClick={this.props.onClose} ></button> | |
</div> | |
{this.props.children} | |
</div> | |
</div> | |
</Fragment>, | |
modalRoot | |
) | |
} | |
} | |
// use case | |
<Modal | |
onClose={this.handleClosePlayerModal} | |
isVisible={this.state.showPlayerModal} | |
title={``} | |
> | |
// content | |
</Modal> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment