import React, { useState } from "react"; import styles from "./InputField.module.css"; interface InputFieldProps { label: string; value: string; width?: string; type?: string; icon?: React.ComponentType; onChange?: (event: React.ChangeEvent) => void; onIconMouseDown?: ( event: React.MouseEvent, ) => void; onFocus?: React.FocusEventHandler; onBlur?: React.FocusEventHandler; children?: React.ReactNode; onKeyDown?: React.KeyboardEventHandler; inputRef?: React.Ref; autoComplete?: string; } function BaseInputField(props: Readonly) { const { label, value, width = "325px", type = "text", icon: IconComponent, onIconMouseDown, onChange, onFocus, onBlur, children, inputRef, onKeyDown, autoComplete, } = props; const inlineStyles: React.CSSProperties = { width: width, }; const [isInternalFocused, setIsInternalFocused] = useState(false); function handleFocus(event: React.FocusEvent): void { setIsInternalFocused(true); if (onFocus) { onFocus(event); } } function handleBlur(event: React.FocusEvent): void { setIsInternalFocused(false); if (onBlur) { onBlur(event); } } const shouldFloat = isInternalFocused || value !== ""; return (
{children ? (
{children}
) : ( IconComponent && ( ) )}
); } export default BaseInputField;