Bläddra i källkod

feat module 2 & 4 : replace visual slider navbar with subcategory navbar - web, mobile

master
nadia 20 timmar sedan
förälder
incheckning
49a8bf281c

+ 270
- 5
src/components/Navbar/Navbar.jsx Visa fil

@@ -87,6 +87,40 @@ const getProductTypeMenuLabel = (productType = "") => {
87 87
   return normalizeTitle(productType) === "BEAUTY" ? "Essentials" : productType;
88 88
 };
89 89
 
90
+const NAV_MENU_STRUCTURE = [
91
+  {
92
+    productType: "Apparel",
93
+    label: "APPAREL",
94
+    groups: [
95
+      {
96
+        label: "Casual",
97
+        children: [
98
+          { label: "ND X Marii for Amber", titles: ["ND X MARII FOR AMBER"] },
99
+          { label: "Somewhere Somehow Someone", titles: ["SOMEWHERE SOMEHOW SOMEONE"] },
100
+          { label: "Flower Power", titles: ["FLOWER POWER"] },
101
+        ],
102
+      },
103
+      {
104
+        label: "Traditional",
105
+        children: [
106
+          { label: "Eid's Time For Love", titles: ["EID'S TIME FOR LOVE"] },
107
+          { label: "Raya Romantics", titles: ["RAYA ROMANTICS COLLECTION 2025"] },
108
+          { label: "Atma Sari", titles: ["ATMA SARI"] },
109
+          { label: "Oasis abaya collection", titles: ["OASIS ABAYA COLLECTION", "MIRAGE COLLECTION"] },
110
+        ],
111
+      },
112
+    ],
113
+  },
114
+  {
115
+    productType: "BEAUTY",
116
+    label: "Essentials",
117
+    children: [
118
+      { label: "Cosmetics", titles: ["COSMETICS"] },
119
+      { label: "Hand & Body Lotion", titles: ["HAND & BODY LOTION"] },
120
+    ],
121
+  },
122
+];
123
+
90 124
 const sortCollectionsByPriority = (collection = [], productType = "") => {
91 125
   const typeKey = (productType || "").trim().toLowerCase();
92 126
   const priorityList = COLLECTION_PRIORITY_BY_TYPE[typeKey] || [];
@@ -165,6 +199,7 @@ function getUniqueCollections(data) {
165 199
 const Navbar = () => {
166 200
 
167 201
   const swiperRef = useRef(null); // Create a ref for the Swiper instance
202
+  const childTransitionTimerRef = useRef(null);
168 203
   const [showHeader, setShowHeader] = useState(true);
169 204
   const [showSearch, setShowSearch] = useState(false);
170 205
   const [isAtTop, setIsAtTop] = useState(false);
@@ -181,6 +216,8 @@ const Navbar = () => {
181 216
   const [openSideCart, setOpenSideCart] = useState(false);
182 217
   const [navItem, setNavItem] = useState([]);
183 218
   const [navItemCompanyInfo, setNavItemCompanyInfo] = useState([]);
219
+  const [activeMenu, setActiveMenu] = useState(null);
220
+  const [activeGroup, setActiveGroup] = useState(null);
184 221
 
185 222
   const [displayCollection, setDisplayCollection] = useState({
186 223
     productType: null,
@@ -342,6 +379,35 @@ const Navbar = () => {
342 379
     setDisplayCollection([])
343 380
   }
344 381
 
382
+  const handleGroupMouseEnter = (groupLabel) => {
383
+    if (activeGroup === groupLabel) return;
384
+
385
+    if (childTransitionTimerRef.current) {
386
+      clearTimeout(childTransitionTimerRef.current);
387
+    }
388
+
389
+    setActiveGroup(null);
390
+    childTransitionTimerRef.current = setTimeout(() => {
391
+      setActiveGroup(groupLabel);
392
+    }, 40);
393
+  }
394
+
395
+  const navigateToMenuItem = (productType, item = null) => {
396
+    sessionStorage.setItem('amber-select-product-type', productType)
397
+    sessionStorage.removeItem('amber-select-collection')
398
+    sessionStorage.removeItem('amber-select-collections')
399
+
400
+    if (item) {
401
+      sessionStorage.setItem('amber-select-collection', JSON.stringify({
402
+        title: item.label,
403
+        image: null
404
+      }))
405
+      sessionStorage.setItem('amber-select-collections', JSON.stringify(item.titles || []))
406
+    }
407
+
408
+    window.location.href = `/products`;
409
+  }
410
+
345 411
   return (
346 412
     <>
347 413
       <AppBar position="fixed"
@@ -364,6 +430,8 @@ const Navbar = () => {
364 430
         }}
365 431
         onMouseLeave={() => {
366 432
           hideCollectionList()
433
+          setActiveMenu(null)
434
+          setActiveGroup(null)
367 435
         }}
368 436
       >
369 437
 
@@ -444,6 +512,202 @@ const Navbar = () => {
444 512
               }}
445 513
             >
446 514
 
515
+              {NAV_MENU_STRUCTURE.map((menu) => (
516
+                <Box
517
+                  key={menu.label}
518
+                  sx={{ position: "relative" }}
519
+                  onMouseEnter={() => {
520
+                    if (childTransitionTimerRef.current) {
521
+                      clearTimeout(childTransitionTimerRef.current);
522
+                    }
523
+                    setActiveMenu(menu.label);
524
+                    setActiveGroup(null);
525
+                  }}
526
+                >
527
+                  <Button
528
+                    sx={{
529
+                      position: "relative",
530
+                      ':hover': {
531
+                        backgroundColor: "rgba(0,0,0,0)",
532
+                      }
533
+                    }}
534
+                    color="inherit"
535
+                    onClick={() => {
536
+                      if (!menu.groups && !menu.children) {
537
+                        navigateToMenuItem(menu.productType)
538
+                      }
539
+                    }}
540
+                  >
541
+                    <Typography variant="body2"
542
+                      className="navItem"
543
+                      sx={{
544
+                        fontSize: {
545
+                          xs: "0.73rem",
546
+                          sm: "0.73rem",
547
+                          md: "0.875rem",
548
+                        },
549
+                        color: (isAtTop) ? "white" : "black",
550
+                        transition: "all 0.3s ease-in-out",
551
+                        ":hover": {
552
+                          color: "#95AAC5 !important"
553
+                        },
554
+                        "&::after": {
555
+                          content: '""',
556
+                          position: "absolute",
557
+                          left: "50%",
558
+                          transform: "translateX(-50%)",
559
+                          bottom: 2,
560
+                          width: activeMenu === menu.label ? "70%" : "0%",
561
+                          height: "2px",
562
+                          backgroundColor: "#95AAC5",
563
+                          transition: "width 0.3s ease-in-out",
564
+                        },
565
+                        ":hover::after": {
566
+                          width: "70%",
567
+                        },
568
+                      }}>{menu.label}</Typography>
569
+                  </Button>
570
+
571
+                  {(
572
+                    <>
573
+                      <Box
574
+                        sx={{
575
+                          position: "absolute",
576
+                          top: "100%",
577
+                          left: 0,
578
+                          width: menu.groups ? (activeGroup ? 560 : 260) : 260,
579
+                          height: 28,
580
+                          zIndex: 1000,
581
+                          backgroundColor: "transparent",
582
+                          visibility: activeMenu === menu.label ? "visible" : "hidden",
583
+                          pointerEvents: activeMenu === menu.label ? "auto" : "none",
584
+                        }}
585
+                      />
586
+                      <Box
587
+                        sx={{
588
+                          position: "absolute",
589
+                          top: 60,
590
+                          left: 0,
591
+                          width: menu.groups ? (activeGroup ? 560 : 260) : 260,
592
+                          backgroundColor: "#FFF",
593
+                          color: "#000",
594
+                          border: "1px solid rgba(0,0,0,0.08)",
595
+                          borderTop: 0,
596
+                          boxShadow: "0 2px 6px rgba(0,0,0,0.12)",
597
+                          display: "flex",
598
+                          minHeight: "auto",
599
+                          zIndex: 1001,
600
+                          overflow: "hidden",
601
+                          opacity: activeMenu === menu.label ? 1 : 0,
602
+                          visibility: activeMenu === menu.label ? "visible" : "hidden",
603
+                          pointerEvents: activeMenu === menu.label ? "auto" : "none",
604
+                          clipPath: activeMenu === menu.label ? "polygon(0 0, 100% 0, 100% 100%, 0 100%)" : "polygon(0 0, 100% 0, 100% 0, 0 0)",
605
+                          transition: activeGroup ? "clip-path .45s ease-in-out, visibility .45s ease-in-out, opacity .45s ease-in-out, width .55s ease-in-out" : "clip-path .45s ease-in-out, visibility .45s ease-in-out, opacity .45s ease-in-out",
606
+                        }}
607
+                      >
608
+                      {menu.groups ? (
609
+                        <>
610
+                          <Box sx={{ width: 260, pb: 1.5, borderRight: "1px solid rgba(0,0,0,0.12)" }}>
611
+                            {menu.groups.map((group) => (
612
+                              <Button
613
+                                key={group.label}
614
+                                fullWidth
615
+                                onMouseEnter={() => handleGroupMouseEnter(group.label)}
616
+                                sx={{
617
+                                  justifyContent: "space-between",
618
+                                  color: activeGroup === group.label ? "#95AAC5" : "#000",
619
+                                  textTransform: "none",
620
+                                  fontSize: "0.875rem",
621
+                                  py: 1.5,
622
+                                  px: 3,
623
+                                  '&:hover': {
624
+                                    backgroundColor: "transparent",
625
+                                    color: "#95AAC5",
626
+                                  }
627
+                                }}
628
+                              >
629
+                                {group.label?.toUpperCase()}
630
+                                <KeyboardArrowRightIcon sx={{ fontSize: 20 }} />
631
+                              </Button>
632
+                            ))}
633
+                          </Box>
634
+
635
+                          {activeGroup && (
636
+                            <Box key={activeGroup} sx={{
637
+                              pb: 1.5,
638
+                              px: 3,
639
+                              width: 300,
640
+                              clipPath: "polygon(0 0, 100% 0, 100% 100%, 0 100%)",
641
+                              overflow: "hidden",
642
+                              position: "relative",
643
+                              animation: "childCardReveal .55s ease-in-out",
644
+                              "@keyframes childCardReveal": {
645
+                                "0%": {
646
+                                  clipPath: "polygon(0 0, 0 0, 0 100%, 0 100%)",
647
+                                },
648
+                                "100%": {
649
+                                  clipPath: "polygon(0 0, 100% 0, 100% 100%, 0 100%)",
650
+                                },
651
+                              },
652
+                            }}>
653
+                              {menu.groups
654
+                                .find((group) => group.label === activeGroup)
655
+                                ?.children.map((item) => (
656
+                                  <Button
657
+                                    key={item.label}
658
+                                    fullWidth
659
+                                    onClick={() => navigateToMenuItem(menu.productType, item)}
660
+                                    sx={{
661
+                                      justifyContent: "flex-start",
662
+                                      color: "#000",
663
+                                      textTransform: "none",
664
+                                      fontSize: "0.875rem",
665
+                                      py: 1.1,
666
+                                      px: 0,
667
+                                      '&:hover': {
668
+                                        backgroundColor: "transparent",
669
+                                        color: "#95AAC5",
670
+                                      }
671
+                                    }}
672
+                                  >
673
+                                    {item.label?.toUpperCase()}
674
+                                  </Button>
675
+                                ))}
676
+                            </Box>
677
+                          )}
678
+                        </>
679
+                      ) : (
680
+                        <Box sx={{ pb: 1.5, px: 3, width: 260 }}>
681
+                          {menu.children.map((item) => (
682
+                            <Button
683
+                              key={item.label}
684
+                              fullWidth
685
+                              onClick={() => navigateToMenuItem(menu.productType, item)}
686
+                              sx={{
687
+                                justifyContent: "flex-start",
688
+                                color: "#000",
689
+                                textTransform: "none",
690
+                                fontSize: "0.875rem",
691
+                                py: 1.1,
692
+                                px: 0,
693
+                                '&:hover': {
694
+                                  backgroundColor: "transparent",
695
+                                  color: "#95AAC5",
696
+                                }
697
+                              }}
698
+                            >
699
+                              {item.label?.toUpperCase()}
700
+                            </Button>
701
+                          ))}
702
+                        </Box>
703
+                      )}
704
+                      </Box>
705
+                    </>
706
+                  )}
707
+                </Box>
708
+              ))}
709
+
710
+              {/*
447 711
               {navItem.map(({ productType, collection }) => (<Button
448 712
                 sx={{
449 713
                   position: "relative",
@@ -481,12 +745,12 @@ const Navbar = () => {
481 745
                       transform: "translateX(-50%)",
482 746
                       bottom: 2,
483 747
                       width: "0%",
484
-                      height: "2px", // Thickness of the underline
748
+                      height: "2px",
485 749
                       backgroundColor: "#95AAC5",
486 750
                       transition: "width 0.3s ease-in-out",
487 751
                     },
488 752
                     ":hover::after": {
489
-                      width: "50%", // Expands on hover
753
+                      width: "50%",
490 754
                     },
491 755
                   }}>{getProductTypeMenuLabel(productType)}</Typography>
492 756
               </Button>))}
@@ -523,15 +787,16 @@ const Navbar = () => {
523 787
                       transform: "translateX(-50%)",
524 788
                       bottom: 2,
525 789
                       width: "0%",
526
-                      height: "2px", // Thickness of the underline
790
+                      height: "2px",
527 791
                       backgroundColor: "#95AAC5",
528 792
                       transition: "width 0.3s ease-in-out",
529 793
                     },
530 794
                     ":hover::after": {
531
-                      width: "70%", // Expands on hover
795
+                      width: "70%",
532 796
                     },
533 797
                   }}>{name}</Typography>
534 798
               </Button>))}
799
+              */}
535 800
 
536 801
 
537 802
 
@@ -638,7 +903,7 @@ const Navbar = () => {
638 903
       </AppBar>
639 904
       {showSearch && <SearchProduct onClose={() => { setShowSearch(false) }} />}
640 905
 
641
-      <MobileNav open={openSideMenu} menu={navItem} infomenu={navItemCompanyInfo} onClose={() => { setOpenSideMenu(false) }} />
906
+      <MobileNav open={openSideMenu} menu={NAV_MENU_STRUCTURE} infomenu={navItemCompanyInfo} onClose={() => { setOpenSideMenu(false) }} />
642 907
       <SideCart open={openSideCart} onClose={() => { setOpenSideCart(false) }} />
643 908
 
644 909
     </>

+ 231
- 85
src/components/Navbar/components/MobileNav/MobileNav.jsx Visa fil

@@ -10,6 +10,46 @@ const getProductTypeMenuLabel = (productType = "") => {
10 10
 };
11 11
 
12 12
 const MobileNav = ({ open, onClose, menu = [], infomenu = [] }) => {
13
+  const [expandedMenu, setExpandedMenu] = React.useState(null);
14
+  const [expandedGroup, setExpandedGroup] = React.useState(null);
15
+
16
+  React.useEffect(() => {
17
+    if (!open) {
18
+      setExpandedMenu(null);
19
+      setExpandedGroup(null);
20
+    }
21
+  }, [open]);
22
+
23
+  const handleClose = () => {
24
+    setExpandedMenu(null);
25
+    setExpandedGroup(null);
26
+    onClose();
27
+  }
28
+
29
+  const navigateToMenuItem = (productType, item = null) => {
30
+    sessionStorage.setItem('amber-select-product-type', productType)
31
+    sessionStorage.removeItem('amber-select-collection')
32
+    sessionStorage.removeItem('amber-select-collections')
33
+
34
+    if (item) {
35
+      sessionStorage.setItem('amber-select-collection', JSON.stringify({
36
+        title: item.label,
37
+        image: null
38
+      }))
39
+      sessionStorage.setItem('amber-select-collections', JSON.stringify(item.titles || []))
40
+    }
41
+
42
+    window.location.href = `/products`;
43
+  }
44
+
45
+  const handleMenuToggle = (label) => {
46
+    setExpandedMenu((current) => current === label ? null : label);
47
+    setExpandedGroup(null);
48
+  }
49
+
50
+  const handleGroupToggle = (label) => {
51
+    setExpandedGroup((current) => current === label ? null : label);
52
+  }
13 53
 
14 54
   // React.useEffect(()=>{
15 55
 
@@ -69,108 +109,214 @@ const MobileNav = ({ open, onClose, menu = [], infomenu = [] }) => {
69 109
   return (
70 110
     <Drawer
71 111
       open={open}
72
-      onClose={onClose}
112
+      onClose={handleClose}
73 113
       sx={{
74 114
         "& .MuiDrawer-paper": {
75 115
           backgroundColor: "white",
76 116
           color: "white",
77
-          width: "100%",
117
+          width: "100vw",
118
+          maxWidth: "100vw",
119
+          overflowX: "hidden",
78 120
         },
79 121
       }}
80 122
     >
81 123
       {/* Logo Section */}
82
-      <Box sx={{ height: 80, px: 2 }}>
83
-        <Grid
84
-          container
85
-          alignItems="center"
86
-          justifyContent="space-between"
87
-          sx={{ height: "100%" }}
124
+      <Box sx={{ height: 80, px: 2, display: "flex", alignItems: "center", justifyContent: "center", position: "relative" }}>
125
+        <a href="/">
126
+          <img
127
+            src={logoSrc}
128
+            alt="Logo"
129
+            style={{
130
+              width: 150,
131
+              height: 25,
132
+            }}
133
+          />
134
+        </a>
135
+        <button
136
+          onClick={handleClose}
137
+          style={{
138
+            background: "none",
139
+            border: "none",
140
+            fontSize: 24,
141
+            cursor: "pointer",
142
+            position: "absolute",
143
+            right: 20,
144
+          }}
88 145
         >
89
-          {/* Left Spacer */}
90
-          <Grid item xs={3} />
91
-
92
-          {/* Centered Logo */}
93
-          <Grid item xs={6} container justifyContent="center">
94
-            <a href="/">
95
-              <img
96
-                src={logoSrc}
97
-                alt="Logo"
98
-                style={{
99
-                  width: 150,
100
-                  height: 25,
101
-                }}
102
-              />
103
-            </a>
104
-          </Grid>
105
-
106
-          {/* Right 'X' Button */}
107
-          <Grid item xs={3} container justifyContent="flex-end">
108
-            <button
109
-              onClick={() => { onClose() }}
110
-              style={{
111
-                background: "none",
112
-                border: "none",
113
-                fontSize: 24,
114
-                cursor: "pointer",
115
-              }}
116
-            >
117
-              &#x2715; {/* Unicode for "X" symbol */}
118
-            </button>
119
-          </Grid>
120
-        </Grid>
146
+          &#x2715; {/* Unicode for "X" symbol */}
147
+        </button>
121 148
       </Box>
122 149
 
123 150
 
124 151
       {/* Main Navigation */}
125
-      <Box sx={{ width: "100%" }} role="presentation">
126
-        {menu.map(({ productType, collection }) => (
127
-          <Accordion
128
-            disableGutters={true}
129
-            onClick={() => {
130
-              sessionStorage.setItem('amber-select-product-type', productType)
131
-              if (collection?.length == 0) {
132
-                window.location.href = `/products`;
133
-                sessionStorage.removeItem('amber-select-collection')
134
-              }
135
-            }}
136
-            sx={{
137
-              backgroundColor: "rgba(0,0,0,0)",
138
-              boxShadow: "none"
139
-            }}>
140
-            <AccordionSummary
141
-              expandIcon={(collection?.length > 0) ? <ExpandMoreIcon /> : ""}
142
-              aria-controls="panel1-content"
143
-              id="panel1-header"
144
-            >
145
-              <Typography
146
-                onClick={() => {
147
-                  sessionStorage.setItem('amber-select-product-type', productType)
148
-                  window.location.href = `/products`;
149
-                  sessionStorage.removeItem('amber-select-collection')
150
-                }}
151
-                variant="body1"
152
+      <Box sx={{ width: "100%", boxSizing: "border-box", px: 3, pt: 5, pb: 4, overflowX: "hidden" }} role="presentation">
153
+        {menu.map(({ productType, label, groups, children }) => {
154
+          const menuLabel = (label || getProductTypeMenuLabel(productType))?.toUpperCase();
155
+          const isMenuExpanded = expandedMenu === menuLabel;
156
+
157
+          return (
158
+            <Box key={menuLabel}>
159
+              <Box
160
+                onClick={() => handleMenuToggle(menuLabel)}
152 161
                 sx={{
153
-                  fontSize: {
154
-                    xs: "0.73rem",
155
-                    sm: "0.73rem",
156
-                    md: "0.875rem",
157
-                  },
162
+                  display: "flex",
163
+                  alignItems: "center",
164
+                  justifyContent: "space-between",
165
+                  width: "100%",
166
+                  boxSizing: "border-box",
167
+                  py: 2,
168
+                  cursor: "pointer",
158 169
                 }}
159 170
               >
160
-                {getProductTypeMenuLabel(productType)?.toUpperCase()}
161
-              </Typography>
162
-            </AccordionSummary>
163
-            <AccordionDetails>
164
-              {(collection?.length > 0) &&
165
-                <Grid container sx={{ maxHeight: "1000px", overflow: "scroll", overflowX: "hidden" }}>
166
-                  {collection?.map((colletion) => {
167
-                    return renderCollectionDisplay(colletion)
171
+                <Typography
172
+                  variant="body1"
173
+                  sx={{
174
+                    color: "#4B2F34",
175
+                    fontSize: "1.05rem",
176
+                    letterSpacing: 0,
177
+                    fontWeight: "400",
178
+                  }}
179
+                >
180
+                  {menuLabel}
181
+                </Typography>
182
+                <Typography
183
+                  component="span"
184
+                  sx={{
185
+                    color: "#4B2F34",
186
+                    fontSize: "1.8rem",
187
+                    lineHeight: 1,
188
+                    fontWeight: "300",
189
+                  }}
190
+                >
191
+                  {isMenuExpanded ? "-" : "+"}
192
+                </Typography>
193
+              </Box>
194
+
195
+              {isMenuExpanded && (
196
+                <Box>
197
+                  {groups?.map((group) => {
198
+                    const isGroupExpanded = expandedGroup === group.label;
199
+
200
+                    return (
201
+                      <Box key={group.label}>
202
+                        <Box
203
+                          onClick={() => handleGroupToggle(group.label)}
204
+                          sx={{
205
+                            display: "flex",
206
+                            alignItems: "center",
207
+                            justifyContent: "space-between",
208
+                            width: "100%",
209
+                            boxSizing: "border-box",
210
+                            py: 2,
211
+                            pl: 4,
212
+                            cursor: "pointer",
213
+                          }}
214
+                        >
215
+                          <Typography
216
+                            variant="body1"
217
+                            sx={{
218
+                              color: "#4B2F34",
219
+                              fontSize: "1rem",
220
+                              letterSpacing: 0,
221
+                              fontWeight: "400",
222
+                            }}
223
+                          >
224
+                            {group.label?.toUpperCase()}
225
+                          </Typography>
226
+                          <Typography
227
+                            component="span"
228
+                            sx={{
229
+                              color: "#4B2F34",
230
+                              fontSize: "1.65rem",
231
+                              lineHeight: 1,
232
+                              fontWeight: "300",
233
+                            }}
234
+                          >
235
+                            {isGroupExpanded ? "-" : "+"}
236
+                          </Typography>
237
+                        </Box>
238
+
239
+                        {isGroupExpanded && (
240
+                          <Box sx={{ ml: 7, pl: 4, borderLeft: "1px solid #777", mb: 2 }}>
241
+                            {group.children.map((item) => (
242
+                              <Button
243
+                                key={item.label}
244
+                                fullWidth
245
+                                onClick={() => navigateToMenuItem(productType, item)}
246
+                                sx={{
247
+                                  justifyContent: "flex-start",
248
+                                  color: "#4B2F34",
249
+                                  textTransform: "none",
250
+                                  px: 0,
251
+                                  py: 1.5,
252
+                                  fontSize: "1rem",
253
+                                  fontWeight: "400",
254
+                                  textAlign: "left",
255
+                                  '& .MuiButton-startIcon, & .MuiButton-endIcon': {
256
+                                    margin: 0,
257
+                                  },
258
+                                  '& .MuiButtonBase-root': {
259
+                                    textAlign: "left",
260
+                                  },
261
+                                  '& .MuiButton-label': {
262
+                                    width: "100%",
263
+                                    textAlign: "left",
264
+                                  },
265
+                                  '&:hover': {
266
+                                    backgroundColor: "transparent",
267
+                                    color: "#95AAC5",
268
+                                  }
269
+                                }}
270
+                              >
271
+                                <Box component="span" sx={{ display: "block", width: "100%", textAlign: "left" }}>
272
+                                  {item.label?.toUpperCase()}
273
+                                </Box>
274
+                              </Button>
275
+                            ))}
276
+                          </Box>
277
+                        )}
278
+                      </Box>
279
+                    )
168 280
                   })}
169
-                </Grid>
170
-              }
171
-            </AccordionDetails>
172
-          </Accordion>
173
-        ))}
281
+
282
+                  {children?.length > 0 && (
283
+                    <Box sx={{ ml: 7, pl: 4, borderLeft: "1px solid #777", mb: 2 }}>
284
+                      {children.map((item) => (
285
+                        <Button
286
+                          key={item.label}
287
+                          fullWidth
288
+                          onClick={() => navigateToMenuItem(productType, item)}
289
+                          sx={{
290
+                            justifyContent: "flex-start",
291
+                            color: "#4B2F34",
292
+                            textTransform: "none",
293
+                            px: 0,
294
+                            py: 1.5,
295
+                            fontSize: "1rem",
296
+                            fontWeight: "400",
297
+                            textAlign: "left",
298
+                            '& .MuiButton-label': {
299
+                              width: "100%",
300
+                              textAlign: "left",
301
+                            },
302
+                            '&:hover': {
303
+                              backgroundColor: "transparent",
304
+                              color: "#95AAC5",
305
+                            }
306
+                          }}
307
+                        >
308
+                          <Box component="span" sx={{ display: "block", width: "100%", textAlign: "left" }}>
309
+                            {item.label?.toUpperCase()}
310
+                          </Box>
311
+                        </Button>
312
+                      ))}
313
+                    </Box>
314
+                  )}
315
+                </Box>
316
+              )}
317
+            </Box>
318
+          )
319
+        })}
174 320
 
175 321
         {infomenu.map(({ name, link }) => (
176 322
           <Accordion

+ 21
- 0
src/components/ProductList/ProductList.jsx Visa fil

@@ -34,6 +34,19 @@ function getAllCollection(data) {
34 34
   return uniqueCollection;
35 35
 }
36 36
 
37
+function getSelectedCollectionTitles() {
38
+  const storedCollections = sessionStorage.getItem("amber-select-collections");
39
+
40
+  if (!storedCollections) return [];
41
+
42
+  try {
43
+    const collectionTitles = JSON.parse(storedCollections);
44
+    return Array.isArray(collectionTitles) ? collectionTitles : [];
45
+  } catch (error) {
46
+    return [];
47
+  }
48
+}
49
+
37 50
 const BootstrapInput = styled(InputBase)(({ theme }) => ({
38 51
   "label + &": {
39 52
     marginTop: theme.spacing(3),
@@ -113,6 +126,7 @@ const ProductList = ({ size = 99999 }) => {
113 126
   const filterProducts = () => {
114 127
     if (products?.length > 0) {
115 128
       let productType = sessionStorage.getItem("amber-select-product-type");
129
+      const selectedCollectionTitles = getSelectedCollectionTitles();
116 130
 
117 131
       let newFilteredProducts = products.filter(
118 132
         (product) => product.productType === productType
@@ -131,6 +145,13 @@ const ProductList = ({ size = 99999 }) => {
131 145
 
132 146
       // Collection
133 147
       newFilteredProducts = newFilteredProducts.filter((product) => {
148
+        if (selectedCollectionTitles.length > 0) {
149
+          return (
150
+            product.productType === productType &&
151
+            product.collections.some((data) => selectedCollectionTitles.includes(data?.title))
152
+          );
153
+        }
154
+
134 155
         if (collection == "all" || collection == "collection") {
135 156
           return product.productType === productType;
136 157
         } else {

+ 1
- 1
src/pages/Products/index.jsx Visa fil

@@ -40,7 +40,7 @@ const Products = () => {
40 40
           lg: 10
41 41
         }
42 42
       }}>
43
-        {collection && <PageTitle title={collection?.title} image={collection?.image?.url} />}
43
+        {collection?.image?.url && <PageTitle title={collection?.title} image={collection?.image?.url} />}
44 44
         <ProductList />
45 45
         <SocialMedia />
46 46
         {/*

Laddar…
Avbryt
Spara