tickethub/frontend/src/components/ui/Input.tsx

25 lines
896 B
TypeScript

import { InputHTMLAttributes, forwardRef } from 'react'
interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
label?: string
error?: string
hint?: string
}
export const Input = forwardRef<HTMLInputElement, InputProps>(
({ label, error, hint, className = '', ...props }, ref) => (
<div className="space-y-1">
{label && <label className="block text-sm font-medium text-gray-700">{label}</label>}
<input
ref={ref}
className={`w-full border rounded-lg px-4 py-2.5 text-gray-900 placeholder-gray-400
focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent
${error ? 'border-red-500' : 'border-gray-300'} ${className}`}
{...props}
/>
{hint && !error && <p className="text-xs text-gray-500">{hint}</p>}
{error && <p className="text-xs text-red-500">{error}</p>}
</div>
)
)