1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 17:45:10 +01:00
onion/js/components/ascribe_modal/modal_wrapper.js

79 lines
2.2 KiB
JavaScript
Raw Normal View History

'use strict';
2015-06-01 18:59:47 +02:00
import React from 'react';
import ReactAddons from 'react/addons';
import Modal from 'react-bootstrap/lib/Modal';
import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger';
import ModalTrigger from 'react-bootstrap/lib/ModalTrigger';
import Tooltip from 'react-bootstrap/lib/Tooltip';
import ModalMixin from '../../mixins/modal_mixin';
2015-06-01 18:59:47 +02:00
let ModalWrapper = React.createClass({
propTypes: {
title: React.PropTypes.string.isRequired,
onRequestHide: React.PropTypes.func,
handleSuccess: React.PropTypes.func.isRequired,
button: React.PropTypes.object.isRequired,
children: React.PropTypes.object,
tooltip: React.PropTypes.string.isRequired
},
2015-06-01 18:59:47 +02:00
render() {
return (
<OverlayTrigger delay={500} placement="left"
overlay={<Tooltip>{this.props.tooltip}</Tooltip>}>
<ModalTrigger modal={
<ModalBody
title={this.props.title}
2015-06-03 11:49:39 +02:00
handleSuccess={this.props.handleSuccess}>
2015-06-01 18:59:47 +02:00
{this.props.children}
</ModalBody>
}>
{this.props.button}
</ModalTrigger>
</OverlayTrigger>
);
2015-06-01 18:59:47 +02:00
}
});
2015-06-01 18:59:47 +02:00
let ModalBody = React.createClass({
propTypes: {
onRequestHide: React.PropTypes.func,
handleSuccess: React.PropTypes.func,
children: React.PropTypes.object,
title: React.PropTypes.string.isRequired
},
mixins: [ModalMixin],
2015-06-01 18:59:47 +02:00
handleSuccess(response){
this.props.handleSuccess(response);
2015-06-02 11:38:18 +02:00
this.props.onRequestHide();
},
2015-06-01 18:59:47 +02:00
renderChildren() {
return ReactAddons.Children.map(this.props.children, (child) => {
2015-06-01 18:59:47 +02:00
return ReactAddons.addons.cloneWithProps(child, {
2015-06-10 15:49:46 +02:00
onRequestHide: this.props.onRequestHide,
2015-06-02 11:38:18 +02:00
handleSuccess: this.handleSuccess
2015-06-01 18:59:47 +02:00
});
});
},
2015-06-01 18:59:47 +02:00
render() {
return (
<Modal {...this.props} title={this.props.title}>
<div className="modal-body">
{this.renderChildren()}
</div>
</Modal>
);
2015-06-01 18:59:47 +02:00
}
});
export default ModalWrapper;