2017-02-28 06:26:24 +00:00
|
|
|
import React, {PureComponent, PropTypes} from 'react';
|
2017-02-27 21:00:13 +00:00
|
|
|
import Editor from './Editor';
|
|
|
|
|
2017-02-28 06:26:24 +00:00
|
|
|
class OneLineEditor extends PureComponent {
|
2017-02-27 21:00:13 +00:00
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.value = props.defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
focus () {
|
2017-02-28 06:26:24 +00:00
|
|
|
if (!this.editor.hasFocus()) {
|
|
|
|
this.editor.focusEnd();
|
|
|
|
}
|
2017-02-27 21:00:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_handleChange = value => {
|
|
|
|
this.value = value;
|
|
|
|
this.props.onChange && this.props.onChange(value);
|
|
|
|
};
|
|
|
|
|
|
|
|
_setRef = n => this.editor = n;
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const {defaultValue, ...props} = this.props;
|
|
|
|
return (
|
|
|
|
<Editor
|
|
|
|
ref={this._setRef}
|
|
|
|
{...props}
|
2017-02-28 06:26:24 +00:00
|
|
|
defaultTabBehavior
|
|
|
|
hideLineNumbers
|
|
|
|
hideScrollbars
|
|
|
|
noDragDrop
|
|
|
|
noMatchBrackets
|
|
|
|
singleLine
|
2017-02-28 21:32:23 +00:00
|
|
|
tabIndex={0}
|
2017-02-27 21:00:13 +00:00
|
|
|
onChange={this._handleChange}
|
|
|
|
className="editor--single-line"
|
|
|
|
value={defaultValue}
|
|
|
|
lineWrapping={false}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OneLineEditor.propTypes = Object.assign({}, Editor.propTypes, {
|
|
|
|
defaultValue: PropTypes.string.isRequired,
|
|
|
|
});
|
|
|
|
|
|
|
|
export default OneLineEditor;
|