CEC-244 Remote car commands, search, sortable tables (#42)
* Add sortable table header * Send bulk commands page Update table page sizes All tables are sortable * Update site layout Add search to update packages * Reenable Datadog * remove dev stuff
This commit is contained in:
49
src/components/Controls/SearchField/index.jsx
Normal file
49
src/components/Controls/SearchField/index.jsx
Normal file
@@ -0,0 +1,49 @@
|
||||
import React, { useState } from "react";
|
||||
import {
|
||||
FormControl,
|
||||
IconButton,
|
||||
Input,
|
||||
InputAdornment,
|
||||
InputLabel,
|
||||
} from "@material-ui/core";
|
||||
import SearchIcon from "@material-ui/icons/Search";
|
||||
import clsx from "clsx";
|
||||
|
||||
const SearchField = (props) => {
|
||||
const { classes, onSearch } = props;
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const handleChange = (e) => {
|
||||
setSearchTerm(e.target.value);
|
||||
};
|
||||
const handleSearch = (e) => {
|
||||
if (!onSearch) return;
|
||||
onSearch(searchTerm);
|
||||
};
|
||||
const handleEnterPress = (e) => {
|
||||
if (e.keyCode !== 13) return;
|
||||
e.preventDefault();
|
||||
handleSearch(e);
|
||||
};
|
||||
|
||||
return (
|
||||
<FormControl className={clsx(classes.margin, classes.textField)}>
|
||||
<InputLabel htmlFor="search">Search</InputLabel>
|
||||
<Input
|
||||
id="search"
|
||||
type="text"
|
||||
value={searchTerm}
|
||||
onChange={handleChange}
|
||||
onKeyDown={handleEnterPress}
|
||||
endAdornment={
|
||||
<InputAdornment position="end">
|
||||
<IconButton aria-label="search" onClick={handleSearch}>
|
||||
<SearchIcon />
|
||||
</IconButton>
|
||||
</InputAdornment>
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
);
|
||||
};
|
||||
|
||||
export default SearchField;
|
||||
Reference in New Issue
Block a user