From 75df0cc4453273f059c839b4fd856cb35c51f397 Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 7 Sep 2020 21:02:28 -0700 Subject: [PATCH] create nav menu, move dark/light toggle to left --- src/app/PageLayout.js | 97 +++++++++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 27 deletions(-) diff --git a/src/app/PageLayout.js b/src/app/PageLayout.js index 49d5a1e..6163ea4 100644 --- a/src/app/PageLayout.js +++ b/src/app/PageLayout.js @@ -1,8 +1,24 @@ import React from "react"; -import { Box, Button, HStack, IconButton, useColorMode } from "@chakra-ui/core"; +import { + Box, + Button, + HStack, + IconButton, + Menu, + MenuButton, + MenuItem, + MenuList, + useBreakpointValue, + useColorMode, +} from "@chakra-ui/core"; import { Link, useLocation } from "react-router-dom"; import { useAuth0 } from "@auth0/auth0-react"; -import { ChevronLeftIcon, MoonIcon, SunIcon } from "@chakra-ui/icons"; +import { + ChevronLeftIcon, + HamburgerIcon, + MoonIcon, + SunIcon, +} from "@chakra-ui/icons"; import useCurrentUser from "./components/useCurrentUser"; @@ -10,6 +26,8 @@ import HomeLinkIcon from "../images/home-link-icon.png"; import HomeLinkIcon2x from "../images/home-link-icon@2x.png"; function PageLayout({ children }) { + const navStyle = useBreakpointValue({ base: "menu", md: "buttons" }); + return ( - - Modeling - + {navStyle === "menu" && } + {navStyle === "buttons" && } @@ -103,7 +120,6 @@ function UserNavBarSection() { Hi, {username}! )} - {id && ( ); } else { - return ( - - - loginWithRedirect()}>Log in - - ); + return loginWithRedirect()}>Log in; } } -function ColorModeToggleButton() { +function NavMenu() { const { colorMode, toggleColorMode } = useColorMode(); return ( - : } - onClick={toggleColorMode} - /> + + } /> + + + Modeling + + + {colorMode === "light" ? ( + + Dark mode + + + ) : ( + + Light mode + + + )} + + + ); } -function NavButton({ kind = "Button", ...props }) { - const Component = kind === "IconButton" ? IconButton : Button; +function NavButtons() { + const { colorMode, toggleColorMode } = useColorMode(); + + return ( + <> + + Modeling + + : } + onClick={toggleColorMode} + /> + + ); +} + +const NavButton = React.forwardRef(({ icon, ...props }, ref) => { + const Component = icon ? IconButton : Button; return ( // Opacity is in a separate Box, to avoid overriding the built-in Button // hover/focus states. - + ); -} +}); export default PageLayout;