mirror of
https://github.com/ascribe/onion.git
synced 2024-12-23 01:39:36 +01:00
Merge pull request #15 from ascribe/AD-1256-refactor-modalwrapper-to-not-be-
Refactor ModalWrapper to not require a trigger component
This commit is contained in:
commit
9a54ebdbd7
@ -7,7 +7,7 @@ import Modal from 'react-bootstrap/lib/Modal';
|
|||||||
|
|
||||||
let ModalWrapper = React.createClass({
|
let ModalWrapper = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
trigger: React.PropTypes.element.isRequired,
|
trigger: React.PropTypes.element,
|
||||||
title: React.PropTypes.oneOfType([
|
title: React.PropTypes.oneOfType([
|
||||||
React.PropTypes.arrayOf(React.PropTypes.element),
|
React.PropTypes.arrayOf(React.PropTypes.element),
|
||||||
React.PropTypes.element,
|
React.PropTypes.element,
|
||||||
@ -52,17 +52,19 @@ let ModalWrapper = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
// this adds the onClick method show of modal_wrapper to the trigger component
|
const { trigger, title } = this.props;
|
||||||
// which is in most cases a button.
|
|
||||||
let trigger = React.cloneElement(this.props.trigger, {onClick: this.show});
|
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
const clonedTrigger = React.isValidElement(trigger) ? React.cloneElement(trigger, {onClick: this.show})
|
||||||
|
: null;
|
||||||
return (
|
return (
|
||||||
<span>
|
<span>
|
||||||
{trigger}
|
{clonedTrigger}
|
||||||
<Modal show={this.state.showModal} onHide={this.hide}>
|
<Modal show={this.state.showModal} onHide={this.hide}>
|
||||||
<Modal.Header closeButton>
|
<Modal.Header closeButton>
|
||||||
<Modal.Title>
|
<Modal.Title>
|
||||||
{this.props.title}
|
{title}
|
||||||
</Modal.Title>
|
</Modal.Title>
|
||||||
</Modal.Header>
|
</Modal.Header>
|
||||||
<div className="modal-body" >
|
<div className="modal-body" >
|
||||||
|
Loading…
Reference in New Issue
Block a user