'use strict'; // Simple pure-React component so we don't have to remember // Bootstrap's classes var BootstrapButton = React.createClass({ render: function() { return ( ); } }); var BootstrapModal = React.createClass({ // The following two methods are the only places we need to // integrate Bootstrap or jQuery with the components lifecycle methods. componentDidMount: function() { // When the component is added, turn it into a modal $(this.refs.root).modal({backdrop: 'static', keyboard: false, show: false}); // Bootstrap's modal class exposes a few events for hooking into modal // functionality. Lets hook into one of them: $(this.refs.root).on('hidden.bs.modal', this.handleHidden); }, componentWillUnmount: function() { $(this.refs.root).off('hidden.bs.modal', this.handleHidden); }, close: function() { $(this.refs.root).modal('hide'); }, open: function() { $(this.refs.root).modal('show'); }, render: function() { var confirmButton = null; var cancelButton = null; if (this.props.confirm) { confirmButton = ( {this.props.confirm} ); } if (this.props.cancel) { cancelButton = ( {this.props.cancel} ); } return (

{this.props.title}

{this.props.children}
{cancelButton} {confirmButton}
); }, handleCancel: function() { if (this.props.onCancel) { this.props.onCancel(); } }, handleConfirm: function() { if (this.props.onConfirm) { this.props.onConfirm(); } }, handleHidden: function() { if (this.props.onHidden) { this.props.onHidden(); } } }); var Example = React.createClass({ handleCancel: function() { if (confirm('Are you sure you want to cancel?')) { this.refs.modal.close(); } }, render: function() { var modal = null; modal = ( This is a React component powered by jQuery and Bootstrap! ); return (
{modal} Open modal
); }, openModal: function() { this.refs.modal.open(); }, closeModal: function() { this.refs.modal.close(); }, handleModalDidClose: function() { alert("The modal has been dismissed!"); } }); ReactDOM.render(, document.getElementById('jqueryexample'));