39 lines
1019 B
TypeScript
39 lines
1019 B
TypeScript
import React from 'react';
|
|
|
|
export interface FormFieldProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
label: string;
|
|
error?: string;
|
|
required?: boolean;
|
|
helpText?: string;
|
|
}
|
|
|
|
export const FormField: React.FC<FormFieldProps> = ({
|
|
label,
|
|
error,
|
|
required,
|
|
helpText,
|
|
className = '',
|
|
...props
|
|
}) => {
|
|
return (
|
|
<div className="space-y-1">
|
|
<label className="block text-sm font-medium text-gray-700">
|
|
{label}
|
|
{required && <span className="text-red-500 ml-1">*</span>}
|
|
</label>
|
|
<input
|
|
className={`w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-[#667eea] focus:border-transparent transition-all ${
|
|
error ? 'border-red-300 bg-red-50' : 'border-gray-300'
|
|
} ${className}`}
|
|
{...props}
|
|
/>
|
|
{helpText && !error && (
|
|
<p className="text-xs text-gray-500">{helpText}</p>
|
|
)}
|
|
{error && (
|
|
<p className="text-xs text-red-600">{error}</p>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|