# FormFieldWrapper Component A unified form field component that automatically provides hints, validation messages, and terminology tooltips based on field type. ## Features - ✅ **Automatic hints** based on field type (speed, height, URL, email, etc.) - ✅ **Built-in validation** display with error messages - ✅ **Terminology tooltips** on labels (hover to see definitions) - ✅ **Character counting** for textareas - ✅ **50% less boilerplate** compared to manual field creation - ✅ **Type-safe** with TypeScript - ✅ **Consistent styling** across all forms ## Quick Start ### Before (Manual) ```tsx

Official website URL (must start with https:// or http://)

{errors.website_url && (

{errors.website_url.message}

)}
``` ### After (With FormFieldWrapper) ```tsx ``` ## Basic Usage ```tsx import { FormFieldWrapper } from '@/components/ui/form-field-wrapper'; import { useForm } from 'react-hook-form'; function MyForm() { const { register, formState: { errors } } = useForm(); return (
{/* Basic text input with automatic hint */} {/* Textarea with character count */} ); } ``` ## With Terminology Tooltips ```tsx ``` ## Using Presets ```tsx import { FormFieldWrapper, formFieldPresets } from '@/components/ui/form-field-wrapper'; ``` ## Available Field Types - `url` - Website URLs with protocol hint - `email` - Email addresses with format hint - `phone` - Phone numbers with flexible format hint - `slug` - URL slugs with character restrictions - `height-requirement` - Height in cm with metric hint - `age-requirement` - Age requirements - `capacity` - Capacity per hour - `duration` - Duration in seconds - `speed` - Max speed (km/h) - `height` - Max height (meters) - `length` - Track length (meters) - `inversions` - Number of inversions - `g-force` - G-force values - `source-url` - Reference URL for verification - `submission-notes` - Notes for moderators (textarea with char count) ## Available Presets ```tsx formFieldPresets.websiteUrl({}) formFieldPresets.email({}) formFieldPresets.phone({}) formFieldPresets.sourceUrl({}) formFieldPresets.submissionNotes({}) formFieldPresets.heightRequirement({}) formFieldPresets.capacity({}) formFieldPresets.duration({}) formFieldPresets.speed({}) formFieldPresets.height({}) formFieldPresets.length({}) formFieldPresets.inversions({}) formFieldPresets.gForce({}) ``` ## Custom Hints Override automatic hints with custom text: ```tsx ``` ## Hide Hints ```tsx ``` ## Migration Guide To migrate existing fields: 1. **Identify the field structure** to replace 2. **Choose appropriate `fieldType`** from the list above 3. **Add `termKey`** if field relates to terminology 4. **Replace** the entire div block with `FormFieldWrapper` Example migration: ```tsx // BEFORE

Speed must be in km/h, between 0-500. Example: "193" for 193 km/h (120 mph)

{errors.max_speed_kmh && (

{errors.max_speed_kmh.message}

)}
// AFTER ``` ## Demo View a live interactive demo at `/examples/form-field-wrapper` (in development mode) by visiting the `FormFieldWrapperDemo` component. ## Props Reference | Prop | Type | Description | |------|------|-------------| | `id` | `string` | Field identifier (required) | | `label` | `string` | Field label text (required) | | `fieldType` | `FormFieldType` | Type for automatic hints | | `termKey` | `string` | Terminology key for tooltip | | `showTermIcon` | `boolean` | Show tooltip icon (default: true) | | `required` | `boolean` | Show required asterisk | | `optional` | `boolean` | Show optional badge | | `hint` | `string` | Custom hint (overrides automatic) | | `error` | `string` | Error message from validation | | `value` | `string \| number` | Current value for char counting | | `maxLength` | `number` | Max length for char counting | | `inputProps` | `InputProps` | Props to pass to Input | | `textareaProps` | `TextareaProps` | Props to pass to Textarea | | `className` | `string` | Additional wrapper classes | | `hideHint` | `boolean` | Hide automatic hint | ## Benefits 1. **Consistency** - All fields follow the same structure 2. **Less Code** - ~50% reduction in boilerplate 3. **Smart Defaults** - Automatic hints based on field type 4. **Built-in Terminology** - Hover tooltips for technical terms 5. **Easy Updates** - Change hints in one place, updates everywhere 6. **Type Safety** - TypeScript ensures correct usage