From 79d7a0cf28095d28e5a31ac03ddc4bc2d351588f Mon Sep 17 00:00:00 2001
From: Michal Sapka <michal@sapka.me>
Date: Tue, 9 Aug 2022 23:50:59 +0200
Subject: feat: basic responsive nav

---
 components/topnav.tsx | 91 ++++++++++++++++++++++++++++++---------------------
 1 file changed, 54 insertions(+), 37 deletions(-)

(limited to 'components/topnav.tsx')

diff --git a/components/topnav.tsx b/components/topnav.tsx
index 7daeeb5..e67f603 100644
--- a/components/topnav.tsx
+++ b/components/topnav.tsx
@@ -1,4 +1,22 @@
 import { useState } from 'react'
+import { 
+  Link,
+  Box, 
+  HStack, 
+  IconButton,
+  Menu,
+  Heading,
+  MenuButton,
+  MenuList,
+  MenuItem,
+  MenuItemOption,
+  MenuGroup,
+  MenuOptionGroup,
+  MenuDivider,
+  useMediaQuery,
+} from '@chakra-ui/react'
+import { GiHamburgerMenu } from "react-icons/gi"
+import { DiGithubBadge } from "react-icons/di"
 
 function NavLink({to, children}) {
     return <a href={to} className={`mx-4`}>
@@ -6,45 +24,44 @@ function NavLink({to, children}) {
     </a>
 }
 
-function MobileNav({open, setOpen}) {
-    return (
-        <div className={`absolute top-0 left-0 h-screen w-screen bg-white transform ${open ? "-translate-x-0" : "-translate-x-full"} `}>
-            <div className="flex flex-col ml-4">
-                <a onClick={() => setTimeout(() => {setOpen(!open)}, 100)}>
-                    About
-                </a>
-                <a onClick={() => setTimeout(() => {setOpen(!open)}, 100)}>
-                    Contact
-                </a>
-            </div>  
-        </div>
-    )
+function MobileNav() {
+  return <Menu>
+    <MenuButton as={IconButton} icon={<GiHamburgerMenu/>}>
+      Action
+    </MenuButton>
+    <MenuList>
+      <MenuItem>Publications</MenuItem>
+      <MenuItem icon={<DiGithubBadge/>}>View source</MenuItem>
+    </MenuList>
+  </Menu>
 }
 
-export default function Navbar() {
+function DesktopNav() {
+  return <HStack>
+    <Box>
+      <Link>Publications</Link>
+    </Box>
+    <Box>
+      <Link href="https://github.com/michalsapka/michal-sapka-pl">Source code</Link>
+    </Box>
+  </HStack>
+}
+
+function Navigation() {
+   const [isMobile] = useMediaQuery("(max-width: 768px)")
+
+  let navigationComponent = isMobile ? MobileNav : DesktopNav
 
-    const [open, setOpen] = useState(false)
-    return (
-        <nav>
-            <MobileNav open={open} setOpen={setOpen}/>
-            <div className="w-3/12 flex items-center">Michal</div>
-            <div className="w-9/12 flex justify-end items-center">
-
-                <div className="z-50 flex relative w-8 h-8 flex-col justify-between items-center md:hidden" onClick={() => {
-                    setOpen(!open)
-                }}>
-                    {/* hamburger button */}
-                    <span className={`h-1 w-full bg-black rounded-lg transform transition duration-300 ease-in-out ${open ? "rotate-45 translate-y-3.5" : ""}`} />
-                    <span className={`h-1 w-full bg-black rounded-lg transition-all duration-300 ease-in-out ${open ? "w-0" : "w-full"}`} />
-                    <span className={`h-1 w-full bg-black rounded-lg transform transition duration-300 ease-in-out ${open ? "-rotate-45 -translate-y-3.5" : ""}`} />
-                </div>
-
-                <div className="hidden md:flex">
-                    <NavLink to="/contact">CONTACT</NavLink>
-                    <NavLink to="/about">ABOUT</NavLink>
-                </div>
-            </div>
-        </nav>
-    )
+  
+  return <HStack as="nav">{navigationComponent()}</HStack>
 }
 
+export default function Navbar() {
+  
+  return <HStack backgroundColor="red" width="900px" maxWidth="100%">
+    <Heading>Michal </Heading>
+    <Navigation/>
+  </HStack>
+}
+
+
-- 
cgit v1.2.3

