Created
January 8, 2014 18:17
-
-
Save Daniel15/8321579 to your computer and use it in GitHub Desktop.
Bootstrap dialog in React
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 Dialog = React.createClass({ | |
getInitialState: function() { | |
return { | |
className: 'modal fade' | |
}; | |
}, | |
show: function() { | |
this.setState({ className: 'modal fade show' }); | |
setTimeout(function() { | |
this.setState({ className: 'modal fade show in' }); | |
}.bind(this), 0); | |
}, | |
hide: function() { | |
// Fade out the help dialog, and totally hide it after a set timeout | |
// (once the fade completes) | |
this.setState({ className: 'modal fade show' }); | |
setTimeout(function() { | |
this.setState({ className: 'modal fade' }); | |
}.bind(this), 400); | |
}, | |
render: function() { | |
return ( | |
<div className={this.state.className}> | |
<div className="modal-dialog"> | |
<div className="modal-content"> | |
<div className="modal-header"> | |
<button type="button" className="close" aria-hidden="true" onClick={this.hide}>×</button> | |
<h4 className="modal-title">{this.props.title}</h4> | |
</div> | |
<div className="modal-body"> | |
{this.props.children} | |
</div> | |
<div className="modal-footer"> | |
<button type="button" className="btn btn-default" onClick={this.hide}>Close</button> | |
</div> | |
</div> | |
</div> | |
</div> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sadly, I am not able to understand how to use this in my own JS code. I am trying to learn ReactJS, but so far I can only seem to render ReactJS components if I provide the React.renderComponent() in the same file as the declared React class. When I load my React component .js file BEFORE my app.js (my own js code), and in app.js I try to render the component using React.renderComponent(Dialog(), mountNode); it gives me an error regarding not able to find Dialog. I thought when defining Dialog as you do above, then loading it BEFORE other .js files, it would be a global accessed function that other .JS files loaded after could use?