import { Field, FieldDescription, FieldError, FieldLabel, Input } from "@repo/shadcn-ui/components"; import { cn } from "@repo/shadcn-ui/lib/utils"; import { Control, Controller, FieldPath, FieldValues, useFormState } from "react-hook-form"; import { CommonInputProps } from "./types.js"; type Normalizer = (value: string) => string; type TextFieldProps = CommonInputProps & { control: Control; name: FieldPath; label?: string; description?: string; orientation?: "vertical" | "horizontal" | "responsive", inputClassName?: string; }; export function TextField({ control, name, label, description, required = false, readOnly = false, orientation = 'vertical', className, inputClassName, ...inputRest }: TextFieldProps) { const { isSubmitting, isValidating } = useFormState({ control, name }); const disabled = isSubmitting || inputRest.disabled; function handleKeyDown(e: React.KeyboardEvent) { if (e.key === "Enter") { const form = (e.currentTarget as HTMLInputElement).form; if (form) form.requestSubmit(); } } return ( { return ( {label && {label}} {false && {description || "\u00A0"}} ); }} /> ); }