Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ProductInfo.jsx 2.8KB

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