import React, { useRef, useImperativeHandle } from "react"; import type { InputProps } from "./types"; import InputTheme from "./inputTheme"; import { useInput } from "../../hooks/useInput"; const TEInput: React.FC = /*#__PURE__*/ React.forwardRef< HTMLInputElement, InputProps >( ( { className, size = "base", value, defaultValue, id, wrapperTag: WrapperTag = "div", label, onChange, children, labelRef, labelID, type, onBlur, readonly = false, theme: customTheme, formWhite = false, counter = false, maxLength, ...props }, ref ) => { const innerRef = useRef(null); useImperativeHandle(ref, () => innerRef.current as HTMLInputElement); const theme = { ...InputTheme, ...customTheme }; const { labelReference, labelWidth, newValue, setWidth, setFocus, handleChange, handleBlur, inputClasses, labelClasses, notchLeadingClasses, notchMiddleClasses, notchTrailingClasses, } = useInput( innerRef, labelRef, value, defaultValue, onBlur, onChange, counter, maxLength, theme, size, className, formWhite ); return ( { handleBlur(value); setFocus(false); }} onChange={handleChange} onFocus={() => { setWidth; setFocus(true); }} value={value} defaultValue={defaultValue} id={id} ref={innerRef} maxLength={maxLength} {...props} /> {label && ( )}
{children}
{counter && maxLength !== undefined && maxLength > 0 && (
{newValue?.toString().length || 0} / {maxLength}
)}
); } ); export default TEInput;