import clsx from 'clsx'; import { useEffect, useState } from 'react'; import { Button, FormControl } from 'react-bootstrap'; import { TbMinus, TbPlus } from 'react-icons/tb'; const TouchSpinInput = ({ min = 0, max = 100, value, setValue, className, inputClassName, buttonClassName, variant = 'light', size, ...props }) => { const [localValue, setLocalValue] = useState(value ?? 0); const increment = () => { if (!props.readOnly) { setLocalValue(prev => { if (prev >= max) return prev; return prev + 1; }); } }; const decrement = () => { if (!props.readOnly) { setLocalValue(prev => { if (prev <= min) return prev; return prev - 1; }); } }; const handleChange = e => { const val = e.target.value; if (val === '') { setLocalValue(0); return; } const newValue = parseInt(val); if (newValue < min) { setLocalValue(min); return; } if (newValue > max) { setLocalValue(max); return; } setLocalValue(newValue); }; useEffect(() => { if (setValue) { setValue(localValue); } }, [localValue]); return
; }; export default TouchSpinInput;