Skip to content

Instantly share code, notes, and snippets.

@Daniel15
Created January 8, 2014 18:17
Show Gist options
  • Save Daniel15/8321579 to your computer and use it in GitHub Desktop.
Save Daniel15/8321579 to your computer and use it in GitHub Desktop.
Bootstrap dialog in React
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>
);
}
});
@andjarnic
Copy link

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?

@danesparza
Copy link

@andjarnic -- how are you 'loading it before other .js files'?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment