JSFiddle - React, Tailwind, and code Playground
by deadlyicon
HTML
<script src="http://fb.me/react-with-addons-0.11.0.js"></script>
<script src="http://fb.me/JSXTransformer-0.11.0.js"></script>
<script src="http://fb.me/react-js-fiddle-integration.js"></script>
CSS
.modal{
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
background-color: rgba(0,0,0,0.5);
}
.example-enter {
opacity: 0.01;
transition: opacity .5s ease-in;
}
.example-enter.example-enter-active {
opacity: 1;
}
.example-leave {
opacity: 1;
transition: opacity .5s ease-in;
}
.example-leave.example-leave-active {
opacity: 0.01;
}
JavaScript 1.7
/** @jsx React.DOM */
var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;
var Modal = React.createClass({
render: function() {
return (
<div className="modal">
<button onClick={this.props.onClose}>Close</button>
</div>
)
},
componentDidMount: function(){
this.getDOMNode().childNodes[0].focus();
},
});
var ModalOpener = React.createClass({
getInitialState: function() {
return {open: false};
},
open: function() {
this.setState({open: true});
},
close: function() {
this.setState({open: false});
},
render: function() {
var modal;
if (this.state.open){
modal = <Modal onClose={this.close}>Close</Modal>;
}
return (
<div>
<button onClick={this.open}>Open</button>
<div className="things">
<ReactCSSTransitionGroup transitionName="example">
{modal}
</ReactCSSTransitionGroup>
</div>
</div>
);
}
});
React.renderComponent(<ModalOpener/>, document.body);