import CustomTextField from "./CustomTextField"; import type { ChangeEvent, KeyboardEvent, FocusEvent } from "react"; import type { SxProps, Theme } from "@mui/material"; interface CustomNumberFieldProps { placeholder: string; onChange?: (event: ChangeEvent) => void; onKeyDown?: (event: KeyboardEvent) => void; onBlur?: (event: FocusEvent) => void; value: string; sx?: SxProps; min?: number; max?: number; } export default function CustomNumberField({ placeholder, value, sx, onChange, onKeyDown, onBlur, min = -999999999, max = 999999999, }: CustomNumberFieldProps) { const onInputChange = (event: ChangeEvent) => { const inputValue = event.target.value; if ( Number(inputValue) >= min && Number(inputValue) <= max && (inputValue === "" || inputValue.match(/^\d*$/) || (inputValue[0] === "-" && inputValue.slice(1).match(/^\d*$/))) ) { onChange?.({ ...event, target: { ...event.target, value: inputValue } }); } }; return ( ); }