Good.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import React, { Component, useState } from 'react';
  2. import Button from '@mui/material/Button';
  3. import { styled } from '@mui/material/styles';
  4. import { Container, Typography, Grid, CardActionArea, Card, CardContent, CardMedia, AvatarGroup, CardActions, Collapse, IconButton, Paper } from '@mui/material';
  5. //CssBaseline, TextField, FormControlLabel, Checkbox, Link, Divider
  6. import { getFullImageUrl } from "./../utills";
  7. import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
  8. import { Box } from '@mui/system';
  9. import { AvatarAnimated } from './AvatarAnimated';
  10. const GoodExample = () => {
  11. return <Good good={
  12. {
  13. "_id": "62c9472cb74e1f5f2ec1a0d1",
  14. "name": "iPhone 4",
  15. "price": 100,
  16. "description": " сенсорный смартфон, разработанный корпорацией Apple. Это четвёртое поколение iPhone и преемник iPhone 3GS. Позиционируется для осуществления видеовызовов (под названием FaceTime), использования медиа, в том числе книг и периодических изданий, фильмов, музыки и игр, и для общего доступа к вебу и электронной почте. Был представлен 7 июня 2010 года на Worldwide Developers Conference в Сан-Франциско[1] и был выпущен 24 июня 2010 года в США, Великобритании, Франции, Германии и Японии.",
  17. "images": [
  18. {
  19. "url": "images/e48e7ee1bcc4ab5432d1e7a3a89b8466"
  20. },
  21. {
  22. "url": "images/58c6157d51d8c2430c4dd41b6d0132f4"
  23. }
  24. ]
  25. }
  26. } />
  27. }
  28. const ExpandMore = styled(props => {
  29. const { expand, ...other } = props;
  30. return <IconButton {...other} />;
  31. })(({ theme, expand }) => ({
  32. transform: !expand ? 'rotate(0deg)' : 'rotate(180deg)',
  33. marginLeft: 'auto',
  34. transition: theme.transitions.create('transform', { duration: theme.transitions.duration.shortest })
  35. }))
  36. const AvatarGroupOriented = styled((props) => {
  37. const { vertical, ...other } = props;
  38. return <AvatarGroup {...other} />;
  39. })(({ theme, vertical }) => (vertical && {
  40. display: 'flex',
  41. flexDirection: 'column',
  42. marginLeft: 10,
  43. '& >:first-child': {
  44. marginTop: 10,
  45. },
  46. '& >*': {
  47. marginLeft: 1,
  48. marginTop: theme.spacing(1),
  49. },
  50. ".MuiAvatar-root": { /*width: 20, height: 20,*/ marginLeft: 1 }
  51. }));
  52. const Good = ({ good, maxWidth, showAddToCard = true }) => {
  53. let [currentImageIndex, setCurrentImageIndex] = useState(0);
  54. let [expanded, setExpanded] = useState(false);
  55. const handleExpandClick = () => setExpanded(!expanded);
  56. maxWidth = maxWidth ?? 'md';
  57. return (
  58. <Container maxWidth={maxWidth}>
  59. <Card variant='outlined'>
  60. <Grid container spacing={maxWidth == 'xs' ? 7 : 5}>
  61. <Grid item xs={1}>
  62. <AvatarGroupOriented variant='rounded' vertical>
  63. {
  64. good.images?.map((image, index) => (
  65. <AvatarAnimated selected={index === currentImageIndex} variant='rounded' key={index} src={getFullImageUrl(image)}
  66. onClick={() => {
  67. setCurrentImageIndex(index)
  68. }} />
  69. ))
  70. }
  71. </AvatarGroupOriented>
  72. </Grid>
  73. <Grid item xs>
  74. <CardActionArea>
  75. <Grid container spacing={2}>
  76. <Grid item xs={4}>
  77. <CardMedia
  78. component="img"
  79. sx={{ height: 300, padding: "1em 1em 0 1em", objectFit: "contain" }}
  80. image={good.images?.length > 0 ? getFullImageUrl(good.images[currentImageIndex]) : ''}
  81. title={good.name}
  82. />
  83. </Grid>
  84. <Grid item xs={8}>
  85. <CardContent>
  86. <Typography gutterBottom variant='h5' component='h2'>
  87. {good.name}
  88. </Typography>
  89. <Typography gutterBottom variant='body2' color='textSecondary' component='p'>
  90. {`Price: $${good.price}`}
  91. </Typography>
  92. </CardContent>
  93. </Grid>
  94. </Grid>
  95. </CardActionArea>
  96. </Grid>
  97. </Grid>
  98. <CardActions>
  99. <ExpandMore
  100. expand={expanded}
  101. onClick={handleExpandClick}
  102. aria-expanded={expanded}
  103. aria-label='showMore'
  104. >
  105. <ExpandMoreIcon />
  106. </ExpandMore>
  107. {
  108. showAddToCard && (
  109. <Button size='small' color='primary'>
  110. Add to cart
  111. </Button>
  112. )
  113. }
  114. </CardActions>
  115. <Collapse in={expanded} timeout='auto' unmountOnExit>
  116. <Typography paragraph sx={{ marginLeft: 1 }}>
  117. Description:
  118. </Typography>
  119. <Typography paragraph align='justify' sx={{ marginLeft: 2, marginRight: 2 }}>
  120. {good.description}
  121. </Typography>
  122. </Collapse>
  123. </Card>
  124. </Container>
  125. )
  126. }
  127. export { Good, GoodExample };