Create passwordInput component
This commit is contained in:
@@ -9,7 +9,6 @@ import { AuthContext } from "../../contexts/auth/AuthContext.js";
|
|||||||
function LoginForm({ className }) {
|
function LoginForm({ className }) {
|
||||||
const [email, setEmail] = useState('');
|
const [email, setEmail] = useState('');
|
||||||
const [password, setPassword] = useState('');
|
const [password, setPassword] = useState('');
|
||||||
const [showPassword, setShowPassword] = useState(false);
|
|
||||||
let navigate = useNavigate();
|
let navigate = useNavigate();
|
||||||
const { login } = useContext(AuthContext);
|
const { login } = useContext(AuthContext);
|
||||||
|
|
||||||
@@ -19,10 +18,6 @@ function LoginForm({ className }) {
|
|||||||
navigate("/");
|
navigate("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggleShowPassword = () => {
|
|
||||||
setShowPassword(!showPassword);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`${className} glassCard ${styles.inputContainer}`}>
|
<div className={`${className} glassCard ${styles.inputContainer}`}>
|
||||||
<div className={styles.formgroup}>
|
<div className={styles.formgroup}>
|
||||||
@@ -35,32 +30,7 @@ function LoginForm({ className }) {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.formgroup}>
|
<div className={styles.formgroup}>
|
||||||
<div style={{ position: 'relative', width: '100%' }}>
|
<Input password={true} onChange={e => setPassword(e.target.value)} value={password} />
|
||||||
<Input
|
|
||||||
type={showPassword ? "text" : "password"}
|
|
||||||
value={password}
|
|
||||||
placeholder="Mot de passe"
|
|
||||||
onChange={e => setPassword(e.target.value)}
|
|
||||||
style={{ width: '100%' }}
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={toggleShowPassword}
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
width: '30px',
|
|
||||||
right: '10px',
|
|
||||||
top: '50%',
|
|
||||||
transform: 'translateY(-50%)',
|
|
||||||
background: 'none',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
fontSize: '16px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{showPassword ? '👁️' : '🔒'}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.logButton}>
|
<div className={styles.logButton}>
|
||||||
|
|||||||
@@ -1,13 +1,38 @@
|
|||||||
import styles from "./input.module.css";
|
import styles from "./input.module.css";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
const TextInput = ({ placeholder, onChange, value, borderStyle, ...props }) => {
|
const TextInput = ({ placeholder, onChange, value, borderStyle, password, className, ...props }) => {
|
||||||
|
|
||||||
|
const [showPassword, setShowPassword] = useState(false);
|
||||||
|
|
||||||
let inputBorderStyle = styles.square;
|
let inputBorderStyle = styles.square;
|
||||||
if (borderStyle === "square") inputBorderStyle = styles.square;
|
if (borderStyle === "square") inputBorderStyle = styles.square;
|
||||||
if(borderStyle === "rounded") inputBorderStyle = styles.rounded;
|
if(borderStyle === "rounded") inputBorderStyle = styles.rounded;
|
||||||
|
|
||||||
return <input className={`${styles.input} ${inputBorderStyle}`} onChange={onChange} placeholder={placeholder} value={value} {...props} />
|
const toggleShowPassword = () => {
|
||||||
|
setShowPassword(!showPassword);
|
||||||
|
};
|
||||||
|
|
||||||
|
if(password) return (
|
||||||
|
<div className={styles.passwordContainer}>
|
||||||
|
<TextInput
|
||||||
|
type={showPassword ? "text" : "password"}
|
||||||
|
value={value}
|
||||||
|
placeholder="Mot de passe"
|
||||||
|
onChange={onChange}
|
||||||
|
className={styles.passwordInput}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={toggleShowPassword}
|
||||||
|
className={styles.passwordBtn}
|
||||||
|
>
|
||||||
|
{showPassword ? '👁️' : '🔒'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return <input className={`${styles.input} ${inputBorderStyle} ${className}`} onChange={onChange} placeholder={placeholder} value={value} {...props} />
|
||||||
};
|
};
|
||||||
|
|
||||||
export default TextInput;
|
export default TextInput;
|
||||||
|
|||||||
@@ -30,3 +30,23 @@
|
|||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.passwordContainer {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.passwordInput {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.passwordBtn {
|
||||||
|
position: absolute;
|
||||||
|
width: 30px;
|
||||||
|
right: 10px;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user