import React, { ChangeEvent, useState } from "react"; import "./number-input-styles.scss"; import { NumberInputProps } from "@app/models/components"; const NumberInput: React.FC = ({ id, name, label, disabled, value, min, max, onChange, placeholder, }) => { const [isFocused, setIsFocused] = useState(false); const handleInputChange = (e: ChangeEvent) => { if (e.target.value === "") { onChange(name, null); return; } const numericValue = parseInt(e.target.value, 10); if (!isNaN(numericValue)) { const clampedValue = Math.min( Math.max(numericValue, min || -Infinity), max || Infinity ); onChange(name, clampedValue); } }; const handleIncrement = () => { const numericValue = parseInt(value || "0", 10); if (!isNaN(numericValue) && (max === undefined || numericValue < max)) { onChange(name, numericValue + 1); } }; const handleDecrement = () => { const numericValue = parseInt(value || "0", 10); if (!isNaN(numericValue) && (min === undefined || numericValue > min)) { onChange(name, numericValue - 1); } }; const handleRootDivClick = () => { setIsFocused(true); }; const handleBlur = () => { setIsFocused(false); }; return (
); }; export default NumberInput;