| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- import { Button, ButtonGroup, Typography } from '@mui/material';
- import { Box } from '@mui/system';
- import Image from 'next/image';
- import PropType from 'prop-types';
- import { useState } from 'react';
-
- const ProductInfo = ({ data, bColor, addProductToCart, inCart }) => {
- const [quantity, setQuantity] = useState(1);
-
- const handleIncrement = () => {
- setQuantity((prevState) => prevState + 1);
- };
-
- const handleDecrement = () => {
- if (quantity > 1) {
- setQuantity((prevState) => prevState - 1);
- }
- };
-
- return (
- <Box
- sx={{
- display: 'flex',
- flexDirection: 'column',
- alignItems: { xs: 'center' },
- width: { xs: '100%', md: '50%' },
- height: '100%',
- }}
- >
- <Typography
- variant="h3"
- sx={{ height: 60, mt: { xs: 5 }, color: 'white' }}
- >
- {data.name}
- </Typography>
- <Box
- sx={{
- width: 100,
- maxWidth: 100,
- height: 60,
- }}
- >
- <Image
- src="/images/Stars.svg"
- alt="reviews"
- width={100}
- height={50}
- ></Image>
- </Box>
- <Typography
- sx={{
- color: 'white',
- }}
- >
- {data.description}
- </Typography>
- <Box
- sx={{
- width: '100%',
- display: 'flex',
- mt: 4,
- flexDirection: { xs: 'column', md: 'row' },
- alignItems: { xs: 'center' },
- justifyContent: { md: 'center' },
- }}
- >
- <ButtonGroup
- size="small"
- aria-label="small outlined button group"
- sx={{
- height: 50,
- backgroundColor: bColor === 'light' ? '#664c47' : '#8f7772',
- color: 'white',
- border: 0,
- }}
- >
- <Button
- disableRipple
- sx={{
- color: 'white',
- fontSize: 20,
- width: 50,
- }}
- onClick={() => {
- handleDecrement();
- }}
- >
- -
- </Button>
- <Button
- disableRipple
- sx={{
- color: 'white',
- fontSize: 17,
- width: 50,
- }}
- >
- {quantity}
- </Button>
- <Button
- disableRipple
- sx={{
- color: 'white',
- fontSize: 20,
- width: 50,
- }}
- onClick={() => {
- handleIncrement();
- }}
- >
- +
- </Button>
- </ButtonGroup>
- <Button
- disableRipple
- sx={{
- mt: { xs: 2, md: 0 },
- ml: { md: 2 },
- backgroundColor: '#CBA213',
- height: 50,
- width: 150,
- color: 'white',
- }}
- disabled={inCart}
- onClick={() => addProductToCart(quantity)}
- >
- {inCart ? 'In Cart' : 'Add to cart'}
- </Button>
- </Box>
- </Box>
- );
- };
-
- ProductInfo.propTypes = {
- data: PropType.shape({
- name: PropType.string,
- description: PropType.string,
- }),
- bColor: PropType.string,
- side: PropType.string,
- addProductToCart: PropType.func,
- inCart: PropType.bool,
- };
- export default ProductInfo;
|