You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.6 KiB
104 lines
2.6 KiB
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
import * as React from 'react';
|
|
import ResizableTextArea from './ResizableTextArea';
|
|
|
|
var TextArea = /*#__PURE__*/function (_React$Component) {
|
|
_inherits(TextArea, _React$Component);
|
|
|
|
var _super = _createSuper(TextArea);
|
|
|
|
function TextArea(props) {
|
|
var _this;
|
|
|
|
_classCallCheck(this, TextArea);
|
|
|
|
_this = _super.call(this, props);
|
|
_this.resizableTextArea = void 0;
|
|
|
|
_this.focus = function () {
|
|
_this.resizableTextArea.textArea.focus();
|
|
};
|
|
|
|
_this.saveTextArea = function (resizableTextArea) {
|
|
_this.resizableTextArea = resizableTextArea;
|
|
};
|
|
|
|
_this.handleChange = function (e) {
|
|
var onChange = _this.props.onChange;
|
|
|
|
_this.setValue(e.target.value, function () {
|
|
_this.resizableTextArea.resizeTextarea();
|
|
});
|
|
|
|
if (onChange) {
|
|
onChange(e);
|
|
}
|
|
};
|
|
|
|
_this.handleKeyDown = function (e) {
|
|
var _this$props = _this.props,
|
|
onPressEnter = _this$props.onPressEnter,
|
|
onKeyDown = _this$props.onKeyDown;
|
|
|
|
if (e.keyCode === 13 && onPressEnter) {
|
|
onPressEnter(e);
|
|
}
|
|
|
|
if (onKeyDown) {
|
|
onKeyDown(e);
|
|
}
|
|
};
|
|
|
|
var value = typeof props.value === 'undefined' || props.value === null ? props.defaultValue : props.value;
|
|
_this.state = {
|
|
value: value
|
|
};
|
|
return _this;
|
|
}
|
|
|
|
_createClass(TextArea, [{
|
|
key: "setValue",
|
|
value: function setValue(value, callback) {
|
|
if (!('value' in this.props)) {
|
|
this.setState({
|
|
value: value
|
|
}, callback);
|
|
}
|
|
}
|
|
}, {
|
|
key: "blur",
|
|
value: function blur() {
|
|
this.resizableTextArea.textArea.blur();
|
|
}
|
|
}, {
|
|
key: "render",
|
|
value: function render() {
|
|
return /*#__PURE__*/React.createElement(ResizableTextArea, _extends({}, this.props, {
|
|
value: this.state.value,
|
|
onKeyDown: this.handleKeyDown,
|
|
onChange: this.handleChange,
|
|
ref: this.saveTextArea
|
|
}));
|
|
}
|
|
}], [{
|
|
key: "getDerivedStateFromProps",
|
|
value: function getDerivedStateFromProps(nextProps) {
|
|
if ('value' in nextProps) {
|
|
return {
|
|
value: nextProps.value
|
|
};
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}]);
|
|
|
|
return TextArea;
|
|
}(React.Component);
|
|
|
|
export { ResizableTextArea };
|
|
export default TextArea; |