import React from 'react' import type { NumberInputProps } from '@toptal/picasso-number-input' import { NumberInput as PicassoNumberInput } from '@toptal/picasso-number-input' import type { FieldValidator } from 'final-form' import { validators } from '../utils' import type { FieldProps } from '../Field' import type { Props as FieldLabelProps } from '../FieldLabel' import FieldLabel from '../FieldLabel' import InputField from '../InputField' export type Props = NumberInputProps & FieldProps & FieldLabelProps const MIN = -2147483648 const MAX = 2147483647 const { composeValidators } = validators export const NumberInput = (props: Props) => { const { min = MIN, max = MAX, validate, label, labelEndAdornment, titleCase, ...rest } = props const validateNumberLimits: FieldValidator< NumberInputProps['value'] > = value => { if (Number(value) > max) { return `Must be less than or equal to ${max}.` } if (Number(value) < min) { return `Must be greater than or equal to ${min}.` } } return ( min={min} max={max} {...rest} validate={composeValidators([validateNumberLimits, validate])} label={ label ? ( ) : null } > {(inputProps: NumberInputProps) => { return }} ) } NumberInput.displayName = 'NumberInput' export default NumberInput