import { useAnimation } from "framer-motion";
import React, { useEffect } from "react";
import { Flex, Box, Text } from "rebass";
import { isUserPremium } from "../../common";
import useMobile from "../../utils/use-mobile";
import Animated from "../animated";
function Menu(props) {
const isMobile = useMobile();
const Container = isMobile ? MobileMenuContainer : MenuContainer;
return (
{props.menuItems.map(
(item) =>
item.visible !== false && (
{
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 ? (
item.component
) : (
{item.title}
)}
{item.onlyPro && !isUserPremium() && (
Pro
)}
)
)}
);
}
export default Menu;
function MenuContainer(props) {
return (
Properties
{props.children}
);
}
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 (
Properties
{props.children}
);
}