import { useRef, type FC, type KeyboardEvent, type ChangeEventHandler, type ChangeEvent, type InputHTMLAttributes, } from 'react'; import SearchIcon from '../svg/search.svg'; import SpinnerIcon from '../svg/spinner.svg'; import CloseIcon from '../svg/times.svg'; import '../styles/components/search-input.scss'; type Props = { /** * The value to display in the text input. */ value?: string; /** * Value change callback for the text input component. */ onChange?: ChangeEventHandler; /** * Key pressed callback for the text input component. */ onKeyDown?: (event: KeyboardEvent) => void; /** * Text to place in the text input component in the absence of value. */ placeholder?: string; /** * Text to place in the text input component in the absence of value. */ isLoading?: boolean; } & InputHTMLAttributes; const SearchInput: FC = ({ value, onChange, onKeyDown, placeholder, isLoading = false, ...props }) => { const inputRef = useRef(null); const handleSuffixInteraction = () => { inputRef?.current?.focus(); if (value && !isLoading) { onChange?.({ target: { value: '' } } as ChangeEvent); } }; let icon; if (isLoading) { icon = ; } else if (value) { icon = ; } else { icon = ; } return ( {icon} ); }; export default SearchInput;