import React from "react"; import { cn } from "../lib/cn"; export interface FormFieldProps extends React.HTMLAttributes { /** Label text */ label?: string; /** Whether the field is required */ required?: boolean; /** Error message (boolean shows generic error, string shows custom message) */ error?: boolean | string; /** Helper text shown below the field */ helperText?: string; /** Whether to show the field as disabled */ disabled?: boolean; /** Children (typically an Input, Textarea, or Select) */ children: React.ReactNode; } export const FormField = React.forwardRef( ({ label, required = false, error, helperText, disabled, className, children, ...props }, ref) => { const hasError = !!error; const errorMessage = typeof error === "string" ? error : null; return (
{label && ( )} {children} {errorMessage && ( {errorMessage} )} {!errorMessage && helperText && ( {helperText} )}
); }, ); FormField.displayName = "FormField";