lbry-desktop/js/component/modal.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

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,
},
getDefaultProps: function() {
return {
type: 'alert',
confirmButtonLabel: 'OK',
abortButtonLabel: 'Cancel',
};
},
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'
? <Link button="alt" label={props.abortButtonLabel} className="modal__button" onClick={props.onAborted} />
: null}
2016-10-21 03:25:32 +02:00
<Link button="primary" label={props.confirmButtonLabel} className="modal__button" onClick={props.onConfirmed} />
</div>
);
}
return (
<ReactModal {...props}>
{this.props.children}
{buttons}
</ReactModal>
);
}
});