Created
July 28, 2016 19:38
-
-
Save eudoxia0/4e540c48d62177a16c158810a3ae95b2 to your computer and use it in GitHub Desktop.
React modal component
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
var App = React.createClass({ | |
getInitialState: function() { | |
return { isModalOpen: false }; | |
}, | |
openModal: function() { | |
this.setState({ isModalOpen: true }); | |
}, | |
closeModal: function() { | |
this.setState({ isModalOpen: false }); | |
}, | |
render: function() { | |
return ( | |
<div className="app"> | |
<h1>App</h1> | |
<button onClick={this.openModal}>Open modal</button> | |
<Modal isOpen={this.state.isModalOpen} | |
transitionName="modal-anim"> | |
<h3>My Modal</h3> | |
<div className="body"> | |
<p>This is the modal's body.</p> | |
</div> | |
<button onClick={this.closeModal}>Close modal</button> | |
</Modal> | |
</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
.modal-anim-enter { | |
opacity: 0.00; | |
transform: scale(0.7); | |
transition: all 0.2s; | |
} | |
.modal-anim-enter.modal-anim-enter-active { | |
opacity: 1; | |
transform: scale(1); | |
} |
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
var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup; |
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-anim-leave { | |
opacity: 1; | |
transform: scale(1); | |
transition: all 0.2s; | |
} | |
.modal-anim-leave.modal-anim-leave-active { | |
opacity: 0.00; | |
transform: scale(0.7); | |
} |
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
var Modal = React.createClass({ | |
render: function() { | |
if(this.props.isOpen){ | |
return ( | |
<ReactCSSTransitionGroup transitionName={this.props.transitionName}> | |
<div className="modal"> | |
{this.props.children} | |
</div> | |
</ReactCSSTransitionGroup> | |
); | |
} else { | |
return <ReactCSSTransitionGroup transitionName={this.props.transitionName} />; | |
} | |
} | |
}); |
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
React.render( | |
<App/>, | |
document.body | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment