lbry-desktop/js/component/modal.js

47 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-11-22 21:19:08 +01:00
import React from 'react';
import ReactModal from 'react-modal';
import {Link} from './link.js';
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,
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',
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'}
overlayClassName={(this.props.overlayClassName || '') + ' modal-overlay'}>
<div>
{this.props.children}
</div>
{this.props.type == 'custom' // custom modals define their own buttons
? null
: <div className="modal__buttons">
{this.props.type == 'confirm'
? <Link button="alt" label={this.props.abortButtonLabel} className="modal__button" disabled={this.props.abortButtonDisabled} onClick={this.props.onAborted} />
: null}
<Link button="primary" label={this.props.confirmButtonLabel} className="modal__button" disabled={this.props.confirmButtonDisabled} onClick={this.props.onConfirmed} />
</div>}
2016-10-21 03:25:32 +02:00
</ReactModal>
);
}
});
2016-11-22 21:19:08 +01:00
export default Modal;