-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSidebarFilter.tsx
92 lines (89 loc) · 2.1 KB
/
SidebarFilter.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { Divider, Drawer, IconButton, Stack, Typography } from "@mui/material";
import React, { useState } from "react";
import { ClearFilterButton } from "../ClearFilterButton";
import { Close } from "@mui/icons-material";
import { SetFilterButton } from "../SetFilterButton";
import { SidebarFilterProps } from "./SidebarFilter.types";
/**
* SidebarFilter component that displays a filter in the sidebar
*/
export function SidebarFilter({
children,
count = 0,
onClear
}: SidebarFilterProps) {
// define state for managing filter drawer
const [open, setOpen] = useState(false);
return (
<>
<SetFilterButton
count={count}
label="Filters"
onClick={() => setOpen(true)}
/>
<Drawer
variant="temporary"
anchor="right"
data-testid="filter-sidebar-drawer"
open={open}
onClose={() => setOpen(false)}
sx={{
"& .MuiDrawer-paper": {
width: 450
}
}}
>
<Stack
sx={{
flex: 1,
overflow: "hidden"
}}
>
<Stack
sx={{
px: 3,
py: 2
}}
>
<Typography
variant="h6"
sx={{
fontWeight: 600
}}
>
Filters
</Typography>
<IconButton
data-testid="filter-close-button"
onClick={() => setOpen(false)}
sx={{
position: "absolute",
right: 12,
top: 12
}}
>
<Close />
</IconButton>
</Stack>
<Divider />
<Stack
sx={{
flex: 1,
gap: 2,
overflow: "auto",
padding: 3
}}
>
{children}
</Stack>
{count > 0 ? (
<>
<Divider />
<ClearFilterButton onClick={onClear} />
</>
) : null}
</Stack>
</Drawer>
</>
);
}