You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProductInfo.jsx 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { Button, ButtonGroup, Typography } from '@mui/material';
  2. import { Box } from '@mui/system';
  3. import Image from 'next/image';
  4. import PropType from 'prop-types';
  5. import { useState } from 'react';
  6. const ProductInfo = ({ data, bColor, addProductToCart, inCart }) => {
  7. const [quantity, setQuantity] = useState(1);
  8. return (
  9. <Box
  10. sx={{
  11. display: 'flex',
  12. flexDirection: 'column',
  13. alignItems: { xs: 'center' },
  14. width: { xs: '100%', md: '50%' },
  15. height: '100%',
  16. }}
  17. >
  18. <Typography
  19. variant="h3"
  20. sx={{ height: 60, mt: { xs: 5 }, color: 'white' }}
  21. >
  22. {data.name}
  23. </Typography>
  24. <Box
  25. sx={{
  26. width: 100,
  27. maxWidth: 100,
  28. height: 60,
  29. }}
  30. >
  31. <Image
  32. src="/images/Stars.svg"
  33. alt="reviews"
  34. width={100}
  35. height={50}
  36. ></Image>
  37. </Box>
  38. <Typography
  39. sx={{
  40. color: 'white',
  41. }}
  42. >
  43. {data.description}
  44. </Typography>
  45. <Box
  46. sx={{
  47. width: '100%',
  48. display: 'flex',
  49. mt: 4,
  50. flexDirection: { xs: 'column', md: 'row' },
  51. alignItems: { xs: 'center' },
  52. justifyContent: { md: 'center' },
  53. }}
  54. >
  55. <ButtonGroup
  56. size="small"
  57. aria-label="small outlined button group"
  58. sx={{
  59. height: 50,
  60. backgroundColor: bColor === 'light' ? '#664c47' : '#8f7772',
  61. color: 'white',
  62. border: 0,
  63. }}
  64. >
  65. <Button
  66. sx={{
  67. color: 'white',
  68. fontSize: 20,
  69. width: 50,
  70. }}
  71. onClick={() => {
  72. setQuantity((prevState) => prevState - 1);
  73. }}
  74. >
  75. -
  76. </Button>
  77. <Button
  78. sx={{
  79. color: 'white',
  80. fontSize: 17,
  81. width: 50,
  82. }}
  83. >
  84. {quantity}
  85. </Button>
  86. <Button
  87. sx={{
  88. color: 'white',
  89. fontSize: 20,
  90. width: 50,
  91. }}
  92. onClick={() => {
  93. setQuantity((prevState) => prevState + 1);
  94. }}
  95. >
  96. +
  97. </Button>
  98. </ButtonGroup>
  99. <Button
  100. sx={{
  101. mt: { xs: 2, md: 0 },
  102. ml: { md: 2 },
  103. backgroundColor: '#CBA213',
  104. height: 50,
  105. width: 150,
  106. color: 'white',
  107. }}
  108. disabled={inCart}
  109. onClick={() => addProductToCart(quantity)}
  110. >
  111. {inCart ? 'In Cart' : 'Add to cart'}
  112. </Button>
  113. </Box>
  114. </Box>
  115. );
  116. };
  117. ProductInfo.propTypes = {
  118. data: PropType.shape({
  119. name: PropType.string,
  120. description: PropType.string,
  121. }),
  122. bColor: PropType.string,
  123. side: PropType.string,
  124. addProductToCart: PropType.func,
  125. inCart: PropType.bool,
  126. };
  127. export default ProductInfo;