Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ProductInfo.tsx 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import { Button, ButtonGroup, Typography } from '@mui/material';
  2. import { Box } from '@mui/system';
  3. import { useTranslation } from 'next-i18next';
  4. import Image from 'next/image';
  5. import { useState } from 'react';
  6. const ProductInfo = ({ data, bColor, addProductToCart, inCart }) => {
  7. const { t } = useTranslation('home');
  8. const [quantity, setQuantity] = useState(1);
  9. const handleIncrement = () => {
  10. setQuantity((prevState) => prevState + 1);
  11. };
  12. const handleDecrement = () => {
  13. if (quantity > 1) {
  14. setQuantity((prevState) => prevState - 1);
  15. }
  16. };
  17. return (
  18. <Box
  19. sx={{
  20. display: 'flex',
  21. flexDirection: 'column',
  22. alignItems: { xs: 'center', md: 'flex-start' },
  23. width: { xs: '100%', md: '50%' },
  24. height: '100%',
  25. }}
  26. >
  27. <Typography variant="h3" sx={{ mt: { xs: 5 }, color: 'white' }}>
  28. {data.name}
  29. </Typography>
  30. <Box
  31. sx={{
  32. display: 'flex',
  33. alignItems: { xs: 'center', md: 'flex-start' },
  34. justifyContent: { xs: 'center', md: 'flex-start' },
  35. width: '100%',
  36. py: { xs: 2 },
  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: 6,
  58. flexDirection: { md: 'row' },
  59. alignItems: { xs: 'center' },
  60. justifyContent: { xs: 'center', md: 'flex-start' },
  61. }}
  62. >
  63. <ButtonGroup
  64. disabled={inCart}
  65. size="small"
  66. aria-label="small outlined button group"
  67. sx={{
  68. height: 50,
  69. backgroundColor: bColor === 'light' ? '#664c47' : '#8f7772',
  70. color: 'white',
  71. border: 0,
  72. }}
  73. >
  74. <Button
  75. disableRipple
  76. sx={{
  77. '&.Mui-disabled': {
  78. color: 'rgba(255, 255, 255, 0.6)',
  79. },
  80. color: 'white',
  81. fontSize: 20,
  82. width: 50,
  83. }}
  84. onClick={() => {
  85. handleDecrement();
  86. }}
  87. >
  88. -
  89. </Button>
  90. <Button
  91. disableRipple
  92. sx={{
  93. '&.Mui-disabled': {
  94. color: 'rgba(255, 255, 255, 0.6)',
  95. },
  96. color: 'white',
  97. fontSize: 17,
  98. width: 50,
  99. }}
  100. >
  101. {quantity}
  102. </Button>
  103. <Button
  104. disableRipple
  105. sx={{
  106. '&.Mui-disabled': {
  107. color: 'rgba(255, 255, 255, 0.6)',
  108. },
  109. color: 'white',
  110. fontSize: 20,
  111. width: 50,
  112. }}
  113. onClick={() => {
  114. handleIncrement();
  115. }}
  116. >
  117. +
  118. </Button>
  119. </ButtonGroup>
  120. <Button
  121. disableRipple
  122. sx={{
  123. mt: { md: 0 },
  124. ml: { xs: 2 },
  125. backgroundColor: '#CBA213',
  126. height: 50,
  127. width: 150,
  128. color: 'white',
  129. '&.Mui-disabled': {
  130. backgroundColor: '#f2d675',
  131. color: '#464646',
  132. },
  133. '&:hover': {
  134. backgroundColor: '#f2d675',
  135. color: '#464646',
  136. boxShadow: 'none',
  137. },
  138. }}
  139. disabled={inCart}
  140. onClick={() => addProductToCart(quantity)}
  141. >
  142. {inCart ? t('home:in') : t('home:add')}
  143. </Button>
  144. </Box>
  145. </Box>
  146. );
  147. };
  148. export default ProductInfo;