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.2KB

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