Kaynağa Gözat

feat module 6, 7 : smooth the product info section collapse movement

master
nadia 4 saat önce
ebeveyn
işleme
afe70951bc
1 değiştirilmiş dosya ile 36 ekleme ve 72 silme
  1. 36
    72
      src/components/ProductDetails/ProductDetails.jsx

+ 36
- 72
src/components/ProductDetails/ProductDetails.jsx Dosyayı Görüntüle

9
   IconButton,
9
   IconButton,
10
   Drawer,
10
   Drawer,
11
   InputBase,
11
   InputBase,
12
-  Tooltip
12
+  Tooltip,
13
+  Collapse
13
 } from "@mui/material";
14
 } from "@mui/material";
14
 import AddIcon from '@mui/icons-material/Add';
15
 import AddIcon from '@mui/icons-material/Add';
15
 import RemoveIcon from '@mui/icons-material/Remove';
16
 import RemoveIcon from '@mui/icons-material/Remove';
359
 
360
 
360
   const toggleInfoRow = (row) => {
361
   const toggleInfoRow = (row) => {
361
     setExpandedInfoRows((prevRows) => ({
362
     setExpandedInfoRows((prevRows) => ({
362
-      ...prevRows,
363
       [row]: !prevRows[row]
363
       [row]: !prevRows[row]
364
     }))
364
     }))
365
   }
365
   }
382
     transition: "padding-bottom 0.25s ease-in-out"
382
     transition: "padding-bottom 0.25s ease-in-out"
383
   })
383
   })
384
 
384
 
385
+  const infoPanelSx = {
386
+    borderBottom: "1px solid #DDD"
387
+  }
388
+
389
+  const infoPanelContentSx = {
390
+    color: "text.secondary",
391
+    fontSize: {
392
+      xs: "0.875rem",
393
+      md: "1rem"
394
+    },
395
+    lineHeight: 1.6,
396
+    pb: 2.5
397
+  }
398
+
385
   const materialMetafield = product?.metafields?.material
399
   const materialMetafield = product?.metafields?.material
386
   const careInstructionMetafield = product?.metafields?.care_instruction
400
   const careInstructionMetafield = product?.metafields?.care_instruction
387
   const shippingInformationMetafield = product?.metafields?.shipping_information
401
   const shippingInformationMetafield = product?.metafields?.shipping_information
394
 
408
 
395
   // Renders Shopify product metafield custom.material inside the Material row.
409
   // Renders Shopify product metafield custom.material inside the Material row.
396
   const materialPanel = (
410
   const materialPanel = (
397
-    <Box
398
-      sx={{
399
-        maxHeight: expandedInfoRows.material ? 600 : 0,
400
-        overflow: "hidden",
401
-        borderBottom: "1px solid #DDD",
402
-        transition: "max-height 0.25s ease-in-out"
403
-      }}
404
-    >
411
+    <Box sx={infoPanelSx}>
412
+      <Collapse in={Boolean(expandedInfoRows.material)} timeout="auto">
405
       <Box
413
       <Box
406
         sx={{
414
         sx={{
407
-          color: "text.secondary",
415
+          ...infoPanelContentSx,
408
           minHeight: materialMetafield?.value ? 0 : 28,
416
           minHeight: materialMetafield?.value ? 0 : 28,
409
-          fontSize: {
410
-            xs: "0.875rem",
411
-            md: "1rem"
412
-          },
413
-          lineHeight: 1.6
414
         }}
417
         }}
415
       >
418
       >
416
         {renderShopifyRichText(materialMetafield?.value)}
419
         {renderShopifyRichText(materialMetafield?.value)}
417
       </Box>
420
       </Box>
421
+      </Collapse>
418
     </Box>
422
     </Box>
419
   )
423
   )
420
 
424
 
421
   // Renders Shopify product metafield custom.care_instruction inside the Care Instruction row.
425
   // Renders Shopify product metafield custom.care_instruction inside the Care Instruction row.
422
   const careInstructionPanel = (
426
   const careInstructionPanel = (
423
-    <Box
424
-      sx={{
425
-        maxHeight: expandedInfoRows.careInstruction ? 600 : 0,
426
-        overflow: "hidden",
427
-        borderBottom: "1px solid #DDD",
428
-        transition: "max-height 0.25s ease-in-out"
429
-      }}
430
-    >
427
+    <Box sx={infoPanelSx}>
428
+      <Collapse in={Boolean(expandedInfoRows.careInstruction)} timeout="auto">
431
       <Box
429
       <Box
432
         sx={{
430
         sx={{
433
-          color: "text.secondary",
431
+          ...infoPanelContentSx,
434
           minHeight: careInstructionMetafield?.value ? 0 : 28,
432
           minHeight: careInstructionMetafield?.value ? 0 : 28,
435
-          fontSize: {
436
-            xs: "0.875rem",
437
-            md: "1rem"
438
-          },
439
-          lineHeight: 1.6
440
         }}
433
         }}
441
       >
434
       >
442
         {renderShopifyRichText(careInstructionMetafield?.value)}
435
         {renderShopifyRichText(careInstructionMetafield?.value)}
443
       </Box>
436
       </Box>
437
+      </Collapse>
444
     </Box>
438
     </Box>
445
   )
439
   )
