Browse Source

feat module 6, 7 : smooth the side menu collapse movement - mobile view

master
nadia 7 hours ago
parent
commit
aea56562a7
1 changed files with 24 additions and 7 deletions
  1. 24
    7
      src/components/Navbar/components/MobileNav/MobileNav.jsx

+ 24
- 7
src/components/Navbar/components/MobileNav/MobileNav.jsx View File

1
 import React from "react";
1
 import React from "react";
2
-import { Drawer, Box, List, ListItem, ListItemButton, ListItemText, Accordion, AccordionSummary, AccordionDetails, AccordionActions, Typography, Button } from "@mui/material";
2
+import { Drawer, Box, List, ListItem, ListItemButton, ListItemText, Accordion, AccordionSummary, AccordionDetails, AccordionActions, Typography, Button, Collapse } from "@mui/material";
3
 import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
3
 import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
4
 import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
4
 import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
5
 import Grid from '@mui/material/Grid2';
5
 import Grid from '@mui/material/Grid2';
89
     setExpandedGroup((current) => current === label ? null : label);
89
     setExpandedGroup((current) => current === label ? null : label);
90
   }
90
   }
91
 
91
 
92
+  // Function to generate styles for the collapse content based on expansion state
93
+  const collapseContentSx = (isExpanded) => ({
94
+    opacity: isExpanded ? 1 : 0, // Adjusted opacity for smoother effect
95
+    transform: isExpanded ? "translateY(0)" : "translateY(-4px)", // Adjusted transform for smoother effect
96
+    transition: "opacity 360ms ease, transform 360ms ease" // Adjusted transition duration for smoother effect 
97
+  })
98
+
92
   // React.useEffect(()=>{
99
   // React.useEffect(()=>{
93
 
100
 
94
   //   console.log(menu)
101
   //   console.log(menu)
146
 
153
 
147
   return (
154
   return (
148
     <Drawer
155
     <Drawer
156
+      anchor="left"
149
       open={open}
157
       open={open}
150
       onClose={handleClose}
158
       onClose={handleClose}
159
+      transitionDuration={{
160
+        enter: 600,
161
+        exit: 580
162
+      }}
163
+      ModalProps={{
164
+        keepMounted: true
165
+      }}
151
       sx={{
166
       sx={{
152
         "& .MuiDrawer-paper": {
167
         "& .MuiDrawer-paper": {
153
           backgroundColor: "white",
168
           backgroundColor: "white",
232
                 </Typography>
247
                 </Typography>
233
               </Box>
248
               </Box>
234
 
249
 
235
-              {isMenuExpanded && (
236
-                <Box>
250
+              {/* Menu Items */}
251
+              <Collapse in={isMenuExpanded} timeout={660}> 
252
+                <Box sx={collapseContentSx(isMenuExpanded)}>
237
                   {groups?.map((group) => {
253
                   {groups?.map((group) => {
238
                     const isGroupExpanded = expandedGroup === group.label;
254
                     const isGroupExpanded = expandedGroup === group.label;
239
 
255
 
276
                           </Typography>
292
                           </Typography>
277
                         </Box>
293
                         </Box>
278
 
294
 
279
-                        {isGroupExpanded && (
280
-                          <Box sx={{ ml: 7, pl: 4, borderLeft: "1px solid #777", mb: 2 }}>
295
+                        {/* Group Children */}
296
+                        <Collapse in={isGroupExpanded} timeout={500}>
297
+                          <Box sx={{ ml: 7, pl: 4, borderLeft: "1px solid #777", mb: 2, ...collapseContentSx(isGroupExpanded) }}>
281
                             {group.children.map((item) => (
298
                             {group.children.map((item) => (
282
                               <Button
299
                               <Button
283
                                 key={item.label}
300
                                 key={item.label}
314
                               </Button>
331
                               </Button>
315
                             ))}
332
                             ))}
316
                           </Box>
333
                           </Box>
317
-                        )}
334
+                        </Collapse>
318
                       </Box>
335
                       </Box>
319
                     )
336
                     )
320
                   })}
337
                   })}
353
                     </Box>
370
                     </Box>
354
                   )}
371
                   )}
355
                 </Box>
372
                 </Box>
356
-              )}
373
+              </Collapse>
357
             </Box>
374
             </Box>
358
           )
375
           )
359
         })}
376
         })}

Loading…
Cancel
Save