SetCount.jsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {Box, Button} from "@mui/material";
  2. import {useEffect, useState} from "react";
  3. export const SetCount = ({onCount, defaultValue=1, height=55, width=50}) => {
  4. let [count, setCount] = useState(defaultValue)
  5. useEffect(() => {
  6. onCount(count)
  7. }, [count, onCount])
  8. return (
  9. <Box
  10. sx={{
  11. display: 'flex',
  12. flexWrap: 'no-wrap'
  13. }}
  14. >
  15. <Button
  16. sx={{height: `${height}px`,
  17. width: `${width}px`,
  18. borderRadius: '0',
  19. color: '#000',
  20. borderColor: '#000',
  21. fontSize: '30px',
  22. fontWeight: '300'
  23. }}
  24. variant="outlined"
  25. color={"inherit"}
  26. onClick={() => setCount(count === 1 ? count : count-1)}
  27. >
  28. -
  29. </Button>
  30. <input
  31. disabled
  32. value={count}
  33. style={{
  34. boxSizing: 'border-box',
  35. height: `${height}px`,
  36. width: `${width+10}px`,
  37. textAlign: 'center',
  38. border: '0',
  39. backgroundColor: '#eaeaea'
  40. }}
  41. />
  42. <Button
  43. sx={{
  44. height: `${height}px`,
  45. width: `${width}px`,
  46. borderRadius: '0',
  47. color: '#000',
  48. borderColor: '#000',
  49. fontSize: '30px',
  50. fontWeight: '300'
  51. }}
  52. variant="outlined"
  53. color={"inherit"}
  54. onClick={() => setCount(count === 100 ? count : count+1)}
  55. >
  56. +
  57. </Button>
  58. </Box>
  59. )
  60. }