2016-10-21 03:25:32 +02:00
|
|
|
var Modal = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
type: React.PropTypes.oneOf(['alert', 'confirm', 'custom']),
|
|
|
|
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',
|
|
|
|
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() {
|
|
|
|
var props = Object.assign({}, this.props);
|
|
|
|
|
|
|
|
if (typeof props.className == 'undefined') {
|
|
|
|
props.className = 'modal';
|
|
|
|
} else {
|
|
|
|
props.className += ' modal';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof props.overlayClassName == 'undefined') {
|
|
|
|
props.overlayClassName = 'modal-overlay';
|
|
|
|
} else {
|
|
|
|
props.overlayClassName += ' modal-overlay';
|
|
|
|
}
|
|
|
|
|
|
|
|
props.onCloseRequested = props.onAborted || props.onConfirmed;
|
|
|
|
|
2016-10-22 07:04:24 +02:00
|
|
|
if (this.props.type == 'custom') {
|
|
|
|
var buttons = null;
|
|
|
|
} else {
|
2016-10-21 03:25:32 +02:00
|
|
|
var buttons = (
|
|
|
|
<div className="modal__buttons">
|
2016-10-22 07:04:24 +02:00
|
|
|
{this.props.type == 'confirm'
|
2016-10-26 09:22:05 +02:00
|
|
|
? <Link button="alt" label={props.abortButtonLabel} className="modal__button" disabled={this.props.abortButtonDisabled} onClick={props.onAborted} />
|
2016-10-22 07:04:24 +02:00
|
|
|
: null}
|
2016-10-26 09:22:05 +02:00
|
|
|
<Link button="primary" label={props.confirmButtonLabel} className="modal__button" disabled={this.props.confirmButtonDisabled} onClick={props.onConfirmed} />
|
2016-10-21 03:25:32 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ReactModal {...props}>
|
2016-11-25 05:03:03 +01:00
|
|
|
<div>
|
|
|
|
{this.props.children}
|
|
|
|
</div>
|
2016-10-21 03:25:32 +02:00
|
|
|
{buttons}
|
|
|
|
</ReactModal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|