25 lines
874 B
TypeScript
25 lines
874 B
TypeScript
import { useState } from "react";
|
|
import { Eye, EyeOff } from "lucide-react";
|
|
import { Input } from "@/components/ui/input";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
export function PasswordInput({
|
|
className,
|
|
...props
|
|
}: Omit<React.ComponentProps<"input">, "type">) {
|
|
const [visible, setVisible] = useState(false);
|
|
return (
|
|
<div className={cn("relative", className)}>
|
|
<Input type={visible ? "text" : "password"} className="pr-9" {...props} />
|
|
<button
|
|
type="button"
|
|
onClick={() => setVisible((v) => !v)}
|
|
className="absolute right-0 top-0 flex h-9 w-9 items-center justify-center text-muted-foreground hover:text-foreground"
|
|
aria-label={visible ? "Hide password" : "Show password"}
|
|
tabIndex={-1}
|
|
>
|
|
{visible ? <EyeOff className="w-4 h-4" /> : <Eye className="w-4 h-4" />}
|
|
</button>
|
|
</div>
|
|
);
|
|
} |