insomnia/app/ui/components/modals/AlertModal.js

56 lines
1.2 KiB
JavaScript
Raw Normal View History

import React, {PureComponent} from 'react';
import Modal from '../base/Modal';
import ModalBody from '../base/ModalBody';
import ModalHeader from '../base/ModalHeader';
import ModalFooter from '../base/ModalFooter';
class AlertModal extends PureComponent {
state = {
title: '',
message: '',
};
_setModalRef = m => this.modal = m;
_handleOk = () => {
this.hide();
this._okCallback();
};
hide () {
this.modal.hide();
}
2016-11-20 07:43:22 +00:00
show (options = {}) {
this.modal.show();
2016-11-20 07:43:22 +00:00
const {title, message} = options;
this.setState({title, message});
return new Promise(resolve => this._okCallback = resolve);
}
render () {
const {extraProps} = this.props;
const {message, title} = this.state;
return (
<Modal ref={this._setModalRef} closeOnKeyCodes={[13]} {...extraProps}>
<ModalHeader>{title || 'Uh Oh!'}</ModalHeader>
<ModalBody className="wide pad">
{message}
</ModalBody>
<ModalFooter>
<button className="btn" onClick={this._handleOk}>
Ok
</button>
</ModalFooter>
</Modal>
)
}
}
AlertModal.propTypes = {};
export default AlertModal;