/** * Gating Form Field Component * * Individual form field with label, input, and error display. */ import React from 'react'; import type { GatingInfoField, GatingConfig } from '../types/gating'; import { t } from '../i18n/config'; export interface GatingFormFieldProps { /** Field name (name, email, phone, company) */ field: GatingInfoField; /** Field value */ value: string; /** Called when field value changes */ onChange: (value: string) => void; /** Error message (translated) */ error?: string; /** Is field required */ required: boolean; /** Gating configuration (for custom translations) */ config: GatingConfig; } /** * Individual form field component */ export function GatingFormField(props: GatingFormFieldProps): React.ReactElement { const { field, value, onChange, error, required, config } = props; // Get field-specific attributes const inputType = field === 'email' ? 'email' : field === 'phone' ? 'tel' : 'text'; const inputMode = field === 'email' ? 'email' : field === 'phone' ? 'tel' : 'text'; // Get translated label and placeholder const label = config.translations?.labels?.[field] || t(`labels.${field}`); const placeholder = config.translations?.placeholders?.[field] || t(`placeholders.${field}`); return (
{/* Label */} {/* Input */} onChange(e.target.value)} placeholder={placeholder} required={required} aria-invalid={!!error} aria-describedby={error ? `gating-${field}-error` : undefined} style={{ width: '100%', padding: '0.75rem', fontSize: '1rem', border: error ? '1px solid #c33' : '1px solid #ddd', borderRadius: '6px', backgroundColor: '#fff', transition: 'border-color 0.2s', boxSizing: 'border-box', outline: 'none', }} onFocus={(e) => { if (!error) { e.currentTarget.style.borderColor = '#007bff'; } }} onBlur={(e) => { if (!error) { e.currentTarget.style.borderColor = '#ddd'; } }} /> {/* Error Message */} {error && ( )}
); }