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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. size="small"
  64. aria-label="small outlined button group"
  65. sx={{
  66. height: 50,
  67. backgroundColor: bColor === 'light' ? '#664c47' : '#8f7772',
  68. color: 'white',
  69. border: 0,
  70. }}
  71. >
  72. <Button
  73. disableRipple
  74. sx={{
  75. color: 'white',
  76. fontSize: 20,
  77. width: 50,
  78. }}
  79. onClick={() => {
  80. handleDecrement();
  81. }}
  82. >
  83. -
  84. </Button>
  85. <Button
  86. disableRipple
  87. sx={{
  88. color: 'white',
  89. fontSize: 17,
  90. width: 50,
  91. }}
  92. >
  93. {quantity}
  94. </Button>
  95. <Button
  96. disableRipple
  97. sx={{
  98. color: 'white',
  99. fontSize: 20,
  100. width: 50,
  101. }}
  102. onClick={() => {
  103. handleIncrement();
  104. }}
  105. >
  106. +
  107. </Button>
  108. </ButtonGroup>
  109. <Button
  110. disableRipple
  111. sx={{
  112. mt: { xs: 2, md: 0 },
  113. ml: { md: 2 },
  114. backgroundColor: '#CBA213',
  115. height: 50,
  116. width: 150,
  117. color: 'white',
  118. }}
  119. disabled={inCart}
  120. onClick={() => addProductToCart(quantity)}
  121. >
  122. {inCart ? 'In Cart' : 'Add to cart'}
  123. </Button>
  124. </Box>
  125. </Box>
  126. );
  127. };
  128. ProductInfo.propTypes = {
  129. data: PropType.shape({
  130. name: PropType.string,
  131. description: PropType.string,
  132. }),
  133. bColor: PropType.string,
  134. side: PropType.string,
  135. addProductToCart: PropType.func,
  136. inCart: PropType.bool,
  137. };
  138. export default ProductInfo;