UNPKG

@intuitionrobotics/thunderstorm

Version:
62 lines 2.51 kB
/* * 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 { Filter } from "@intuitionrobotics/ts-common/utils/filter-tools"; import { TS_Input } from "./TS_Input.js"; import {} from "../tools/Stylable.js"; import { compare, generateHex } from '@intuitionrobotics/ts-common'; export class FilterInput extends React.Component { filterInstance; notifyChanges; static defaultProps = { id: generateHex(16) }; constructor(props) { super(props); this.filterInstance = new Filter(); this.filterInstance.setFilter(props.initialFilterText || ''); this.notifyChanges = true; } componentDidMount() { this.callOnChange(this.props.list, ""); } shouldComponentUpdate(nextProps, _nextState, _nextContext) { const b = this.notifyChanges = !compare(this.props.list, nextProps.list); if (b) this.callOnChange(nextProps.list, ""); return b; } callOnChange = (list, filter) => { if (this.notifyChanges) this.props.onChange(this.filterInstance.filter(list, this.props.filter), filter, this.props.id); this.notifyChanges = false; }; filter = (text) => { this.filterInstance.setFilter(text); this.notifyChanges = true; this.callOnChange(this.props.list, text); }; render() { const { id, placeholder, focus } = this.props; return (React.createElement(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 })); } } //# sourceMappingURL=FilterInput.js.map