-
Notifications
You must be signed in to change notification settings - Fork 3
/
SearchBar.tsx
61 lines (59 loc) · 1.4 KB
/
SearchBar.tsx
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { IconButton, InputBase, Paper } from "@mui/material";
import CloseIcon from "@mui/icons-material/Close";
import React from "react";
import { SearchBarProps } from "./SearchBar.types";
import SearchIcon from "@mui/icons-material/Search";
export default function SearchBar({
value = "",
onChange = () => {},
onBlur = () => {},
placeholder = "Search",
width = "100%"
}: SearchBarProps) {
const hasValue = value && value !== "";
return (
<Paper
variant="outlined"
sx={theme => ({
alignItems: "center",
display: "flex",
marginBottom: theme.spacing(2),
marginTop: theme.spacing(2),
width
})}
>
<InputBase
aria-label={"Search"}
placeholder={placeholder}
value={value}
onChange={onChange}
onBlur={onBlur}
sx={theme => ({
flex: 1,
marginLeft: theme.spacing(1)
})}
/>
{hasValue ? (
<IconButton
aria-label="clear search"
onClick={() => {
onChange({ target: { value: "" } });
}}
size="large"
sx={theme => ({
padding: theme.spacing(1)
})}
>
<CloseIcon />
</IconButton>
) : (
<SearchIcon
color="action"
sx={theme => ({
margin: theme.spacing(1)
})}
/>
)}
</Paper>
);
}