import React, { useRef, useState } from 'react'; import { useTheme } from 'styled-components'; import { CloseIcon, SearchIcon } from '../../icons'; import Button from '../Button'; import CircleLoader from '../CircleLoader'; import { ISearchInputProps } from './interfaces'; import { ClearButtonWrapper, IconWrapper, SearchButtonWrapper, StyledInput, Wrapper, } from './styles'; const SearchInput = ({ value, placeholder, icon, isLoading, isClearable = true, isMobile = false, onChange, onClear, onFocus, onBlur, onSearchClick, onKeyDown, iconSize, inputHeight, inputWidth, fontSize, }: ISearchInputProps) => { const theme = useTheme(); const inputRef = useRef(null); const [isFocused, setIsFocused] = useState(false); const showClear = Boolean(isClearable && value); const handleFocus = () => { setIsFocused(true); onFocus?.(); }; const handleBlur = () => { setIsFocused(false); onBlur?.(); }; const handleKeydown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' || e.code === 'Enter' || e.keyCode === 13) { e.preventDefault(); e.stopPropagation(); onSearchClick?.(); } onKeyDown?.(e); }; return ( {isLoading ? ( ) : ( icon || ( ) )} {showClear && ( )}