-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordInputToggle
More file actions
46 lines (44 loc) · 1.48 KB
/
PasswordInputToggle
File metadata and controls
46 lines (44 loc) · 1.48 KB
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
45
46
export const PasswordInputToggle = forwardRef((props, passwordRef) => {
const { inputValue, inputLabel, inputName, onChange, tooltip } = props;
const passwordToggle = (e) => {
const password = e.current;
if (password.type === "password") {
password.type = "text";
} else {
password.type = "password";
}
password.focus();
};
return (
<div className="relative">
{tooltip?.enabled && <ToolTip>{tooltip?.message}</ToolTip>}
<div className="absolute inset-y-0 right-0 flex items-center px-2">
<input className="hidden js-password-toggle" id="toggle" type="checkbox" />
<div
className="group bg-none cursor-pointer js-password-label"
htmlFor="toggle"
onClick={(e) => passwordToggle(passwordRef)}
>
<EyeIcon width={20} height={20} className="text-gray-200 group-hover:text-gray-500" />
</div>
</div>
<div
htmlFor={inputName}
className="absolute left-4 px-2 bg-[#ffffff] text-[#919EAB] text-xs"
style={{ transform: "translateY(-45%)" }}
>
<label dangerouslySetInnerHTML={{ __html: inputLabel }} />
</div>
<input
type="password"
id={inputName}
name={inputName}
className="w-full pl-10 pr-4 py-3 border rounded-md focus:outline-none resize-none "
placeholder=""
ref={passwordRef}
defaultValue={inputValue}
onChange={(e) => onChange(e)}
/>
</div>
);
});