diff --git a/apps/web/src/components/menu/index.js b/apps/web/src/components/menu/index.js
index 7c0b2c74d..9c0d8445f 100644
--- a/apps/web/src/components/menu/index.js
+++ b/apps/web/src/components/menu/index.js
@@ -1,16 +1,6 @@
-import { useAnimation } from "framer-motion";
-import { Check, ChevronRight, Pro } from "../icons";
-import React, {
- useCallback,
- useEffect,
- useMemo,
- useRef,
- useState,
-} from "react";
-import { Flex, Box, Text, Button } from "rebass";
-import useMobile from "../../utils/use-mobile";
-import { AnimatedFlex } from "../animated";
-import { getPosition } from "../../hooks/use-menu";
+import React, { useCallback, useEffect, useState } from "react";
+import { Flex, Text } from "rebass";
+import MenuItem from "./menu-item";
function useMenuFocus(items) {
const [focusIndex, setFocusIndex] = useState(-1);
@@ -73,17 +63,11 @@ function useMenuFocus(items) {
}
function Menu({ items, data, closeMenu }) {
- const isMobile = useMobile();
const [focusIndex, setFocusIndex, isSubmenuOpen, setIsSubmenuOpen] =
useMenuFocus(items);
- const Container = useMemo(
- () => (isMobile ? MobileMenuContainer : MenuContainer),
- [isMobile]
- );
-
return (
-
+
{items.map((item, index) => (
))}
-
+
);
}
export default React.memo(Menu);
@@ -141,191 +125,3 @@ function MenuContainer({ title, children }) {
);
}
-
-function MobileMenuContainer({ style, id, state, title, children }) {
- 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 (
-
-
-
-
-
- {title || "Properties"}
-
- {children}
-
-
-
- );
-}
-
-function MenuItem({ item, data, isFocused, isSubmenuOpen, onClose, onHover }) {
- const {
- title,
- key,
- onClick,
- color,
- items,
- icon: Icon,
- iconColor,
- type,
- tooltip,
- isDisabled,
- isChecked,
- hasSubmenu,
- isPremium,
- } = item;
- const itemRef = useRef();
- const subMenuRef = useRef();
-
- useEffect(() => {
- if (isFocused) itemRef.current?.focus();
- }, [isFocused]);
-
- useEffect(() => {
- if (!subMenuRef.current) return;
- if (!isSubmenuOpen) {
- subMenuRef.current.style.visibility = "hidden";
- return;
- }
-
- const { top, left } = getPosition(
- subMenuRef.current,
- itemRef.current,
- "right"
- );
-
- subMenuRef.current.style.visibility = "visible";
- subMenuRef.current.style.top = `${top}px`;
- subMenuRef.current.style.left = `${left}px`;
- }, [isSubmenuOpen]);
-
- const onAction = useCallback(
- (e) => {
- e.stopPropagation();
- if (onClose) onClose();
- if (onClick) onClick(data, item);
- },
- [onClick, onClose, item, data]
- );
-
- if (type === "seperator")
- return (
-
- );
-
- return (
-
-
- {hasSubmenu && (
-
-
-
- )}
-
- );
-}
diff --git a/apps/web/src/components/menu/menu-item.js b/apps/web/src/components/menu/menu-item.js
new file mode 100644
index 000000000..2738110b4
--- /dev/null
+++ b/apps/web/src/components/menu/menu-item.js
@@ -0,0 +1,136 @@
+import { Check, ChevronRight, Pro } from "../icons";
+import React, { useCallback, useEffect, useRef } from "react";
+import { Flex, Box, Text, Button } from "rebass";
+import { getPosition } from "../../hooks/use-menu";
+import Menu from "./index";
+
+function MenuItem({ item, data, isFocused, isSubmenuOpen, onClose, onHover }) {
+ const {
+ title,
+ key,
+ onClick,
+ color,
+ items,
+ icon: Icon,
+ iconColor,
+ type,
+ tooltip,
+ isDisabled,
+ isChecked,
+ hasSubmenu,
+ isPremium,
+ } = item;
+ const itemRef = useRef();
+ const subMenuRef = useRef();
+
+ useEffect(() => {
+ if (isFocused) itemRef.current?.focus();
+ }, [isFocused]);
+
+ useEffect(() => {
+ if (!subMenuRef.current) return;
+ if (!isSubmenuOpen) {
+ subMenuRef.current.style.visibility = "hidden";
+ return;
+ }
+
+ const { top, left } = getPosition(
+ subMenuRef.current,
+ itemRef.current,
+ "right"
+ );
+
+ subMenuRef.current.style.visibility = "visible";
+ subMenuRef.current.style.top = `${top}px`;
+ subMenuRef.current.style.left = `${left}px`;
+ }, [isSubmenuOpen]);
+
+ const onAction = useCallback(
+ (e) => {
+ e.stopPropagation();
+ if (onClose) onClose();
+ if (onClick) onClick(data, item);
+ },
+ [onClick, onClose, item, data]
+ );
+
+ if (type === "seperator")
+ return (
+
+ );
+
+ return (
+
+
+ {hasSubmenu && (
+
+
+
+ )}
+
+ );
+}
+export default MenuItem;