import { forwardRef, PropsWithoutRef } from "react"; import { Link, Routes } from "blitz"; import { useFormContext } from "react-hook-form"; import clsx from "clsx"; export interface LabeledTextFieldProps extends PropsWithoutRef { /** Field name. */ name: string; /** Field label. */ label: string; /** Field type. Doesn't include radio buttons and checkboxes */ type?: "text" | "password" | "email" | "number"; showForgotPasswordLabel?: boolean; } export const LabeledTextField = forwardRef( ({ label, name, showForgotPasswordLabel, ...props }, ref) => { const { register, formState: { isSubmitting, errors }, } = useFormContext(); const error = Array.isArray(errors[name]) ? errors[name].join(", ") : errors[name]?.message || errors[name]; return (
{error ? (
{error}
) : null}
); }, ); export default LabeledTextField;