import * as React from "react"; import { Eye, EyeOff, X } from "lucide-react"; import { cn } from "../../lib/utils"; import { Button } from "./button"; interface InputProps extends React.ComponentProps<"input"> { showPassword?: boolean; onShowPasswordChange?: (show: boolean) => void; showClearIcon?: boolean; onClear?: () => void; } const Input = React.forwardRef( ( { className, type, showPassword, onShowPasswordChange, showClearIcon, onClear, value, onFocus, onBlur, ...props }, ref ) => { const [isFocused, setIsFocused] = React.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 };