Explorar el Código

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

master
nadia hace 7 horas
padre
commit
aea56562a7
Se han modificado 1 ficheros con 24 adiciones y 7 borrados
  1. 24
    7
      src/components/Navbar/components/MobileNav/MobileNav.jsx

+ 24
- 7
src/components/Navbar/components/MobileNav/MobileNav.jsx Ver fichero

@@ -1,5 +1,5 @@
1 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 3
 import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
4 4
 import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
5 5
 import Grid from '@mui/material/Grid2';
@@ -89,6 +89,13 @@ const MobileNav = ({ open, onClose, menu = [], infomenu = [], products = [] }) =
89 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 99
   // React.useEffect(()=>{
93 100
 
94 101
   //   console.log(menu)
@@ -146,8 +153,16 @@ const MobileNav = ({ open, onClose, menu = [], infomenu = [], products = [] }) =
146 153
 
147 154
   return (
148 155
     <Drawer
156
+      anchor="left"
149 157
       open={open}
150 158
       onClose={handleClose}
159
+      transitionDuration={{
160
+        enter: 600,
161
+        exit: 580
162
+      }}
163
+      ModalProps={{
164
+        keepMounted: true
165
+      }}
151 166
       sx={{
152 167
         "& .MuiDrawer-paper": {
153 168
           backgroundColor: "white",
@@ -232,8 +247,9 @@ const MobileNav = ({ open, onClose, menu = [], infomenu = [], products = [] }) =
232 247
                 </Typography>
233 248
               </Box>
234 249
 
235
-              {isMenuExpanded && (
236
-                <Box>
250
+              {/* Menu Items */}
251
+              <Collapse in={isMenuExpanded} timeout={660}> 
252
+                <Box sx={collapseContentSx(isMenuExpanded)}>
237 253
                   {groups?.map((group) => {
238 254
                     const isGroupExpanded = expandedGroup === group.label;
239 255
 
@@ -276,8 +292,9 @@ const MobileNav = ({ open, onClose, menu = [], infomenu = [], products = [] }) =
276 292
                           </Typography>
277 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 298
                             {group.children.map((item) => (
282 299
                               <Button
283 300
                                 key={item.label}
@@ -314,7 +331,7 @@ const MobileNav = ({ open, onClose, menu = [], infomenu = [], products = [] }) =
314 331
                               </Button>
315 332
                             ))}
316 333
                           </Box>
317
-                        )}
334
+                        </Collapse>
318 335
                       </Box>
319 336
                     )
320 337
                   })}
@@ -353,7 +370,7 @@ const MobileNav = ({ open, onClose, menu = [], infomenu = [], products = [] }) =
353 370
                     </Box>
354 371
                   )}
355 372
                 </Box>
356
-              )}
373
+              </Collapse>
357 374
             </Box>
358 375
           )
359 376
         })}

Loading…
Cancelar
Guardar