Files
notesnook/apps/web/src/components/menu/index.js

91 lines
2.5 KiB
JavaScript
Raw Normal View History

2019-12-02 10:19:32 +05:00
import React from "react";
import { Flex, Box, Text } from "rebass";
import { useStore as useUserStore } from "../../stores/user-store";
2019-12-02 10:19:32 +05:00
function Menu(props) {
2020-05-27 10:19:35 +05:00
const isPremium = useUserStore((store) => store.user.isPremium);
const isTrialExpired = useUserStore((store) => store.isTrialExpired);
2019-12-02 10:19:32 +05:00
return (
2019-12-19 10:04:46 +05:00
<Flex
id={props.id}
2020-01-08 15:04:18 +05:00
bg="background"
2019-12-19 10:04:46 +05:00
py={1}
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,
...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"
fontSize="body"
color="primary"
py={"8px"}
px={3}
sx={{ borderBottom: "1px solid", borderBottomColor: "border" }}
>
Properties
</Text>
{props.menuItems.map(
(item) =>
2020-05-16 14:05:06 +05:00
(item.visible === undefined || item.visible === true) && (
<Flex
key={item.title}
onClick={(e) => {
e.stopPropagation();
if (props.closeMenu) {
props.closeMenu();
}
2020-05-27 10:19:35 +05:00
const onlyPro = item.onlyPro && !isPremium && isTrialExpired;
2020-05-15 00:59:04 +05:00
if (onlyPro) {
// TODO
} else if (item.onClick) {
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 data={props.data} />
) : (
<Text as="span" fontFamily="body" fontSize="menu">
{item.title}
</Text>
)}
{item.onlyPro && !isPremium && (
<Text
fontSize="menu"
bg="primary"
color="static"
px={1}
sx={{ borderRadius: "default" }}
>
Pro
</Text>
)}
</Flex>
)
)}
2019-12-02 10:19:32 +05:00
</Box>
</Flex>
);
}
export default Menu;