SetCount.jsx 1.9 KB

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