您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ProductInfo.jsx 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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: 6,
  57. flexDirection: { md: 'row' },
  58. alignItems: { xs: 'center' },
  59. justifyContent: { xs: 'center', 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. '&.Mui-disabled': {
  77. color: 'rgba(255, 255, 255, 0.6)',
  78. },
  79. color: 'white',
  80. fontSize: 20,
  81. width: 50,
  82. }}
  83. onClick={() => {
  84. handleDecrement();
  85. }}
  86. >
  87. -
  88. </Button>
  89. <Button
  90. disableRipple
  91. sx={{
  92. '&.Mui-disabled': {
  93. color: 'rgba(255, 255, 255, 0.6)',
  94. },
  95. color: 'white',
  96. fontSize: 17,
  97. width: 50,
  98. }}
  99. >
  100. {quantity}
  101. </Button>
  102. <Button
  103. disableRipple
  104. sx={{
  105. '&.Mui-disabled': {
  106. color: 'rgba(255, 255, 255, 0.6)',
  107. },
  108. color: 'white',
  109. fontSize: 20,
  110. width: 50,
  111. }}
  112. onClick={() => {
  113. handleIncrement();
  114. }}
  115. >
  116. +
  117. </Button>
  118. </ButtonGroup>
  119. <Button
  120. disableRipple
  121. sx={{
  122. mt: { md: 0 },
  123. ml: { xs: 2 },
  124. backgroundColor: '#CBA213',
  125. height: 50,
  126. width: 150,
  127. color: 'white',
  128. '&.Mui-disabled': {
  129. backgroundColor: '#f2d675',
  130. color: '#464646',
  131. },
  132. '&:hover': {
  133. backgroundColor: '#f2d675',
  134. color: '#464646',
  135. boxShadow: 'none',
  136. },
  137. }}
  138. disabled={inCart}
  139. onClick={() => addProductToCart(quantity)}
  140. >
  141. {inCart ? 'In Cart' : 'Add to cart'}
  142. </Button>
  143. </Box>
  144. </Box>
  145. );
  146. };
  147. ProductInfo.propTypes = {
  148. data: PropType.shape({
  149. name: PropType.string,
  150. description: PropType.string,
  151. }),
  152. bColor: PropType.string,
  153. side: PropType.string,
  154. addProductToCart: PropType.func,
  155. inCart: PropType.bool,
  156. };
  157. export default ProductInfo;