-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPasswordInput.jsx
44 lines (41 loc) · 1.1 KB
/
PasswordInput.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { useState } from "react";
import { FaEye, FaEyeSlash } from "react-icons/fa";
import BaseInput from "./BaseInput";
/**
* An <input> with toggle to show / hide the password
*
* @param {object} props
* @returns
*/
export default function PasswordInput({
label = "Password",
showError,
errorMessage = "Please enter your password",
...props
}) {
const [showPassword, setShowPassword] = useState(false);
function togglePasswordVisibility() {
setShowPassword(!showPassword);
}
return (
<>
<label htmlFor="password">{label}</label>
<span className="userfront-password-input-container">
<BaseInput
type={showPassword ? "text" : "password"}
name="password"
aria-describedby="userfront-password-rules"
showError={showError}
errorMessage={errorMessage}
{...props}
/>
<div
className="userfront-password-toggle"
onClick={togglePasswordVisibility}
>
{showPassword ? <FaEyeSlash size="15px" /> : <FaEye size="15px" />}
</div>
</span>
</>
);
}