eli02 commited on
Commit
bdd9b98
·
1 Parent(s): c6fb72f

feat: Add responsive drawer navigation to Header component

Browse files
Files changed (1) hide show
  1. src/components/Layout/Header.jsx +43 -10
src/components/Layout/Header.jsx CHANGED
@@ -1,13 +1,17 @@
1
- import React from 'react';
2
- import {
3
- AppBar,
4
- Toolbar,
5
- Typography,
6
- Button,
7
- IconButton,
8
  Box,
9
  useScrollTrigger,
10
- Slide
 
 
 
 
11
  } from '@mui/material';
12
  import MenuIcon from '@mui/icons-material/Menu';
13
  import { useAuth } from '../../hooks/useAuth';
@@ -25,6 +29,19 @@ function HideOnScroll({ children }) {
25
 
26
  const Header = () => {
27
  const { isAuthenticated, logout } = useAuth();
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  return (
30
  <HideOnScroll>
@@ -33,8 +50,9 @@ const Header = () => {
33
  <IconButton
34
  edge="start"
35
  color="inherit"
36
- aria-label="menu"
37
- sx={{ mr: 2 }}
 
38
  >
39
  <MenuIcon />
40
  </IconButton>
@@ -96,6 +114,21 @@ const Header = () => {
96
  <ThemeToggle />
97
  </Box>
98
  </Toolbar>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  </AppBar>
100
  </HideOnScroll>
101
  );
 
1
+ import React, { useState } from 'react';
2
+ import {
3
+ AppBar,
4
+ Toolbar,
5
+ Typography,
6
+ Button,
7
+ IconButton,
8
  Box,
9
  useScrollTrigger,
10
+ Slide,
11
+ Drawer,
12
+ List,
13
+ ListItemButton,
14
+ ListItemText
15
  } from '@mui/material';
16
  import MenuIcon from '@mui/icons-material/Menu';
17
  import { useAuth } from '../../hooks/useAuth';
 
29
 
30
  const Header = () => {
31
  const { isAuthenticated, logout } = useAuth();
32
+ const [drawerOpen, setDrawerOpen] = useState(false);
33
+
34
+ const toggleDrawer = (open) => (event) => {
35
+ if (event.type === 'keydown' && (event.key === 'Tab' || event.key === 'Shift')) {
36
+ return;
37
+ }
38
+ setDrawerOpen(open);
39
+ };
40
+
41
+ const handleLogoutMobile = () => {
42
+ logout();
43
+ setDrawerOpen(false);
44
+ };
45
 
46
  return (
47
  <HideOnScroll>
 
50
  <IconButton
51
  edge="start"
52
  color="inherit"
53
+ aria-label="open navigation"
54
+ onClick={toggleDrawer(true)}
55
+ sx={{ mr: 2, display: { xs: 'block', sm: 'none' } }}
56
  >
57
  <MenuIcon />
58
  </IconButton>
 
114
  <ThemeToggle />
115
  </Box>
116
  </Toolbar>
117
+ <Drawer anchor="left" open={drawerOpen} onClose={toggleDrawer(false)}>
118
+ <Box sx={{ width: 250 }} role="presentation" onClick={toggleDrawer(false)} onKeyDown={toggleDrawer(false)}>
119
+ <List>
120
+ <ListItemButton component={Link} to="/about"><ListItemText primary="About" /></ListItemButton>
121
+ {isAuthenticated ? (
122
+ <>
123
+ <ListItemButton component={Link} to="/dashboard"><ListItemText primary="Dashboard" /></ListItemButton>
124
+ <ListItemButton onClick={handleLogoutMobile}><ListItemText primary="Logout" /></ListItemButton>
125
+ </>
126
+ ) : (
127
+ <ListItemButton component={Link} to="/login"><ListItemText primary="Login" /></ListItemButton>
128
+ )}
129
+ </List>
130
+ </Box>
131
+ </Drawer>
132
  </AppBar>
133
  </HideOnScroll>
134
  );