Skip to content

Commit bbbdafc

Browse files
committed
chore: create catalog filter sidebar
Signed-off-by: Amit Amrutiya <amitamrutiya2210@gmail.com>
1 parent c4ee39a commit bbbdafc

1 file changed

Lines changed: 123 additions & 0 deletions

File tree

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import FilterAltIcon from '@mui/icons-material/FilterAlt';
2+
import { useCallback, useState } from 'react';
3+
import { Box, Drawer, Typography } from '../../base';
4+
import { CloseIcon } from '../../icons';
5+
import { CULTURED, DARK_SLATE_GRAY, WHITE } from '../../theme';
6+
import { CloseBtn } from '../Modal';
7+
import CatalogFilterSidebarState from './CatalogFilterSidebarState';
8+
import {
9+
FilterButton,
10+
FilterDrawerDiv,
11+
FilterText,
12+
FiltersCardDiv,
13+
FiltersDrawerHeader
14+
} from './style';
15+
16+
export interface FilterOption {
17+
value: string;
18+
label: string;
19+
totalCount?: number;
20+
description?: string;
21+
Icon?: React.ComponentType<{
22+
width: string;
23+
height: string;
24+
}>;
25+
}
26+
27+
export interface FilterList {
28+
filterKey: string;
29+
sectionDisplayName?: string;
30+
options: FilterOption[];
31+
defaultOpen?: boolean;
32+
isMultiSelect?: boolean;
33+
}
34+
35+
export interface CatalogFilterSidebarProps {
36+
setData: (callback: (prevFilters: FilterValues) => FilterValues) => void;
37+
lists: FilterList[];
38+
value?: FilterValues;
39+
}
40+
41+
export type FilterValues = Record<string, string | string[]>;
42+
43+
export interface StyleProps {
44+
backgroundColor?: string;
45+
sectionTitleBackgroundColor?: string;
46+
}
47+
48+
/**
49+
* @function CatalogFilterSidebar
50+
* @description A functional component that renders the filter sidebar.
51+
* @param {Array} value - The data to be filtered.
52+
* @param {Function} setData - A function to set the filtered data.
53+
* @param {Array} lists - An array of filter sections and it's options lists.
54+
*/
55+
const CatalogFilterSidebar: React.FC<CatalogFilterSidebarProps> = ({
56+
lists,
57+
setData,
58+
value = {}
59+
}) => {
60+
const [openDrawer, setOpenDrawer] = useState<boolean>(false);
61+
62+
const handleDrawerOpen = useCallback(() => {
63+
setOpenDrawer(true);
64+
}, []);
65+
66+
const handleDrawerClose = useCallback(() => {
67+
setOpenDrawer(false);
68+
}, []);
69+
70+
const styleProps: StyleProps = {
71+
backgroundColor: WHITE,
72+
sectionTitleBackgroundColor: CULTURED
73+
};
74+
75+
return (
76+
<>
77+
<FiltersCardDiv styleProps={styleProps}>
78+
<CatalogFilterSidebarState
79+
lists={lists}
80+
onApplyFilters={setData}
81+
value={value}
82+
styleProps={styleProps}
83+
/>
84+
</FiltersCardDiv>
85+
<FilterDrawerDiv>
86+
<FilterButton variant="contained" onClick={handleDrawerOpen}>
87+
<FilterAltIcon height="20" width="20" fill={WHITE} />
88+
<FilterText>Filters</FilterText>
89+
</FilterButton>
90+
91+
<Drawer anchor="bottom" open={openDrawer} variant="temporary" onClose={handleDrawerClose}>
92+
<Box sx={{ overflowY: 'hidden', height: '90vh' }}>
93+
<FiltersDrawerHeader>
94+
<Typography variant="h6" sx={{ color: WHITE }} component="div">
95+
Filters
96+
</Typography>
97+
<CloseBtn onClick={handleDrawerClose}>
98+
<CloseIcon height={'32px'} width={'32px'} />
99+
</CloseBtn>
100+
</FiltersDrawerHeader>
101+
<Box
102+
style={{
103+
height: '75vh',
104+
overflowY: 'auto',
105+
background: WHITE
106+
}}
107+
>
108+
<CatalogFilterSidebarState
109+
lists={lists}
110+
onApplyFilters={setData}
111+
value={value}
112+
styleProps={styleProps}
113+
/>
114+
</Box>
115+
<Box sx={{ backgroundColor: DARK_SLATE_GRAY, height: '5vh' }} />
116+
</Box>
117+
</Drawer>
118+
</FilterDrawerDiv>
119+
</>
120+
);
121+
};
122+
123+
export default CatalogFilterSidebar;

0 commit comments

Comments
 (0)