import { useFieldInfo, useTsController } from '@ts-react/form' import { useId } from 'react' import { Fieldset, Input, InputProps, Label, Theme, XStack } from 'tamagui' import { z } from 'zod' import { FieldError } from '../FieldError' import { Shake } from '../Shake' export const AddressSchema = z.object({ street: z.string().min(4), zipCode: z.string().regex(/\d{5}/, 'ZIP code should contain only 5 integers'), }) export const AddressField = (props: Pick) => { const { field, error, formState: { isSubmitting }, } = useTsController>() const { label } = useFieldInfo() const id = useId() const disabled = isSubmitting return (
field.onChange({ ...field.value, street })} onBlur={field.onBlur} ref={field.ref} placeholder="e.g. 4116 Pretty View Lane" id={`${id}-street`} {...props} />
field.onChange({ ...field.value, zipCode })} onBlur={field.onBlur} ref={field.ref} placeholder="e.g. 12345" id={`${id}-zip-code`} {...props} />
) }