import { cn } from '@/lib/utils' import { SearchIcon, X } from 'lucide-react' import { ComponentProps, forwardRef, useEffect, useState } from 'react' const SearchInput = forwardRef>( ({ value, onChange, className, ...props }, ref) => { const [displayClear, setDisplayClear] = useState(false) const [inputRef, setInputRef] = useState(null) useEffect(() => { setDisplayClear(!!value) }, [value]) function setRefs(el: HTMLInputElement) { setInputRef(el) if (typeof ref === 'function') { ref(el) } else if (ref) { ;(ref as React.MutableRefObject).current = el } } return (
inputRef?.focus()} /> {displayClear && ( )}
) } ) SearchInput.displayName = 'SearchInput' export default SearchInput