import type { FC } from 'react' import { useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { RiCloseCircleFill, RiSearchLine } from '@remixicon/react' import cn from '@/utils/classnames' type SearchInputProps = { placeholder?: string className?: string value: string onChange: (v: string) => void white?: boolean } const SearchInput: FC = ({ placeholder, className, value, onChange, white, }) => { const { t } = useTranslation() const [focus, setFocus] = useState(false) const isComposing = useRef(false) const [compositionValue, setCompositionValue] = useState('') return (
{ const newValue = e.target.value if (isComposing.current) setCompositionValue(newValue) else onChange(newValue) }} onCompositionStart={() => { isComposing.current = true setCompositionValue(value) }} onCompositionEnd={(e) => { isComposing.current = false setCompositionValue('') onChange(e.currentTarget.value) }} onFocus={() => setFocus(true)} onBlur={() => setFocus(false)} autoComplete="off" /> {value && (
{ onChange('') }} >
)}
) } export default SearchInput