-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathSearchSubMenu.tsx
57 lines (52 loc) · 1.75 KB
/
SearchSubMenu.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
import * as React from 'react';
import { Box } from '@mui/material';
import { SearchWithResult, SearchResultsPanel } from '@react-admin/ra-search';
import {
CommandListItem,
CustomerListItem,
ProductListItem,
ReviewListItem,
} from './SearchItems';
import { useSolarSidebarActiveMenu } from '@react-admin/ra-navigation';
export const SearchSubMenu = () => {
const [, setActiveMenu] = useSolarSidebarActiveMenu();
const handleClose = () => {
setActiveMenu('');
};
return (
<Box data-testid="search" m={-1} width={{ xs: '100%', md: 270 }}>
<SearchWithResult onNavigate={handleClose} sx={{ m: 1 }}>
<SearchResultsPanel
sx={{
maxHeight: 'calc(100vh - 65px)',
overflowX: 'hidden',
marginBlockEnd: 0,
px: 1,
}}
disablePadding
data-testid="search-panel"
>
<CustomSearchResultItem />
</SearchResultsPanel>
</SearchWithResult>
</Box>
);
};
const CustomSearchResultItem = (props: any) => {
const { data, onClose, ...rest } = props;
if (!data) {
return null;
}
switch (data.type) {
case 'customers':
return <CustomerListItem {...rest} data={data} onClick={onClose} />;
case 'products':
return <ProductListItem {...rest} data={data} onClick={onClose} />;
case 'orders':
return <CommandListItem {...rest} data={data} onClick={onClose} />;
case 'reviews':
return <ReviewListItem {...rest} data={data} onClick={onClose} />;
default:
return null;
}
};