37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
import * as React from "react";
|
|
import { Eye, EyeOff } from "lucide-react";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
const PasswordInput = React.forwardRef(({ className, ...props }, ref) => {
|
|
const [showPassword, setShowPassword] = React.useState(false);
|
|
|
|
return (
|
|
<div className="relative">
|
|
<input
|
|
type={showPassword ? "text" : "password"}
|
|
className={cn(
|
|
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 pr-10 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
|
className
|
|
)}
|
|
ref={ref}
|
|
{...props}
|
|
/>
|
|
<button
|
|
type="button"
|
|
onClick={() => setShowPassword(!showPassword)}
|
|
className="absolute right-3 top-1/2 -translate-y-1/2 text-[var(--slate-muted)] hover:text-[var(--slate-dark)] transition-colors focus:outline-none"
|
|
tabIndex={-1}
|
|
>
|
|
{showPassword ? (
|
|
<EyeOff className="h-5 w-5" />
|
|
) : (
|
|
<Eye className="h-5 w-5" />
|
|
)}
|
|
</button>
|
|
</div>
|
|
);
|
|
});
|
|
PasswordInput.displayName = "PasswordInput";
|
|
|
|
export { PasswordInput };
|