"use client"; import { Eye, EyeOff, X } from "lucide-react"; import { cn } from "@/utils/ui"; import { Button } from "./button"; import { forwardRef, type ComponentProps } from "react"; import { useState } from "react"; interface InputProps extends ComponentProps<"input"> { showPassword?: boolean; onShowPasswordChange?: (show: boolean) => void; showClearIcon?: boolean; onClear?: () => void; containerClassName?: string; } const Input = forwardRef( ( { className, type, containerClassName, showPassword, onShowPasswordChange, showClearIcon, onClear, value, onFocus, onBlur, ...props }, ref, ) => { const [isFocused, setIsFocused] = useState(false); const isPassword = type === "password"; const showPasswordToggle = isPassword && onShowPasswordChange; const showClear = showClearIcon && onClear && value && String(value).length > 0 && isFocused; const inputType = isPassword && showPassword ? "text" : type; const hasIcons = showPasswordToggle || showClear; const iconCount = Number(showPasswordToggle) + Number(showClear); const paddingRight = iconCount === 2 ? "pr-20" : iconCount === 1 ? "pr-10" : ""; return (
{ setIsFocused(true); onFocus?.(e); }} onBlur={(e) => { setIsFocused(false); onBlur?.(e); }} {...props} /> {showClear && ( )} {showPasswordToggle && ( )}
); }, ); Input.displayName = "Input"; export { Input };