Skip to main content
password input
View Live Demo

Does this depend on any other rangoli components?

No, Password Input is an independent component, it’s not depend on any other rangoli components.

Usage

anyComponent.tsx
<PasswordInput placeholder="Password" onChange={handleChange} />

Component Code

@app/components/PasswordInput.tsx
//Run The following command to install required shadcn component
//npx shadcn@latest add input

"use client";

import { Input } from "@/components/ui/input";
import { EyeClosed, EyeIcon } from "lucide-react";
import { useState } from "react";

type TPasswordInput = React.InputHTMLAttributes<HTMLInputElement> & {
    className?: string;
};

export default function PasswordInput({ className, ...rest }: TPasswordInput) {
    const [visibility, setVisibility] = useState(false);

    return (
        <div className="relative">
            <Input
                type={visibility ? "text" : "password"}
                className={className}
                {...rest} // Spread remaining props (like onClick, onChange, etc.)
            />
            {visibility ? (
                <EyeIcon
                    className="w-4 absolute right-5 top-1/2 -translate-y-1/2 text-muted-foreground cursor-pointer"
                    onClick={() => setVisibility((prevState) => !prevState)}
                />
            ) : (
                <EyeClosed
                    className="w-4 absolute right-5 top-1/2 -translate-y-1/2 text-muted-foreground cursor-pointer"
                    onClick={() => setVisibility((prevState) => !prevState)}
                />
            )}
        </div>
    );
}