-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinput.tsx
More file actions
58 lines (55 loc) · 1.49 KB
/
input.tsx
File metadata and controls
58 lines (55 loc) · 1.49 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
47
48
49
50
51
52
53
54
55
56
57
58
import { tv } from "tailwind-variants";
import { RenderFieldProps } from "../Input.types";
import { usePasswordToggle } from "@/hooks/usePasswordToggle";
const inputClass = tv({
base: "body-3 w-full rounded-xl p-4 bg-white bg-opacity-10 ring-0 outline-0 focus:ring-1 active:ring-1 focus:ring-white active:ring-white transition-all ease-in-out duration-300 text-white",
variants: {
error: {
true: "border border-error-600",
false: "",
},
withIcon: {
true: "pr-12", // Add padding to the right to accommodate the icon
},
},
});
const Input = ({
type,
disabled,
className,
errors,
inputProps,
inputRef,
handleChange,
defaultValue,
name,
ref,
props,
}: RenderFieldProps) => {
const { showPassword, PasswordToggleIcon } = usePasswordToggle();
console.log("type", type);
return (
<div className="relative w-full">
<input
defaultValue={defaultValue}
className={inputClass({
error: !disabled && errors[name] !== undefined,
withIcon: type === "password",
className,
})}
disabled={disabled}
id={name}
type={type === "password" && showPassword ? "text" : type}
{...inputProps}
onChange={handleChange}
{...props}
ref={(e) => {
if (typeof inputRef === "function") inputRef(e);
if (typeof ref === "function") ref(e);
}}
/>
{type === "password" && PasswordToggleIcon}
</div>
);
};
export default Input;