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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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', md: 'flex-start' },
  22. width: { xs: '100%', md: '50%' },
  23. height: '100%',
  24. }}
  25. >
  26. <Typography variant="h3" sx={{ mt: { xs: 5 }, color: 'white' }}>
  27. {data.name}
  28. </Typography>
  29. <Box
  30. sx={{
  31. display: 'flex',
  32. alignItems: { xs: 'center', md: 'flex-start' },
  33. justifyContent: { xs: 'center', md: 'flex-start' },
  34. width: '100%',
  35. py: { xs: 2 },
  36. }}
  37. >
  38. <Image
  39. src="/images/Stars.svg"
  40. alt="reviews"
  41. width={100}
  42. height={50}
  43. ></Image>
  44. </Box>
  45. <Typography
  46. sx={{
  47. color: 'white',
  48. }}
  49. >
  50. {data.description}
  51. </Typography>
  52. <Box
  53. sx={{
  54. width: '100%',
  55. display: 'flex',
  56. mt: 4,
  57. flexDirection: { xs: 'column', md: 'row' },
  58. alignItems: { xs: 'center' },
  59. justifyContent: { md: 'flex-start' },
  60. }}
  61. >
  62. <ButtonGroup
  63. disabled={inCart}
  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. '&.Mui-disabled': {
  120. backgroundColor: '#f2d675',
  121. color: '#464646',
  122. },
  123. '&:hover': {
  124. backgroundColor: '#f2d675',
  125. color: '#464646',
  126. boxShadow: 'none',
  127. },
  128. }}
  129. disabled={inCart}
  130. onClick={() => addProductToCart(quantity)}
  131. >
  132. {inCart ? 'In Cart' : 'Add to cart'}
  133. </Button>
  134. </Box>
  135. </Box>
  136. );
  137. };
  138. ProductInfo.propTypes = {
  139. data: PropType.shape({
  140. name: PropType.string,
  141. description: PropType.string,
  142. }),
  143. bColor: PropType.string,
  144. side: PropType.string,
  145. addProductToCart: PropType.func,
  146. inCart: PropType.bool,
  147. };
  148. export default ProductInfo;