TableLine.jsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import React from 'react';
  2. import {Box, Button, Grid, Typography} from "@mui/material";
  3. import Link from "react-router-dom/es/Link";
  4. import {backURL} from "../actions/PathDB";
  5. import imgNotFound from "../img/catalog/imgNotFound.png";
  6. import CloseIcon from "@mui/icons-material/Close";
  7. export const ItemHeaderLine = ({text, align='left'}) => {
  8. return (
  9. <Typography
  10. color='#616161'
  11. variant='body1'
  12. letterSpacing='1px'
  13. textAlign={align}
  14. >
  15. {text || ''}
  16. </Typography>
  17. )
  18. }
  19. export const LinkProductItem = ({item: [_id, name, images], children=''}) => {
  20. return (
  21. <Link
  22. style={{
  23. textDecoration: 'none',
  24. display: 'flex',
  25. alignItems: 'center'
  26. }}
  27. to={`/good/${_id}`}
  28. >
  29. <Box
  30. minWidth='60px'
  31. maxWidth='60px'
  32. height='60px'
  33. borderRadius='10px'
  34. overflow='hidden'
  35. marginRight='20px'
  36. >
  37. <img
  38. style={{
  39. width: '100%',
  40. height: '100%',
  41. objectFit: 'cover'
  42. }}
  43. src={
  44. Array.isArray(images) && images[0]?.url ?
  45. backURL + '/' + images[0]?.url
  46. :
  47. imgNotFound
  48. }
  49. alt={name}
  50. />
  51. </Box>
  52. {children ?
  53. <Box
  54. display='flex'
  55. flexDirection='column'
  56. height='50px'
  57. justifyContent='space-around'
  58. >
  59. <ItemHeaderLine text={name}/>
  60. <ItemHeaderLine text={children}/>
  61. </Box>
  62. :
  63. <ItemHeaderLine text={name}/>
  64. }
  65. </Link>
  66. )
  67. }
  68. const AddToCart = ({good, addToCart}) => {
  69. return (
  70. <Button
  71. sx={{
  72. height: '40px',
  73. width: '70%',
  74. borderRadius: '0',
  75. color: '#000',
  76. borderColor: '#000',
  77. fontSize: '16px',
  78. fontWeight: '300'
  79. }}
  80. variant="outlined"
  81. color={"inherit"}
  82. onClick={() => addToCart(good)}
  83. >
  84. ADD TO CART
  85. </Button>
  86. )
  87. }
  88. export const RemoveFromList = ({good, onRemove}) => {
  89. return (
  90. <Button
  91. size="small"
  92. color="inherit"
  93. onClick={() => onRemove(good)}
  94. >
  95. <CloseIcon/>
  96. </Button>
  97. )
  98. }
  99. export const TableLine = ({columnName, role='header', customSizeCol}) => {
  100. const good = {
  101. '_id': columnName[0][0],
  102. 'name': columnName[0][1],
  103. 'images': columnName[0][2],
  104. 'price': columnName[1]
  105. }
  106. return (
  107. <Grid
  108. container
  109. justifyContent='space-between'
  110. marginBottom='20px'
  111. alignItems='center'
  112. >
  113. <Grid
  114. item xs={3}
  115. md={customSizeCol ? customSizeCol[0] : 5}
  116. >
  117. {
  118. role === 'header' ?
  119. <ItemHeaderLine text={columnName[0]}/>
  120. :
  121. <LinkProductItem item={columnName[0]}/>
  122. }
  123. </Grid>
  124. <Grid
  125. item xs={3}
  126. md={customSizeCol ? customSizeCol[1] : 2}
  127. >
  128. <ItemHeaderLine
  129. text={role === 'header' ? columnName[1] : '$'+columnName[1]}
  130. align={'center'}
  131. />
  132. </Grid>
  133. <Grid
  134. item xs={3}
  135. md={customSizeCol ? customSizeCol[2] : 3}
  136. display='flex'
  137. justifyContent='center'
  138. >
  139. {
  140. role === 'header' ?
  141. <ItemHeaderLine text={columnName[3]} align={'center'}/>
  142. :
  143. <AddToCart good={good} addToCart={columnName[3]}/>
  144. }
  145. </Grid>
  146. <Grid
  147. item xs={3}
  148. md={customSizeCol ? customSizeCol[3] : 1}
  149. display='flex'
  150. justifyContent='center'
  151. >
  152. {
  153. role === 'header' ?
  154. <ItemHeaderLine text={columnName[2]} align={'center'}/>
  155. :
  156. <RemoveFromList good={good} onRemove={columnName[2]}/>
  157. }
  158. </Grid>
  159. </Grid>
  160. )
  161. }