1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 01:25:17 +01:00

Refactor ModalWrapper to not require a trigger component

This commit is contained in:
Brett Sun 2015-10-29 16:23:02 +01:00
parent 590818cf0b
commit 22234492e6

View File

@ -7,7 +7,7 @@ import Modal from 'react-bootstrap/lib/Modal';
let ModalWrapper = React.createClass({
propTypes: {
trigger: React.PropTypes.element.isRequired,
trigger: React.PropTypes.element,
title: React.PropTypes.oneOfType([
React.PropTypes.arrayOf(React.PropTypes.element),
React.PropTypes.element,
@ -38,7 +38,7 @@ let ModalWrapper = React.createClass({
});
},
handleSuccess(response){
handleSuccess(response) {
this.props.handleSuccess(response);
this.hide();
},
@ -52,17 +52,19 @@ let ModalWrapper = React.createClass({
},
render() {
// this adds the onClick method show of modal_wrapper to the trigger component
// which is in most cases a button.
let trigger = React.cloneElement(this.props.trigger, {onClick: this.show});
const { trigger, title } = this.props;
// If the trigger component exists, we add the ModalWrapper's show() as its onClick method.
// The trigger component should, in most cases, be a button.
let clonedTrigger = React.isValidElement(trigger) ? React.cloneElement(trigger, {onClick: this.show})
: null;
return (
<span>
{trigger}
{clonedTrigger}
<Modal show={this.state.showModal} onHide={this.hide}>
<Modal.Header closeButton>
<Modal.Title>
{this.props.title}
{title}
</Modal.Title>
</Modal.Header>
<div className="modal-body" >