Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | 2x 2x 2x | import * as React from "react";
import { palette } from "@palette";
// assets
import {
SortIcon,
SortUpIconV2,
SortDownIconV2,
ArrowForwardUp,
ArrowForwardDown,
CheckMarkIcon,
} from "@assets/icons";
import { DropdownItem } from "@common/Select";
import { Text } from "@common/Text";
import { Menu, Stack, Box } from "@mui/material";
import { Button } from "@common/Button";
type MobileRevenueSortMenuProps = {
setSelectedSortIcon: React.Dispatch<React.SetStateAction<JSX.Element>>;
anchorEl: null | HTMLElement;
setAnchorEl: React.Dispatch<React.SetStateAction<null | HTMLElement>>;
};
const MobileRevenueSortMenu = ({
setSelectedSortIcon,
anchorEl,
setAnchorEl,
}: MobileRevenueSortMenuProps) => {
const [sortList, setSortList] = React.useState(initialSortList);
const openMenu = Boolean(anchorEl);
const checkSortType = (type: string, subType: string): void => {
const updatedSortList = sortList.map((item) => {
if (item.type === type) {
if (subType === "up") {
!item.subType.up === true
? setSelectedSortIcon(<SortUpIconV2 />)
: setSelectedSortIcon(<SortIcon />);
return {
...item,
subType: { up: !item.subType.up, down: false },
};
}
!item.subType.down === true
? setSelectedSortIcon(<SortDownIconV2 />)
: setSelectedSortIcon(<SortIcon />);
return {
...item,
subType: { down: !item.subType.down, up: false },
};
}
return {
...item,
subType: { down: false, up: false },
};
});
setSortList(updatedSortList);
};
const clearFilters = () => {
setSortList(initialSortList);
setSelectedSortIcon(<SortIcon />);
};
return (
<Menu
open={openMenu}
anchorEl={anchorEl}
onClose={() => setAnchorEl(null)}
anchorOrigin={{
vertical: "bottom",
horizontal: "right",
}}
transformOrigin={{
vertical: "top",
horizontal: "right",
}}
sx={{
"& .MuiPaper-root": {
width: 172,
},
}}
>
{sortList.map((item) => (
<Box key={item.type}>
<DropdownItem
disabled
sx={{
"&.Mui-disabled": {
opacity: 1,
},
}}
>
<Text sx={sortTypeStyle}>{item.type}</Text>
</DropdownItem>
<DropdownItem onClick={() => checkSortType(item.type, "up")}>
<Stack
direction="row"
spacing={0.5}
alignItems="center"
height="100%"
>
<ArrowForwardUp />
<Text
sx={{
flexGrow: 1,
fontWeight: item.subType.up ? "500" : "400",
}}
>
Low to high
</Text>
{item.subType.up && <CheckMarkIcon fill="#4C4A52" />}
</Stack>
</DropdownItem>
<DropdownItem onClick={() => checkSortType(item.type, "down")}>
<Stack
direction="row"
spacing={0.5}
alignItems="center"
height="100%"
>
<ArrowForwardDown />
<Text
sx={{
flexGrow: 1,
fontWeight: item.subType.down ? "500" : "400",
}}
>
High to low
</Text>
{item.subType.down && <CheckMarkIcon fill="#4C4A52" />}
</Stack>
</DropdownItem>
</Box>
))}
<Button
variant="text"
fullWidth
sx={{ fontWeight: 400, color: palette.neutral[600] }}
onClick={clearFilters}
>
Clear Filters
</Button>
</Menu>
);
};
const initialSortList = [
{ type: "Source", subType: { up: false, down: false } },
{ type: "Amount", subType: { up: false, down: false } },
{ type: "Average", subType: { up: false, down: false } },
];
const sortTypeStyle = {
color: palette.primary[400],
fontSize: 12,
fontWeight: "400",
};
export default MobileRevenueSortMenu;
|