TableLine.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {Box, Button, Grid, Typography} from "@mui/material";
  2. import Link from "react-router-dom/es/Link";
  3. import {backURL} from "../actions/PathDB";
  4. import imgNotFound from "../img/catalog/imgNotFound.png";
  5. import CloseIcon from "@mui/icons-material/Close";
  6. export const ItemHeaderLine = ({text, align='left'}) => {
  7. return (
  8. <Typography
  9. color='#616161'
  10. variant='body1'
  11. letterSpacing='1px'
  12. textAlign={align}
  13. >
  14. {text || ''}
  15. </Typography>
  16. )
  17. }
  18. export const LinkProductItem = ({item: [_id, name, images], children=''}) => {
  19. return (
  20. <Link style={{textDecoration: 'none', display: 'flex', alignItems: 'center'}} to={`/good/${_id}`}>
  21. <Box minWidth='60px' maxWidth='60px' height='60px' borderRadius='10px' overflow='hidden' marginRight='20px'>
  22. <img style={{width: '100%', height: '100%', objectFit: 'cover'}} src={images[0]?.url ? backURL + '/' + images[0]?.url : imgNotFound} alt={name}/>
  23. </Box>
  24. {children ?
  25. <Box display='flex' flexDirection='column' height='50px' justifyContent='space-around'>
  26. <ItemHeaderLine text={name}/>
  27. <ItemHeaderLine text={children}/>
  28. </Box> :
  29. <ItemHeaderLine text={name}/>
  30. }
  31. </Link>
  32. )
  33. }
  34. const AddToCart = ({good, addToCart}) => {
  35. return (
  36. <Button
  37. sx={{height: '40px', width: '70%', borderRadius: '0', color: '#000', borderColor: '#000', fontSize: '16px', fontWeight: '300'}}
  38. variant="outlined"
  39. color={"inherit"}
  40. onClick={() => addToCart(good)}
  41. >
  42. ADD TO CART
  43. </Button>
  44. )
  45. }
  46. export const RemoveFromList = ({good, onRemove}) => {
  47. return (
  48. <Button
  49. size="small"
  50. color="inherit"
  51. onClick={() => onRemove(good)}
  52. >
  53. <CloseIcon/>
  54. </Button>
  55. )
  56. }
  57. export const TableLine = ({columnName, role='header', customSizeCol}) => {
  58. const good = {'_id': columnName[0][0], 'name': columnName[0][1], 'images': columnName[0][2], 'price': columnName[1]};
  59. return (
  60. <Grid container justifyContent='space-between' marginBottom='20px' alignItems='center'>
  61. <Grid item xs={3} md={customSizeCol ? customSizeCol[0] : 5}>
  62. {role === 'header' ? <ItemHeaderLine text={columnName[0]}/> : <LinkProductItem item={columnName[0]}/>}
  63. </Grid>
  64. <Grid item xs={3} md={customSizeCol ? customSizeCol[1] : 2}>
  65. <ItemHeaderLine text={role === 'header' ? columnName[1] : '$'+columnName[1]} align={'center'}/>
  66. </Grid>
  67. <Grid item xs={3} md={customSizeCol ? customSizeCol[2] : 3} display='flex' justifyContent='center'>
  68. {role === 'header' ? <ItemHeaderLine text={columnName[3]} align={'center'}/> : <AddToCart good={good} addToCart={columnName[3]}/>}
  69. </Grid>
  70. <Grid item xs={3} md={customSizeCol ? customSizeCol[3] : 1} display='flex' justifyContent='center'>
  71. {role === 'header' ? <ItemHeaderLine text={columnName[2]} align={'center'}/> : <RemoveFromList good={good} onRemove={columnName[2]}/>}
  72. </Grid>
  73. </Grid>
  74. )
  75. }