X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/c90e813adcec89899d9db95843295a84fb058c3e..158a4936f754ad78004e1bbcbb5af053a6a4073a:/src/components/search-input/search-input.tsx diff --git a/src/components/search-input/search-input.tsx b/src/components/search-input/search-input.tsx index edc82d55..dc02cd3d 100644 --- a/src/components/search-input/search-input.tsx +++ b/src/components/search-input/search-input.tsx @@ -3,87 +3,9 @@ // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; -import { IconButton, Paper, StyleRulesCallback, withStyles, WithStyles, FormControl, InputLabel, Input, InputAdornment, FormHelperText } from '@material-ui/core'; +import { IconButton, StyleRulesCallback, withStyles, WithStyles, FormControl, InputLabel, Input, InputAdornment } from '@material-ui/core'; import SearchIcon from '@material-ui/icons/Search'; -interface SearchInputDataProps { - value: string; -} - -interface SearchInputActionProps { - onSearch: (value: string) => any; - debounce?: number; -} - -type SearchInputProps = SearchInputDataProps & SearchInputActionProps & WithStyles; - -interface SearchInputState { - value: string; -} - -export const DEFAULT_SEARCH_DEBOUNCE = 1000; - -class SearchInput extends React.Component { - - state: SearchInputState = { - value: "" - }; - - timeout: number; - - render() { - const { classes } = this.props; - return
- - Search - - - - - - } /> - -
; - } - - componentDidMount() { - this.setState({ value: this.props.value }); - } - - componentWillReceiveProps(nextProps: SearchInputProps) { - if (nextProps.value !== this.props.value) { - this.setState({ value: nextProps.value }); - } - } - - componentWillUnmount() { - clearTimeout(this.timeout); - } - - handleSubmit = (event: React.FormEvent) => { - event.preventDefault(); - clearTimeout(this.timeout); - this.props.onSearch(this.state.value); - } - - handleChange = (event: React.ChangeEvent) => { - clearTimeout(this.timeout); - this.setState({ value: event.target.value }); - this.timeout = window.setTimeout( - () => this.props.onSearch(this.state.value), - this.props.debounce || DEFAULT_SEARCH_DEBOUNCE - ); - - } - -} - type CssRules = 'container' | 'input' | 'button'; const styles: StyleRulesCallback = theme => { @@ -110,4 +32,80 @@ const styles: StyleRulesCallback = theme => { }; }; -export default withStyles(styles)(SearchInput); \ No newline at end of file +interface SearchInputDataProps { + value: string; +} + +interface SearchInputActionProps { + onSearch: (value: string) => any; + debounce?: number; +} + +type SearchInputProps = SearchInputDataProps & SearchInputActionProps & WithStyles; + +interface SearchInputState { + value: string; +} + +export const DEFAULT_SEARCH_DEBOUNCE = 1000; + +export const SearchInput = withStyles(styles)( + class extends React.Component { + state: SearchInputState = { + value: "" + }; + + timeout: number; + + render() { + const { classes } = this.props; + return
+ + Search + + + + + + }/> + +
; + } + + componentDidMount() { + this.setState({ value: this.props.value }); + } + + componentWillReceiveProps(nextProps: SearchInputProps) { + if (nextProps.value !== this.props.value) { + this.setState({ value: nextProps.value }); + } + } + + componentWillUnmount() { + clearTimeout(this.timeout); + } + + handleSubmit = (event: React.FormEvent) => { + event.preventDefault(); + clearTimeout(this.timeout); + this.props.onSearch(this.state.value); + } + + handleChange = (event: React.ChangeEvent) => { + clearTimeout(this.timeout); + this.setState({ value: event.target.value }); + this.timeout = window.setTimeout( + () => this.props.onSearch(this.state.value), + this.props.debounce || DEFAULT_SEARCH_DEBOUNCE + ); + + } + } +);