@intuitionrobotics/thunderstorm
Version:
58 lines • 2.19 kB
JavaScript
/*
* Thunderstorm is a full web app framework!
*
* Typescript & Express backend infrastructure that natively runs on firebase function
* Typescript & React frontend infrastructure
*
* Copyright (C) 2020 Intuition Robotics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as React from 'react';
import {} from 'react';
import {} from "../tools/Stylable.js";
export class TS_TextArea extends React.Component {
constructor(props) {
super(props);
this.state = TS_TextArea.getInitialState(props);
}
static getInitialState(props) {
return {
id: props.id,
name: props.name,
initialValue: props.value,
value: props.value || ""
};
}
static getDerivedStateFromProps(props, state) {
if (props.id === state.id && state.name === props.name && state.initialValue === props.value)
return { value: state.value };
return TS_TextArea.getInitialState(props);
}
changeValue = (event) => {
const value = event.target.value;
this.setState({ value });
this.props.onChange?.(value, event.target.id);
};
handleKeyPress = (event) => {
if (!this.props.onAccept)
return;
if (event.key === "Escape")
this.props.onAccept();
};
render() {
const { id, placeholder, style } = this.props;
return React.createElement("textarea", { disabled: this.props.enable === false, key: id, id: id, onKeyPress: this.handleKeyPress, onChange: this.changeValue, value: this.state.value, placeholder: placeholder, style: { ...style } });
}
}
//# sourceMappingURL=TS_TextArea.js.map