forked from ritz078/transform
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSearchbox.tsx
More file actions
37 lines (33 loc) · 957 Bytes
/
Searchbox.tsx
File metadata and controls
37 lines (33 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { routes } from "@utils/routes";
import { Autocomplete, SearchInput } from "evergreen-ui";
import React, { useCallback } from "react";
import { useRouter } from "next/router";
const SearchBox: React.FunctionComponent<{}> = () => {
const router = useRouter();
const onSearchSelect = useCallback(changedItem => {
const route = routes.find(route => changedItem === route.searchTerm);
router.push(route.path);
}, []);
return (
<Autocomplete
onChange={onSearchSelect}
items={routes.map(a => a.searchTerm)}
width="100%"
>
{props => {
const { getInputProps, getRef, inputValue } = props;
return (
<SearchInput
width="100%"
marginBottom={10}
placeholder="Search"
value={inputValue}
innerRef={getRef}
{...getInputProps()}
/>
);
}}
</Autocomplete>
);
};
export default SearchBox;