CategoryAside.jsx 3.3 KB

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