diff --git a/frontend/src/components/StepperInput.jsx b/frontend/src/components/StepperInput.jsx new file mode 100644 index 0000000..b46bd4f --- /dev/null +++ b/frontend/src/components/StepperInput.jsx @@ -0,0 +1,89 @@ +function StepperInput({ + value = '', + onChange, + step = 1, + min = 0, + max = null, + label = 'Value', + suffix = '', + disabled = false, +}) { + const numValue = parseFloat(value) || 0; + + function handleInputChange(e) { + const raw = e.target.value; + if (raw === '') { + onChange(''); + return; + } + const parsed = parseFloat(raw); + if (isNaN(parsed)) return; + if (parsed < min) { + onChange(String(min)); + } else if (max !== null && parsed > max) { + onChange(String(max)); + } else { + onChange(String(parsed)); + } + } + + function handleDecrement() { + if (disabled) return; + const newVal = Math.max(min, numValue - step); + onChange(String(newVal)); + } + + function handleIncrement() { + if (disabled) return; + const newVal = numValue + step; + if (max === null || newVal <= max) { + onChange(String(newVal)); + } + } + + const canDecrement = numValue > min; + const canIncrement = max === null || numValue < max; + + return ( +