import { cn } from "@/lib/utils"; import { FormControl, FormDescription, FormField, FormItem, FormMessage, Input, InputProps, } from "@/ui"; import * as React from "react"; import { createElement } from "react"; import { FieldErrors, FieldPath, FieldValues, UseControllerProps } from "react-hook-form"; import { FormLabel, FormLabelProps } from "./FormLabel"; import { FormInputProps, FormInputWithIconProps } from "./FormProps"; export type FormTextFieldProps< TFieldValues extends FieldValues = FieldValues, TName extends FieldPath = FieldPath > = { button?: (props?: React.PropsWithChildren) => React.ReactNode; } & InputProps & FormInputProps & Partial & FormInputWithIconProps & UseControllerProps & { errors?: FieldErrors; }; export const FormTextField = React.forwardRef< HTMLDivElement, React.HTMLAttributes & FormTextFieldProps >((props, ref) => { const { label, placeholder, hint, description, required, className, leadIcon, trailIcon, button, disabled, // eslint-disable-next-line @typescript-eslint/no-unused-vars errors, name, control, type, } = props; return ( ( {label && }
{leadIcon && (
{React.createElement( leadIcon, { className: "h-5 w-5 text-muted-foreground", "aria-hidden": true, }, null )}
)} {trailIcon && (
{createElement( trailIcon, { className: "h-5 w-5 text-muted-foreground", "aria-hidden": true, }, null )}
)}
{button && <>{createElement(button)}}
{description && {description}}
)} /> ); });