2016-09-10 02:51:24 +00:00
|
|
|
import React, {Component, PropTypes} from 'react';
|
|
|
|
|
|
|
|
class ResponseRaw extends Component {
|
|
|
|
_update (value) {
|
2016-09-14 23:25:19 +00:00
|
|
|
// Use a timeout so it doesn't block the UI
|
2017-02-27 21:00:13 +00:00
|
|
|
window.requestAnimationFrame(() => this._setTextAreaValue(value))
|
2016-09-14 23:25:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_setTextAreaValue (value) {
|
|
|
|
// Bail if we're not mounted
|
|
|
|
if (!this._textarea) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._textarea.value = value;
|
2016-09-10 02:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate () {
|
|
|
|
this._update(this.props.value)
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
this._update(this.props.value)
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldComponentUpdate (nextProps) {
|
|
|
|
for (let key in nextProps) {
|
|
|
|
if (nextProps.hasOwnProperty(key)) {
|
|
|
|
if (nextProps[key] !== this.props[key]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const {fontSize} = this.props;
|
|
|
|
return (
|
|
|
|
<textarea
|
|
|
|
ref={n => this._textarea = n}
|
|
|
|
placeholder="..."
|
|
|
|
className="force-wrap scrollable wide tall selectable monospace pad no-resize"
|
|
|
|
readOnly={true}
|
|
|
|
defaultValue=""
|
|
|
|
style={{fontSize}}>
|
|
|
|
</textarea>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ResponseRaw.propTypes = {
|
|
|
|
value: PropTypes.string.isRequired,
|
|
|
|
fontSize: PropTypes.number
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ResponseRaw;
|