import classnames from 'classnames'; import React, { Ref } from 'react'; import { connectField, HTMLFieldProps } from 'uniforms'; import wrapField from './wrapField'; export type NumFieldProps = HTMLFieldProps< number, HTMLDivElement, { decimal?: boolean; inputClassName?: string; inputRef?: Ref; } >; function Num(props: NumFieldProps) { return wrapField( props, { const parse = props.decimal ? parseFloat : parseInt; const value = parse(event.target.value); props.onChange(isNaN(value) ? undefined : value); }} placeholder={props.placeholder} readOnly={props.readOnly} ref={props.inputRef} step={props.step || (props.decimal ? 0.01 : 1)} type="number" value={props.value ?? ''} />, ); } export default connectField(Num, { kind: 'leaf' });