A Pen by hiroaki tachibana on CodePen.
Created
August 5, 2018 00:49
-
-
Save superposition/b0d883861bbe6663d2b9eea4384681c8 to your computer and use it in GitHub Desktop.
react-modal sample
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
<div id="main"> | |
</div> |
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
class ExampleApp extends React.Component { | |
constructor () { | |
super(); | |
this.state = { | |
showModal: false | |
}; | |
this.handleOpenModal = this.handleOpenModal.bind(this); | |
this.handleCloseModal = this.handleCloseModal.bind(this); | |
} | |
handleOpenModal () { | |
this.setState({ showModal: true }); | |
} | |
handleCloseModal () { | |
this.setState({ showModal: false }); | |
} | |
render () { | |
return ( | |
<div> | |
<button onClick={this.handleOpenModal}>Trigger Modal</button> | |
<ReactModal | |
isOpen={this.state.showModal} | |
contentLabel="Minimal Modal Example" | |
className="Modal" | |
overlayClassName="Overlay" | |
onRequestClose={this.handleCloseModal} | |
> | |
<div>モーダル</div> | |
<button onClick={this.handleCloseModal}>Close Modal</button> | |
</ReactModal> | |
</div> | |
); | |
} | |
} | |
const props = {}; | |
ReactDOM.render(<ExampleApp {...props} />, document.getElementById('main')) |
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react-dom.min.js"></script> | |
<script src="https://unpkg.com/[email protected]/dist/react-modal.min.js"></script> |
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
.Modal { | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
display: block; | |
padding: 2em; | |
min-width: 20em; | |
max-width: 70%; | |
color: #f00; | |
background-color: #fff; | |
border-radius: 1em; | |
transform: translate(-50%, -50%); | |
outline: transparent; | |
} | |
.Overlay { | |
position: fixed; | |
top: 0; | |
right: 0; | |
bottom: 0; | |
left: 0; | |
background-color: rgba(0,0,0,.4); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment