CategoryAside.jsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import React from 'react';
  2. import {useState} from "react";
  3. import Link from "react-router-dom/es/Link";
  4. import {Accordion, AccordionDetails, AccordionSummary, Grid, Typography} from "@mui/material";
  5. import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
  6. const CategoryItem = ({object: {_id, name, subCategories}={}}) => {
  7. const [expanded, setExpanded] = useState(false);
  8. const handleChange = (panel) => (event, isExpanded) => {
  9. setExpanded(isExpanded ? panel : false);
  10. };
  11. return (
  12. <>
  13. {subCategories === null || !subCategories ?
  14. <li>
  15. <Link
  16. style={{textDecoration: 'none'}}
  17. to={`/catalog/category/${_id}`}
  18. >
  19. <Typography
  20. variant='body1'
  21. color='#616161'
  22. marginBottom='10px'
  23. >
  24. {name || 'no name'}
  25. </Typography>
  26. </Link>
  27. </li>
  28. :
  29. <li>
  30. <Accordion
  31. style={{
  32. border: 'none',
  33. borderRadius: '0',
  34. marginTop: '-10px',
  35. boxShadow: 'none'
  36. }}
  37. expanded={expanded === 'panel1'}
  38. onChange={handleChange('panel1')}
  39. >
  40. <AccordionSummary
  41. sx={{padding: '0'}}
  42. expandIcon={<ExpandMoreIcon />}
  43. aria-controls="panel1bh-content"
  44. id="panel1bh-header"
  45. >
  46. <Link
  47. style={{textDecoration: 'none'}}
  48. to={`/catalog/category/${_id}`}
  49. >
  50. <Typography
  51. variant='body1'
  52. color='#616161'
  53. padding='0'
  54. >
  55. {name || 'no name'}
  56. </Typography>
  57. </Link>
  58. </AccordionSummary>
  59. <AccordionDetails>
  60. <ul
  61. style={{
  62. listStyle: 'none',
  63. padding: '0 0 0 10px',
  64. marginBottom: '10px'
  65. }}
  66. >
  67. {subCategories && Object.values(subCategories).map(item =>
  68. <CategoryItem key={item['_id']} object={item}/>
  69. )}
  70. </ul>
  71. </AccordionDetails>
  72. </Accordion>
  73. </li>
  74. }
  75. </>
  76. )
  77. }
  78. export const CategoryAside = ({category}) => {
  79. return (
  80. <Grid
  81. sx={{
  82. backgroundColor: '#fff', padding: '30px'
  83. }}
  84. xs={12} lg={3} item
  85. >
  86. <Typography
  87. variant='h6'
  88. letterSpacing='3px'
  89. lineHeight='1.3em'
  90. marginBottom='20px'
  91. >
  92. PRODUCT CATEGORIES
  93. </Typography>
  94. <ul style={{listStyle: 'none', padding: '0'}}>
  95. {category && Object.values(category).map(item =>
  96. <CategoryItem key={item['_id']} object={item}/>
  97. )}
  98. </ul>
  99. </Grid>
  100. )
  101. }