Skip to content

Commit 400f996

Browse files
committed
Add a responsive navigation bar
1 parent 0b11a8e commit 400f996

File tree

3 files changed

+59
-23
lines changed

3 files changed

+59
-23
lines changed

src/components/nav-bar.tsx

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
1+
import React, { useState } from 'react';
12
import styles from '@/styles/nav-bar.module.css';
23

34
export default function Navbar() {
5+
const [isOpen, setOpen] = useState(true);
6+
7+
function handleMenuClick() {
8+
setOpen(!isOpen);
9+
}
10+
411
return (
512
<div className={styles.nav}>
613
<div className={styles.title}>
714
<a href="">pygame</a>
815
</div>
9-
<ul>
10-
<li>
11-
<a href="docs">Documentation</a>
12-
</li>
13-
<li>
14-
<a href="tutorials">Tutorials</a>
15-
</li>
16-
<li>
17-
<a href="https://github.com/pygame-community/pygame-ce">Contribute</a>
18-
</li>
19-
</ul>
16+
<div className={styles.mobilemenuicon} onClick={handleMenuClick}>
17+
<span className="material-symbols-outlined">menu</span>
18+
</div>
19+
<div className={isOpen ? styles.routes : styles.mobileroutes}>
20+
<ul>
21+
<li>
22+
<a href="docs">Documentation</a>
23+
</li>
24+
<li>
25+
<a href="tutorials">Tutorials</a>
26+
</li>
27+
<li>
28+
<a href="https://github.com/pygame-community/pygame-ce">Contribute</a>
29+
</li>
30+
</ul>
31+
</div>
2032
</div>
2133
);
2234
}

src/pages/_document.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import { Html, Head, Main, NextScript } from 'next/document';
33
export default function Document() {
44
return (
55
<Html lang="en">
6-
<Head />
6+
<Head>
7+
<link
8+
rel="stylesheet"
9+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,600,0,0&display=swap"
10+
/>
11+
</Head>
712
<body>
813
<Main />
914
<NextScript />

src/styles/nav-bar.module.css

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
display: flex;
33
color: white;
44
justify-content: space-between;
5-
gap: 2rem;
6-
width: 100vw;
75
padding: 0 75px;
86
height: 10vh;
97
align-items: center;
@@ -14,30 +12,37 @@
1412
font-size: 1.5rem;
1513
}
1614

15+
.mobilemenuicon {
16+
display: none;
17+
}
18+
1719
.nav ul {
20+
display: flex;
1821
font-size: 1.05rem;
19-
padding: 0;
20-
margin: 0;
2122
list-style: none;
22-
display: flex;
23-
gap: 1rem;
23+
gap: 16px;
2424
}
2525

2626
.nav a {
27-
color: inherit;
27+
color: white;
2828
text-decoration: none;
29-
height: 100%;
3029
display: flex;
3130
align-items: center;
32-
padding: 0.25rem;
31+
padding: 4px;
3332
opacity: 1;
34-
transition: 0.5s;
33+
transition: 500ms;
3534
}
3635

3736
.nav a:hover {
3837
color: #dedede;
3938
}
4039

40+
.mobileroutes a {
41+
padding-top: 8px;
42+
padding-bottom: 8px;
43+
text-align: left;
44+
}
45+
4146
/* Ultra Small
4247
-----------------------*/
4348
@media only screen and (max-width: 600px) {
@@ -46,6 +51,20 @@
4651
}
4752

4853
.nav {
49-
justify-content: center;
54+
display: block;
55+
justify-content: baseline;
56+
padding: 35px 35px;
57+
}
58+
59+
.nav .mobilemenuicon {
60+
display: block;
61+
}
62+
63+
.nav ul {
64+
display: block;
65+
}
66+
67+
.nav .routes {
68+
display: none;
5069
}
5170
}

0 commit comments

Comments
 (0)