Skip to content

Commit c35e55e

Browse files
committed
Implemented hamburger menu for mobile nav sadanandpai#399
1 parent a0f18c3 commit c35e55e

File tree

4 files changed

+1007
-17
lines changed

4 files changed

+1007
-17
lines changed

apps/host/src/components/common/navbar/navbar.module.scss

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,41 @@
3737
.links {
3838
display: none;
3939
}
40-
40+
/* For desktop view */
4141
.github {
4242
display: flex;
4343
align-items: center;
4444
justify-content: center;
4545
width: var(--icon-container-size);
4646
height: var(--icon-container-size);
4747
color: var(--text-body);
48+
}
49+
50+
.github > svg {
51+
width: var(--github-svg-size);
52+
height: var(--github-svg-size);
53+
}
54+
55+
/* For mobile view */
56+
.hamburger {
57+
display: none;
58+
}
59+
60+
@media screen and (max-width: 768px) {
61+
.github {
62+
display: none;
63+
}
4864

65+
.hamburger {
66+
display: flex;
67+
align-items: center;
68+
justify-content: center;
69+
width: var(--icon-container-size);
70+
height: var(--icon-container-size);
71+
color: var(--text-body);
72+
}
4973

50-
& > svg {
74+
.hamburger > svg {
5175
width: var(--github-svg-size);
5276
height: var(--github-svg-size);
5377
}
@@ -70,3 +94,38 @@
7094
}
7195
}
7296
}
97+
.right:first-child {
98+
display: flex;
99+
}
100+
101+
.drawerContent {
102+
padding: 1rem; // Adjust as needed
103+
}
104+
105+
.drawerList {
106+
list-style-type: none;
107+
padding: 0;
108+
margin: 0;
109+
}
110+
111+
.drawerListItem {
112+
margin-bottom: 1rem; // Adjust as needed
113+
}
114+
.ant-drawer-close {
115+
justify-content: flex-end;
116+
padding-left: 50px;
117+
margin-left: 500px;
118+
}
119+
.ant-drawer-header {
120+
display: flex;
121+
justify-content: space-between;
122+
align-items: center;
123+
124+
.ant-drawer-title {
125+
justify-content: flex-start;
126+
}
127+
128+
.ant-drawer-close {
129+
justify-content: flex-end;
130+
}
131+
}

apps/host/src/components/common/navbar/navbar.tsx

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,62 @@
1-
import styles from "./navbar.module.scss";
1+
import React, { useState } from 'react';
2+
import { Drawer, Button } from 'antd';
3+
import { MenuOutlined, CloseOutlined } from '@ant-design/icons';
4+
import styles from './navbar.module.scss';
5+
6+
function Navbar({ children, title }: { children?: React.ReactNode; title?: string }) {
7+
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
8+
9+
const toggleDrawer = () => {
10+
setIsDrawerOpen(!isDrawerOpen);
11+
};
212

3-
function Navbar({ children, title }: { children?: React.ReactNode, title?: string }) {
413
return (
514
<nav className={styles.navbar}>
6-
<a className={styles.logo} href="/frontend-mini-challenges/">
15+
<div className={styles.logo}>
716
<img
817
src="https://github.com/sadanandpai/frontend-mini-challenges/raw/main/shared/assets/logo.png"
918
alt="logo"
19+
className={styles.logoImage}
1020
/>
1121
<span>{title ?? 'Frontend Mini Challenges'}</span>
12-
</a>
13-
22+
</div>
1423
<div className={styles.right}>
1524
<div className={styles.links}>{children}</div>
16-
1725
<a
1826
href="https://github.com/sadanandpai/frontend-mini-challenges/"
1927
target="blank"
2028
className={styles.github}
2129
>
22-
<svg
23-
xmlns="http://www.w3.org/2000/svg"
24-
width="24"
25-
height="24"
26-
viewBox="0 0 24 24"
27-
>
30+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
2831
<path
2932
fill="currentColor"
3033
d="M12 2A10 10 0 0 0 2 12c0 4.42 2.87 8.17 6.84 9.5c.5.08.66-.23.66-.5v-1.69c-2.77.6-3.36-1.34-3.36-1.34c-.46-1.16-1.11-1.47-1.11-1.47c-.91-.62.07-.6.07-.6c1 .07 1.53 1.03 1.53 1.03c.87 1.52 2.34 1.07 2.91.83c.09-.65.35-1.09.63-1.34c-2.22-.25-4.55-1.11-4.55-4.92c0-1.11.38-2 1.03-2.71c-.1-.25-.45-1.29.1-2.64c0 0 .84-.27 2.75 1.02c.79-.22 1.65-.33 2.5-.33c.85 0 1.71.11 2.5.33c1.91-1.29 2.75-1.02 2.75-1.02c.55 1.35.2 2.39.1 2.64c.65.71 1.03 1.6 1.03 2.71c0 3.82-2.34 4.66-4.57 4.91c.36.31.69.92.69 1.85V21c0 .27.16.59.67.5C19.14 20.16 22 16.42 22 12A10 10 0 0 0 12 2Z"
3134
/>
3235
</svg>
3336
</a>
3437
</div>
38+
<div className={styles.hamburger}>
39+
<Button type="text" icon={<MenuOutlined />} onClick={toggleDrawer} />
40+
</div>
41+
42+
<Drawer
43+
title="Menu"
44+
placement="right"
45+
closable={true}
46+
onClose={toggleDrawer}
47+
visible={isDrawerOpen}
48+
width="50%"
49+
>
50+
<div className={styles.drawerContent}>
51+
<ul className={styles.drawerList}>
52+
{React.Children.map(children, (child, index) => (
53+
<li key={index} className={styles.drawerListItem}>
54+
{child}
55+
</li>
56+
))}
57+
</ul>
58+
</div>
59+
</Drawer>
3560
</nav>
3661
);
3762
}

0 commit comments

Comments
 (0)