1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 18:13:49 +01:00
onion/js/components/ascribe_modal/modal_wrapper.js

96 lines
2.6 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
},
2015-06-01 18:59:47 +02:00
getModalTrigger() {
2015-06-01 18:59:47 +02:00
return (
<ModalTrigger modal={
<ModalBody
title={this.props.title}
handleSuccess={this.props.handleSuccess}>
2015-06-01 18:59:47 +02:00
{this.props.children}
</ModalBody>
}>
{this.props.button}
</ModalTrigger>
);
},
render() {
if(this.props.tooltip) {
return (
<OverlayTrigger
delay={500}
placement="left"
overlay={<Tooltip>{this.props.tooltip}</Tooltip>}>
{this.getModalTrigger()}
</OverlayTrigger>
);
} else {
return (
<span>
{/* This needs to be some kind of inline-block */}
{this.getModalTrigger()}
</span>
);
}
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;