insomnia/app/components/base/PromptModal.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-04-07 17:06:04 +00:00
import React, {Component, PropTypes} from 'react';
import {Modal, ModalHeader, ModalBody, ModalFooter} from './Modal'
class PromptModal extends Component {
2016-04-08 04:05:08 +00:00
_onSubmit (e) {
e.preventDefault();
this.props.onSubmit(this.refs.input.value);
this.refs.modal.close();
}
2016-04-07 17:06:04 +00:00
render () {
2016-04-08 04:05:08 +00:00
const {visible, onClose, submitName, headerName} = this.props;
2016-04-07 17:06:04 +00:00
return (
2016-04-08 04:05:08 +00:00
<Modal ref="modal" onClose={onClose} visible={visible}>
<ModalHeader>{headerName}</ModalHeader>
2016-04-09 01:14:25 +00:00
<ModalBody className="wide">
<form onSubmit={this._onSubmit.bind(this)} className="wide">
<div className="form-control form-control--outlined">
<input ref="input"
type="text"
autoFocus={true}/>
</div>
2016-04-08 04:05:08 +00:00
</form>
</ModalBody>
<ModalFooter className="grid grid--end">
2016-04-09 01:14:25 +00:00
<button className="btn" onClick={() => this.refs.modal.close()}>Cancel</button>
2016-04-08 04:05:08 +00:00
<button className="btn" onClick={this._onSubmit.bind(this)}>
{submitName || 'Save'}
</button>
</ModalFooter>
2016-04-07 17:06:04 +00:00
</Modal>
)
}
}
PromptModal.propTypes = {
onSubmit: PropTypes.func.isRequired,
2016-04-08 04:05:08 +00:00
visible: PropTypes.bool.isRequired,
headerName: PropTypes.string.isRequired,
submitName: PropTypes.string,
2016-04-07 17:06:04 +00:00
onClose: PropTypes.func
};
export default PromptModal;