import type { FieldProps } from 'formik'; import { Field as FormikField } from 'formik'; import type { InputHTMLAttributes, TextareaHTMLAttributes } from 'react'; import { forwardRef } from 'react'; import tw, { styled } from 'twin.macro'; import Label from '@/components/elements/Label'; import Input, { Textarea } from '@/components/elements/Input'; import InputError from '@/components/elements/InputError'; interface OwnProps { name: string; light?: boolean; label?: string; description?: string; validate?: (value: any) => undefined | string | Promise; } type Props = OwnProps & Omit, 'name'>; const Field = forwardRef( ({ id, name, light = false, label, description, validate, ...props }, ref) => ( {({ field, form: { errors, touched } }: FieldProps) => (
{label && ( )} {touched[field.name] && errors[field.name] ? (

{(errors[field.name] as string).charAt(0).toUpperCase() + (errors[field.name] as string).slice(1)}

) : description ? (

{description}

) : null}
)}
), ); Field.displayName = 'Field'; export default Field; type TextareaProps = OwnProps & Omit, 'name'>; export const TextareaField = forwardRef(function TextareaField( { id, name, light = false, label, description, validate, className, ...props }, ref, ) { return ( {({ field, form: { errors, touched } }: FieldProps) => (
{label && ( )}