446
 
440
 
447
   // Renders Shopify product metafield custom.shipping_information inside the Shipping Information row.
441
   // Renders Shopify product metafield custom.shipping_information inside the Shipping Information row.
448
   const shippingInformationPanel = (
442
   const shippingInformationPanel = (
449
-    <Box
450
-      sx={{
451
-        maxHeight: expandedInfoRows.shippingInformation ? 600 : 0,
452
-        overflow: "hidden",
453
-        borderBottom: "1px solid #DDD",
454
-        transition: "max-height 0.25s ease-in-out"
455
-      }}
456
-    >
443
+    <Box sx={infoPanelSx}>
444
+      <Collapse in={Boolean(expandedInfoRows.shippingInformation)} timeout="auto">
457
       <Box
445
       <Box
458
         sx={{
446
         sx={{
459
-          color: "text.secondary",
447
+          ...infoPanelContentSx,
460
           minHeight: shippingInformationMetafield?.value ? 0 : 28,
448
           minHeight: shippingInformationMetafield?.value ? 0 : 28,
461
-          fontSize: {
462
-            xs: "0.875rem",
463
-            md: "1rem"
464
-          },
465
-          lineHeight: 1.6
466
         }}
449
         }}
467
       >
450
       >
468
         {renderShopifyRichText(shippingInformationMetafield?.value)}
451
         {renderShopifyRichText(shippingInformationMetafield?.value)}
469
       </Box>
452
       </Box>
453
+      </Collapse>
470
     </Box>
454
     </Box>
471
   )
455
   )
472
 
456
 
473
   // Renders Shopify product metafield custom.return_exchange inside the Return & Exchanges row.
457
   // Renders Shopify product metafield custom.return_exchange inside the Return & Exchanges row.
474
   const returnExchangesPanel = (
458
   const returnExchangesPanel = (
475
-    <Box
476
-      sx={{
477
-        maxHeight: expandedInfoRows.returnExchanges ? 600 : 0,
478
-        overflow: "hidden",
479
-        borderBottom: "1px solid #DDD",
480
-        transition: "max-height 0.25s ease-in-out"
481
-      }}
482
-    >
459
+    <Box sx={infoPanelSx}>
460
+      <Collapse in={Boolean(expandedInfoRows.returnExchanges)} timeout="auto">
483
       <Box
461
       <Box
484
         sx={{
462
         sx={{
485
-          color: "text.secondary",
463
+          ...infoPanelContentSx,
486
           minHeight: returnExchangeMetafield?.value ? 0 : 28,
464
           minHeight: returnExchangeMetafield?.value ? 0 : 28,
487
-          fontSize: {
488
-            xs: "0.875rem",
489
-            md: "1rem"
490
-          },
491
-          lineHeight: 1.6
492
         }}
465
         }}
493
       >
466
       >
494
         {renderShopifyRichText(returnExchangeMetafield?.value)}
467
         {renderShopifyRichText(returnExchangeMetafield?.value)}
495
       </Box>
468
       </Box>
469
+      </Collapse>
496
     </Box>
470
     </Box>
497
   )
471
   )
498
 
472
 
499
   // Renders Shopify product metafield custom.product_details inside the Product Details row.
473
   // Renders Shopify product metafield custom.product_details inside the Product Details row.
500
   const productDetailsPanel = (
474
   const productDetailsPanel = (
501
-    <Box
502
-      sx={{
503
-        maxHeight: expandedInfoRows.productDetails ? 1200 : 0,
504
-        overflow: "hidden",
505
-        borderBottom: "1px solid #DDD",
506
-        transition: "max-height 0.25s ease-in-out"
507
-      }}
508
-    >
475
+    <Box sx={infoPanelSx}>
476
+      <Collapse in={Boolean(expandedInfoRows.productDetails)} timeout="auto">
509
       <Box
477
       <Box
510
         sx={{
478
         sx={{
511
-          color: "text.secondary",
479
+          ...infoPanelContentSx,
512
           minHeight: productDetailsMetafield?.value ? 0 : 28,
480
           minHeight: productDetailsMetafield?.value ? 0 : 28,
513
-          fontSize: {
514
-            xs: "0.875rem",
515
-            md: "1rem"
516
-          },
517
-          lineHeight: 1.6,
518
           "& > div > *:first-child": {
481
           "& > div > *:first-child": {
519
             borderTop: "none !important",
482
             borderTop: "none !important",
520
             marginTop: "0 !important",
483
             marginTop: "0 !important",
542
       >
505
       >
543
         {renderShopifyRichText(productDetailsMetafield?.value)}
506
         {renderShopifyRichText(productDetailsMetafield?.value)}
544
       </Box>
507
       </Box>
508
+      </Collapse>
545
     </Box>
509
     </Box>
546
   )
510
   )
547
 
511
 

Loading…
İptal
Kaydet