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-09 19:24:33 +00:00
|
|
|
_setDefaultValueFromProps () {
|
|
|
|
if (this.props.defaultValue) {
|
|
|
|
this.refs.input.value = this.props.defaultValue;
|
|
|
|
}
|
2016-04-09 21:41:27 +00:00
|
|
|
|
|
|
|
this.refs.input.focus();
|
|
|
|
this.refs.input.select();
|
2016-04-09 19:24:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
this._setDefaultValueFromProps();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate () {
|
|
|
|
this._setDefaultValueFromProps();
|
|
|
|
}
|
|
|
|
|
2016-04-07 17:06:04 +00:00
|
|
|
render () {
|
2016-04-10 02:58:48 +00:00
|
|
|
const {onClose, submitName, headerName} = this.props;
|
2016-04-07 17:06:04 +00:00
|
|
|
return (
|
2016-04-10 02:58:48 +00:00
|
|
|
<Modal ref="modal" onClose={onClose}>
|
2016-04-08 04:05:08 +00:00
|
|
|
<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">
|
2016-04-09 21:41:27 +00:00
|
|
|
<input ref="input" type="text"/>
|
2016-04-09 01:14:25 +00:00
|
|
|
</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
|
|
|
headerName: PropTypes.string.isRequired,
|
2016-04-09 19:24:33 +00:00
|
|
|
|
|
|
|
defaultValue: PropTypes.string,
|
2016-04-08 04:05:08 +00:00
|
|
|
submitName: PropTypes.string,
|
2016-04-07 17:06:04 +00:00
|
|
|
onClose: PropTypes.func
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PromptModal;
|