Skip to content

Instantly share code, notes, and snippets.

@superposition
Created August 5, 2018 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superposition/b0d883861bbe6663d2b9eea4384681c8 to your computer and use it in GitHub Desktop.
Save superposition/b0d883861bbe6663d2b9eea4384681c8 to your computer and use it in GitHub Desktop.
react-modal sample
<div id="main">
</div>
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'))
<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/react-modal@1.6.2/dist/react-modal.min.js"></script>
.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