import React from 'react'; import { clsx } from 'clsx'; export interface FormFieldProps { label?: string; description?: string; error?: string; required?: boolean; children: React.ReactNode; className?: string; labelClassName?: string; errorClassName?: string; } /** * Form field wrapper with label, description, and error */ export const FormField = ({ label, description, error, required, children, className, labelClassName, errorClassName, }: FormFieldProps) => { const fieldId = React.useId(); return (
{label && ( )} {description &&

{description}

}
{React.isValidElement(children) ? React.cloneElement(children as React.ReactElement, { id: fieldId, 'aria-invalid': error ? 'true' : 'false', 'aria-describedby': error ? `${fieldId}-error` : undefined, }) : children}
{error && ( )}
); };