2016-11-22 21:19:08 +01:00
|
|
|
import React from 'react';
|
|
|
|
import ReactModal from 'react-modal';
|
|
|
|
import {Link} from './link.js';
|
|
|
|
|
|
|
|
|
2017-02-25 08:56:57 +01:00
|
|
|
export const Modal = React.createClass({
|
2016-10-21 03:25:32 +02:00
|
|
|
propTypes: {
|
|
|
|
type: React.PropTypes.oneOf(['alert', 'confirm', 'custom']),
|
2017-04-12 22:23:20 +02:00
|
|
|
overlay: React.PropTypes.bool,
|
2016-10-21 03:25:32 +02:00
|
|
|
onConfirmed: React.PropTypes.func,
|
|
|
|
onAborted: React.PropTypes.func,
|
|
|
|
confirmButtonLabel: React.PropTypes.string,
|
|
|
|
abortButtonLabel: React.PropTypes.string,
|
2016-10-26 09:22:05 +02:00
|
|
|
confirmButtonDisabled: React.PropTypes.bool,
|
|
|
|
abortButtonDisabled: React.PropTypes.bool,
|
2016-10-21 03:25:32 +02:00
|
|
|
},
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
type: 'alert',
|
2017-04-12 22:23:20 +02:00
|
|
|
overlay: true,
|
2016-10-21 03:25:32 +02:00
|
|
|
confirmButtonLabel: 'OK',
|
|
|
|
abortButtonLabel: 'Cancel',
|
2016-10-26 09:22:05 +02:00
|
|
|
confirmButtonDisabled: false,
|
|
|
|
abortButtonDisabled: false,
|
2016-10-21 03:25:32 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
return (
|
2017-02-25 08:45:39 +01:00
|
|
|
<ReactModal onCloseRequested={this.props.onAborted || this.props.onConfirmed} {...this.props}
|
|
|
|
className={(this.props.className || '') + ' modal'}
|
2017-04-12 22:23:20 +02:00
|
|
|
overlayClassName={[null, undefined, ""].indexOf(this.props.overlayClassName) === -1 ? this.props.overlayClassName : 'modal-overlay'}>
|
2017-02-25 08:45:39 +01:00
|
|
|
<div>
|
|
|
|
{this.props.children}
|
|
|
|
</div>
|
|
|
|
{this.props.type == 'custom' // custom modals define their own buttons
|
|
|
|
? null
|
|
|
|
: <div className="modal__buttons">
|
2017-03-17 23:05:25 +01:00
|
|
|
<Link button="primary" label={this.props.confirmButtonLabel} className="modal__button" disabled={this.props.confirmButtonDisabled} onClick={this.props.onConfirmed} />
|
|
|
|
{this.props.type == 'confirm'
|
|
|
|
? <Link button="alt" label={this.props.abortButtonLabel} className="modal__button" disabled={this.props.abortButtonDisabled} onClick={this.props.onAborted} />
|
|
|
|
: null}
|
2017-02-25 08:45:39 +01:00
|
|
|
</div>}
|
2016-10-21 03:25:32 +02:00
|
|
|
</ReactModal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2016-11-22 21:19:08 +01:00
|
|
|
|
2017-02-25 08:56:57 +01:00
|
|
|
export const ExpandableModal = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
expandButtonLabel: React.PropTypes.string,
|
|
|
|
extraContent: React.PropTypes.element,
|
|
|
|
},
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
confirmButtonLabel: 'OK',
|
|
|
|
expandButtonLabel: 'Show More...',
|
|
|
|
hideButtonLabel: 'Show Less',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
expanded: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toggleExpanded: function() {
|
|
|
|
this.setState({
|
|
|
|
expanded: !this.state.expanded,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<Modal type="custom" {... this.props}>
|
|
|
|
{this.props.children}
|
|
|
|
{this.state.expanded
|
|
|
|
? this.props.extraContent
|
|
|
|
: null}
|
|
|
|
<div className="modal__buttons">
|
|
|
|
<Link button="primary" label={this.props.confirmButtonLabel} className="modal__button" onClick={this.props.onConfirmed} />
|
|
|
|
<Link button="alt" label={!this.state.expanded ? this.props.expandButtonLabel : this.props.hideButtonLabel}
|
|
|
|
className="modal__button" onClick={this.toggleExpanded} />
|
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-22 21:19:08 +01:00
|
|
|
export default Modal;
|