import classNames from "classnames"; import { forwardRef, useState } from "react"; import { Icon, Icons } from "../Icon"; export interface TextInputControlPropsNoLabel { onChange?: (data: string) => void; onUnFocus?: () => void; onFocus?: () => void; value?: string; name?: string; autoComplete?: string; placeholder?: string; className?: string; passwordToggleable?: boolean; } export interface TextInputControlProps extends TextInputControlPropsNoLabel { label?: string; } export const TextInputControl = forwardRef< HTMLInputElement, TextInputControlProps >( ( { onChange, onUnFocus, value, label, name, autoComplete, className, placeholder, onFocus, passwordToggleable, }, ref ) => { let inputType = "text"; const [showPassword, setShowPassword] = useState(true); if (passwordToggleable) inputType = showPassword ? "password" : "text"; const input = (
onChange && onChange(e.target.value)} value={value} name={name} autoComplete={autoComplete} onBlur={() => onUnFocus && onUnFocus()} onFocus={() => onFocus?.()} onKeyDown={(e) => e.key === "Enter" ? (e.target as HTMLInputElement).blur() : null } /> {passwordToggleable ? ( ) : null}
); if (label) { return ( ); } return input; } );