Skip to content

Commit aae6c4b

Browse files
committed
Add sidenav functionality for mobile view
1 parent 7835862 commit aae6c4b

File tree

5 files changed

+73
-3
lines changed

5 files changed

+73
-3
lines changed

components/Header.tsx

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
/* eslint-disable @next/next/no-sync-scripts */
2+
import { useState } from "react";
23
import Link from "next/link";
34
import Image from "next/image";
5+
import { MenuIcon, XIcon } from "@heroicons/react/outline";
46
import Coffee from "./Coffee";
57
import styles from "../styles/Coffee.module.css";
68

79
const Header = () => {
10+
const [isOpen, setIsOpen] = useState(false);
11+
const toggleSideNav = () => {
12+
setIsOpen(!isOpen);
13+
};
14+
815
return (
916
<>
1017
<nav className="bg-slate-950 text-slate-50 backdrop-blur">
@@ -22,7 +29,16 @@ const Header = () => {
2229
</div>
2330
</Link>
2431
</div>
25-
<nav>
32+
<div className="md:hidden">
33+
<button onClick={toggleSideNav}>
34+
{isOpen ? (
35+
<XIcon className="h-6 w-6" />
36+
) : (
37+
<MenuIcon className="h-6 w-6" />
38+
)}
39+
</button>
40+
</div>
41+
<nav className="hidden md:block">
2642
<ul className="md:flex items-center space-x-1">
2743
<li>
2844
<Link href="/getting-started">
@@ -49,8 +65,50 @@ const Header = () => {
4965
</div>
5066
</div>
5167
</nav>
52-
<header className="bg-slate-950 text-slate-50 sticky top-0 z-10">
53-
<div className="container mx-auto px-6 py-3 pb-6">
68+
{isOpen && (
69+
<div className="fixed top-0 left-0 w-64 h-full pt-6 text-slate-50 bg-slate-900 overflow-auto z-20 md:hidden">
70+
<div className="ml-6 mb-6">
71+
<div className={styles.buyButton}>
72+
<Coffee />
73+
</div>
74+
</div>
75+
<Link href="/getting-started">
76+
<div className="py-2 px-6 block text-sm cursor-pointer hover:underline">
77+
Getting Started
78+
</div>
79+
</Link>
80+
<Link
81+
href="https://github.com/nikohoffren/devgallery.io"
82+
target="blank"
83+
>
84+
<div className="py-2 px-6 block text-sm cursor-pointer hover:underline">
85+
Contribute in GitHub
86+
</div>
87+
</Link>
88+
<Link href="/projects">
89+
<div className="py-2 px-6 block text-sm cursor-pointer hover:underline">
90+
Projects
91+
</div>
92+
</Link>
93+
<Link href="/developers">
94+
<div className="py-2 px-6 block text-sm cursor-pointer hover:underline">
95+
Developers
96+
</div>
97+
</Link>
98+
<Link href="/about">
99+
<div className="py-2 px-6 block text-sm cursor-pointer hover:underline">
100+
About
101+
</div>
102+
</Link>
103+
<Link href="/contact">
104+
<div className="py-2 px-6 block text-sm cursor-pointer hover:underline">
105+
Contact
106+
</div>
107+
</Link>
108+
</div>
109+
)}
110+
<header className="bg-slate-950 text-slate-50 sticky top-0 z-10 hidden md:block">
111+
<div className="container mx-auto px-6 py-1 pb-6">
54112
<div className="mt-3 md:flex items-center space-x-1 justify-end">
55113
<Link href="/projects">
56114
<div className="py-2 px-6 block text-sm cursor-pointer hover:underline">

declarations.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module "@heroicons/react/outline";

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12+
"@heroicons/react": "^1.0.6",
1213
"@types/node": "20.4.5",
1314
"@types/react": "18.2.16",
1415
"@types/react-dom": "18.2.7",

styles/Coffee.module.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
border-radius: 6px;
66
padding: 0.2rem;
77
box-shadow: 0px 1px 2px rgba(190, 190, 190, 0.5);
8+
width: 2rem;
89
}
910

1011
.buyButton:hover,

0 commit comments

Comments
 (0)