@intuitionrobotics/thunderstorm
Version:
63 lines • 2.67 kB
JavaScript
"use strict";
/*
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.FilterInput = void 0;
const React = require("react");
const filter_tools_1 = require("@intuitionrobotics/ts-common/utils/filter-tools");
const TS_Input_1 = require("./TS_Input");
const ts_common_1 = require("@intuitionrobotics/ts-common");
class FilterInput extends React.Component {
constructor(props) {
super(props);
this.callOnChange = (list, filter) => {
if (this.notifyChanges)
this.props.onChange(this.filterInstance.filter(list, this.props.filter), filter, this.props.id);
this.notifyChanges = false;
};
this.filter = (text) => {
this.filterInstance.setFilter(text);
this.notifyChanges = true;
this.callOnChange(this.props.list, text);
};
this.filterInstance = new filter_tools_1.Filter();
this.filterInstance.setFilter(props.initialFilterText || '');
this.notifyChanges = true;
}
componentDidMount() {
this.callOnChange(this.props.list, "");
}
shouldComponentUpdate(nextProps, nextState, nextContext) {
const b = this.notifyChanges = !(0, ts_common_1.compare)(this.props.list, nextProps.list);
if (b)
this.callOnChange(nextProps.list, "");
return b;
}
render() {
const { id, placeholder, focus } = this.props;
return (React.createElement(TS_Input_1.TS_Input, { type: 'text', id: id, value: this.props.initialFilterText, onChange: (text) => this.filter(text), focus: focus, placeholder: placeholder, className: this.props.className, style: this.props.style, handleKeyEvent: this.props.handleKeyEvent }));
}
}
exports.FilterInput = FilterInput;
FilterInput.defaultProps = {
id: (0, ts_common_1.generateHex)(16)
};
//# sourceMappingURL=FilterInput.js.map