import React, { useState } from 'react';
import { Button, Input } from '@abdalkader/component-library';
function LoginForm() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [errors, setErrors] = useState({ email: false, password: false });
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
const newErrors = {
email: !email.includes('@'),
password: password.length < 8,
};
setErrors(newErrors);
if (!newErrors.email && !newErrors.password) {
console.log('Form submitted:', { email, password });
}
};
return (
<form onSubmit={handleSubmit} style={{ maxWidth: '400px' }}>
<Input
label="Email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
error={errors.email}
errorMessage={errors.email ? 'Please enter a valid email' : undefined}
required
/>
<Input
label="Password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
error={errors.password}
errorMessage={errors.password ? 'Password must be at least 8 characters' : undefined}
helperText="Use a strong password"
required
/>
<Button type="submit" variant="primary">
Sign In
</Button>
</form>
);
}