Files
home/Projects/kompose/news/apps/web/src/components/form-controlled-input.tsx

49 lines
1.0 KiB
TypeScript
Raw Normal View History

2025-10-08 10:35:48 +02:00
import { Control, FieldPath, FieldValues } from "react-hook-form"
import type { ComponentProps } from "react"
import {
FormField,
FormItem,
FormLabel,
FormControl,
Input,
FormDescription,
FormMessage,
} from "@repo/ui"
interface FormControlledInputProps<
TFieldValues extends FieldValues = FieldValues,
> {
control: Control<TFieldValues>
name: FieldPath<TFieldValues>
label: string
description?: string
inputProps?: ComponentProps<typeof Input>
}
export function FormControlledInput<
TFieldValues extends FieldValues = FieldValues,
>({
control,
name,
label,
description,
inputProps,
}: FormControlledInputProps<TFieldValues>) {
return (
<FormField
control={control}
name={name}
render={({ field }) => (
<FormItem>
<FormLabel>{label}</FormLabel>
<FormControl>
<Input {...inputProps} {...field} />
</FormControl>
{description && <FormDescription>{description}</FormDescription>}
<FormMessage />
</FormItem>
)}
/>
)
}