import { cn } from "@/lib/utils"; import { FormControl, FormDescription, FormField, FormItem, Input, InputProps } from "@/ui"; import { cva, type VariantProps } from "class-variance-authority"; import * as React from "react"; import { createElement } from "react"; import { FieldPath, FieldValues, UseControllerProps, useFormContext } from "react-hook-form"; import { FormErrorMessage } from "./FormErrorMessage"; import { FormLabel, FormLabelProps } from "./FormLabel"; import { FormInputProps, FormInputWithIconProps } from "./FormProps"; const formTextFieldVariants = cva("", { variants: { variant: { default: "", ghost: "border-0 focus-visible:border focus-visible:border-input focus-visible:ring-0 focus-visible:ring-offset-0 ", }, }, defaultVariants: { variant: "default", }, }); export type FormTextFieldProps< TFieldValues extends FieldValues = FieldValues, TName extends FieldPath = FieldPath > = { button?: (props?: React.PropsWithChildren) => React.ReactNode; } & InputProps & FormInputProps & Partial & FormInputWithIconProps & UseControllerProps & VariantProps; export const FormTextField = React.forwardRef( (props, ref) => { const { name, label, hint, description, placeholder, className, disabled, defaultValue, rules, type, variant, required, button, leadIcon, trailIcon, } = props; const { control } = useFormContext(); return ( { 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}}
); }} /> ); } );