import { useNumberFieldInfo, useTsController } from '@ts-react/form' import { useId } from 'react' import { Fieldset, Input, InputProps, Label, Theme } from 'tamagui' import { FieldError } from '../FieldError' import { Shake } from '../Shake' export const NumberField = (props: Pick) => { const { field, error, formState: { isSubmitting }, } = useTsController() const { label, defaultValue, isOptional, placeholder, minValue, maxValue } = useNumberFieldInfo() const id = useId() const disabled = isSubmitting return (
{!!label && ( )} { const num = Number(text) if (isNaN(num)) { if (!field.value) { field.onChange(defaultValue || 0) } return } if (typeof maxValue !== 'undefined' && num > maxValue) { field.onChange(maxValue) return } if (typeof minValue !== 'undefined' && num < minValue) { field.onChange(minValue) return } field.onChange(num) }} onBlur={field.onBlur} ref={field.ref} placeholder={placeholder} id={id} {...props} />
) }