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.

TabContent.jsx 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { Button, Grid, Tab, Tabs, Typography } from '@mui/material';
  2. import { Box } from '@mui/system';
  3. import { useState } from 'react';
  4. import TabPanel from '../tab-panel/TabPanel';
  5. const TabContent = ({
  6. description,
  7. inCart,
  8. price,
  9. category,
  10. addProductToCart,
  11. }) => {
  12. const [value, setValue] = useState(0);
  13. const handleChange = (event, newValue) => {
  14. setValue(newValue);
  15. };
  16. function a11yProps(index) {
  17. return {
  18. id: `simple-tab-${index}`,
  19. 'aria-controls': `simple-tabpanel-${index}`,
  20. };
  21. }
  22. return (
  23. <Grid item xs={12} md={6}>
  24. <Tabs
  25. sx={{
  26. '& button:focus': {
  27. borderTop: '1px solid black',
  28. borderLeft: '1px solid black',
  29. borderRight: '1px solid black',
  30. borderRadius: '5px 5px 0 0',
  31. borderBottom: 'none',
  32. },
  33. }}
  34. value={value}
  35. onChange={handleChange}
  36. aria-label="basic tabs example"
  37. >
  38. <Tab
  39. sx={{
  40. width: '50%',
  41. }}
  42. label="Purchase"
  43. {...a11yProps(0)}
  44. />
  45. <Tab sx={{ width: '50%' }} label="Category" {...a11yProps(1)} />
  46. </Tabs>
  47. <TabPanel value={value} index={0}>
  48. <Box flexGrow={2} sx={{ pb: { xs: '70px' } }}>
  49. <Typography>{description}</Typography>
  50. </Box>
  51. <Box
  52. sx={{
  53. display: { xs: 'flex' },
  54. flexDirection: { xs: 'column' },
  55. justifyContent: { xs: 'center' },
  56. alignItems: { xs: 'center', md: 'flex-end' },
  57. }}
  58. >
  59. <Typography mb={2}>${price}</Typography>
  60. <Button
  61. disabled={inCart}
  62. onClick={() => addProductToCart(1)}
  63. sx={{
  64. backgroundColor: '#CBA213',
  65. height: 50,
  66. width: { xs: '300px', md: '150px' },
  67. color: 'white',
  68. }}
  69. >
  70. {inCart ? 'In Cart' : 'Add to cart'}
  71. </Button>
  72. </Box>
  73. </TabPanel>
  74. <TabPanel value={value} index={1}>
  75. <Box sx={{ mb: { xs: '60px' } }}>{category}</Box>
  76. </TabPanel>{' '}
  77. </Grid>
  78. );
  79. };
  80. export default TabContent;