2020-11-11 10:54:12 +05:00
|
|
|
import { useAnimation } from "framer-motion";
|
|
|
|
|
import React, { useEffect } from "react";
|
2019-12-02 10:19:32 +05:00
|
|
|
import { Flex, Box, Text } from "rebass";
|
2021-01-12 23:21:43 +05:00
|
|
|
import { isUserPremium } from "../../common";
|
2020-11-11 10:54:12 +05:00
|
|
|
import useMobile from "../../utils/use-mobile";
|
|
|
|
|
import Animated from "../animated";
|
2019-12-02 10:19:32 +05:00
|
|
|
|
|
|
|
|
function Menu(props) {
|
2020-11-11 10:54:12 +05:00
|
|
|
const isMobile = useMobile();
|
|
|
|
|
const Container = isMobile ? MobileMenuContainer : MenuContainer;
|
2020-05-15 00:35:20 +05:00
|
|
|
|
2020-11-11 10:54:12 +05:00
|
|
|
return (
|
|
|
|
|
<Container {...props}>
|
|
|
|
|
{props.menuItems.map(
|
|
|
|
|
(item) =>
|
|
|
|
|
item.visible !== false && (
|
|
|
|
|
<Flex
|
|
|
|
|
data-test-id={`menuitem-${item.title
|
|
|
|
|
.split(" ")
|
|
|
|
|
.join("")
|
|
|
|
|
.toLowerCase()}`}
|
|
|
|
|
key={item.title}
|
|
|
|
|
onClick={async (e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
if (props.closeMenu) {
|
|
|
|
|
props.closeMenu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!item.component) {
|
|
|
|
|
item.onClick(props.data);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
flexDirection="row"
|
|
|
|
|
alignItems="center"
|
|
|
|
|
justifyContent="space-between"
|
|
|
|
|
py={"8px"}
|
|
|
|
|
px={3}
|
|
|
|
|
sx={{
|
|
|
|
|
color: item.color || "text",
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
":hover": {
|
|
|
|
|
backgroundColor: "shade",
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{item.component ? (
|
2020-11-26 10:47:04 +05:00
|
|
|
item.component
|
2020-11-11 10:54:12 +05:00
|
|
|
) : (
|
|
|
|
|
<Text as="span" fontFamily="body" fontSize="menu">
|
|
|
|
|
{item.title}
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
2021-01-12 23:21:43 +05:00
|
|
|
{item.onlyPro && !isUserPremium() && (
|
2020-11-11 10:54:12 +05:00
|
|
|
<Text
|
|
|
|
|
fontSize="body"
|
|
|
|
|
bg="primary"
|
|
|
|
|
color="static"
|
|
|
|
|
px={1}
|
|
|
|
|
sx={{ borderRadius: "default" }}
|
|
|
|
|
>
|
|
|
|
|
Pro
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
|
|
|
|
</Flex>
|
|
|
|
|
)
|
|
|
|
|
)}
|
|
|
|
|
</Container>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
export default Menu;
|
|
|
|
|
|
|
|
|
|
function MenuContainer(props) {
|
2019-12-02 10:19:32 +05:00
|
|
|
return (
|
2019-12-19 10:04:46 +05:00
|
|
|
<Flex
|
2020-03-01 20:03:37 +05:00
|
|
|
id={props.id}
|
2020-01-08 15:04:18 +05:00
|
|
|
bg="background"
|
2019-12-19 10:04:46 +05:00
|
|
|
py={1}
|
2020-03-01 20:03:37 +05:00
|
|
|
style={props.style}
|
2019-12-19 10:04:46 +05:00
|
|
|
sx={{
|
|
|
|
|
position: "relative",
|
|
|
|
|
borderRadius: "default",
|
2020-03-28 23:29:04 +05:00
|
|
|
border: "2px solid",
|
|
|
|
|
borderColor: "border",
|
2020-04-21 10:56:43 +05:00
|
|
|
width: 180,
|
2020-04-14 23:36:23 +05:00
|
|
|
...props.sx,
|
2019-12-19 10:04:46 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2020-01-08 15:04:18 +05:00
|
|
|
<Box width="100%">
|
2020-03-02 15:00:53 +05:00
|
|
|
<Text
|
|
|
|
|
fontFamily="body"
|
2020-11-11 10:54:12 +05:00
|
|
|
fontSize="subtitle"
|
2020-03-02 15:00:53 +05:00
|
|
|
color="primary"
|
|
|
|
|
py={"8px"}
|
|
|
|
|
px={3}
|
|
|
|
|
sx={{ borderBottom: "1px solid", borderBottomColor: "border" }}
|
|
|
|
|
>
|
|
|
|
|
Properties
|
|
|
|
|
</Text>
|
2020-11-11 10:54:12 +05:00
|
|
|
{props.children}
|
2019-12-02 10:19:32 +05:00
|
|
|
</Box>
|
|
|
|
|
</Flex>
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-11-11 10:54:12 +05:00
|
|
|
|
|
|
|
|
function MobileMenuContainer(props) {
|
|
|
|
|
const { style, id, state } = props;
|
|
|
|
|
const animation = useAnimation();
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (state === "open") {
|
|
|
|
|
animation.start({ y: 0 });
|
|
|
|
|
const menu = document.getElementById(id);
|
|
|
|
|
menu.style.top = 0;
|
|
|
|
|
menu.style.left = 0;
|
|
|
|
|
} else {
|
|
|
|
|
animation.start({ y: 500 });
|
|
|
|
|
}
|
|
|
|
|
}, [state, animation, id]);
|
|
|
|
|
return (
|
|
|
|
|
<Flex
|
|
|
|
|
flexDirection="column"
|
|
|
|
|
id={id}
|
|
|
|
|
style={style}
|
|
|
|
|
width="100%"
|
|
|
|
|
height="100%"
|
|
|
|
|
bg="overlay"
|
|
|
|
|
overflow="hidden"
|
|
|
|
|
sx={{ position: "relative" }}
|
|
|
|
|
>
|
|
|
|
|
<Animated.Flex
|
|
|
|
|
width="100%"
|
|
|
|
|
bg="background"
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
bottom: 0,
|
|
|
|
|
borderTopLeftRadius: 10,
|
|
|
|
|
borderTopRightRadius: 10,
|
|
|
|
|
overflow: "hidden",
|
|
|
|
|
}}
|
|
|
|
|
initial={{ y: 500 }}
|
|
|
|
|
animate={animation}
|
|
|
|
|
flexDirection="column"
|
|
|
|
|
p={2}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
width={50}
|
|
|
|
|
height={7}
|
|
|
|
|
bg="shade"
|
|
|
|
|
alignSelf="center"
|
|
|
|
|
sx={{ borderRadius: "default" }}
|
|
|
|
|
/>
|
|
|
|
|
<Flex flex="1" flexDirection="column" overflowY="scroll">
|
|
|
|
|
<Text variant="title" mt={2} alignSelf="center">
|
|
|
|
|
Properties
|
|
|
|
|
</Text>
|
|
|
|
|
{props.children}
|
|
|
|
|
</Flex>
|
|
|
|
|
</Animated.Flex>
|
|
|
|
|
</Flex>
|
|
|
|
|
);
|
|
|
|
|
}
|