import React, { useEffect, useRef, useState } from "react"; import useOutsideClick from "../../../_helpers/customHook/useOutsideClick"; import "./index.scss"; import classnames from "classnames"; // interface Props { // value: string | number; // setValue: (..._args: any[]) => void; // name: string; // placeholder?: string; // required?: boolean; // type: string; // className?: string; // label?: string; // style?: any; // isWarning?: boolean; // setIsWarning?: (..._args: any[]) => void; // setIcon?: () => any; // min?: number; // max?: number; // isHiddenClear?: boolean; // } const InputText = (props) => { const $inputRef = useRef(null); const [isFocus, setIsFocus] = useState(false); const isFocusState = useRef(false); const [showPw, setShowPw] = useState(false); useEffect(() => { isFocusState.current = isFocus; }, [isFocus]); useOutsideClick($inputRef, () => { if (isFocusState.current) { setIsFocus(false); } }); /** * togglePw */ const togglePw = () => { setShowPw(!showPw); }; /** * renderType: render type input */ const renderType = () => { if (props.type === "password") { return !showPw ? "password" : "text"; } return props.type; }; /** * changeValue: input change value * @param e event */ const changeValue = (e) => { // if (e.target.value === " ") { // return; // } // if ( // e.target.value?.length > 2 && // e.target.value[e.target.value.length - 2] === " " && // e.target.value[e.target.value.length - 1] === " " // ) { // return; // } if (props.removeWarningOnType && props.errorText) { props.setErrorText && props.setErrorText(""); } else if (props.errorText && !e.target.value) { props.setErrorText && props.setErrorText(""); } if (props.type === "password") { // props.setValue(e.target.value?.trim()); props.setValue(e.target.value); } else { props.setValue(e.target.value); } }; // Handle Reset Value Search const handleResetValue = () => { props.handleResetValueSearch("reset"); }; // Handle Checked box const handleCheckedBoxValue = () => { props.handleCheckedBox(); }; return (