import clsx from 'clsx'; import React, { useState } from 'react'; import { FiMinus, FiPlus } from 'react-icons/fi'; interface NumberInputProps { className?: string; label: string; value: number; min: number; max: number; step?: number; onChange: (value: number) => void; } const NumberInput: React.FC = ({ className, label, value, onChange, min, max, step, }) => { const [localValue, setLocalValue] = useState(value); const numberStep = step || 1; const handleInput = (e: React.FormEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); }; const handleChange = (e: React.ChangeEvent) => { const newValue = e.target.value === '' ? 0 : parseFloat(e.target.value); setLocalValue(newValue); if (!isNaN(newValue)) { const roundedValue = Math.round(newValue * 10) / 10; onChange(Math.max(min, Math.min(max, roundedValue))); } }; const increment = () => { const newValue = Math.min(max, localValue + numberStep); const roundedValue = Math.round(newValue * 10) / 10; setLocalValue(roundedValue); onChange(roundedValue); }; const decrement = () => { const newValue = Math.max(min, localValue - numberStep); const roundedValue = Math.round(newValue * 10) / 10; setLocalValue(roundedValue); onChange(roundedValue); }; const handleOnBlur = () => { const newValue = Math.max(min, Math.min(max, localValue)); setLocalValue(newValue); onChange(newValue); }; return (
{label}
e.target.select()} />
); }; export default NumberInput;