diff --git a/src/components/MainDrawer/MainDrawer.tsx b/src/components/MainDrawer/MainDrawer.tsx index 7e7e95a..8b584a9 100644 --- a/src/components/MainDrawer/MainDrawer.tsx +++ b/src/components/MainDrawer/MainDrawer.tsx @@ -9,27 +9,24 @@ import { DrawerProps, HStack, IconButton, - List, - ListItem, Stack, Link, } from "@chakra-ui/react"; import Image from "next/image"; -import React, { useContext, useEffect, useState } from "react"; +import React, { useContext, useEffect } from "react"; import { MdMenu } from "react-icons/md"; import logo from "@/assets/logo.svg"; import NextLink from "next/link"; import { AuthContext } from "@/contexts/AuthContext"; import { useRouter } from "next/router"; -import MenuLink from "./MenuLink"; import { menu } from "./menu"; +import SideMenu from "./SideMenu"; type Props = Pick; function MainDrawer({ onClose, isOpen }: Props) { const { user, logout } = useContext(AuthContext); const router = useRouter(); - const [nestedMenuOpen, setNestedMenuOpen] = useState(null); useEffect(() => { onClose(); @@ -57,33 +54,7 @@ function MainDrawer({ onClose, isOpen }: Props) { - - {menu.map((menuItem, menuItemKey) => ( - - { - if (nestedMenuOpen === menuItemKey) { - setNestedMenuOpen(null); - } else { - setNestedMenuOpen(menuItemKey); - } - }} - {...menuItem} - /> - {nestedMenuOpen === menuItemKey && ( - - {menuItem.children && - menuItem.children.map((child, childIndex) => ( - - - - ))} - - )} - - ))} - + { + const [displayChildren, setDisplayChildren] = useState< + Record + >({}); + const router = useRouter(); + + return ( + + {items.map((item) => ( + + {item.children ? ( + + ) : ( + + + {item.icon && ( + + )} + {item.text} + + + )} + {displayChildren[item.text] && item.children && ( + + )} + + ))} + + ); +}; + +export default SideMenu; diff --git a/src/components/MainDrawer/styles.ts b/src/components/MainDrawer/styles.ts new file mode 100644 index 0000000..801a0da --- /dev/null +++ b/src/components/MainDrawer/styles.ts @@ -0,0 +1,12 @@ +import { List, Theme } from "@chakra-ui/react"; +import styled from "@emotion/styled"; + +export const NestedList = styled(List)<{ theme?: Theme }>` + ul { + padding-left: ${({ theme }) => theme.space[3]}; + } + + a { + height: 40px; + } +`; diff --git a/src/config/theme.ts b/src/config/theme.ts index 03fc1b5..7633970 100644 --- a/src/config/theme.ts +++ b/src/config/theme.ts @@ -5,7 +5,7 @@ export const override = { colors: { brand: { 50: "#e7f6fd", // hover - 500: "#478ad2", // button background color + 500: "#478ad2", // button background color, menu link color 600: "#2a69ac", // active }, },