import { debounce } from 'lodash' import { SearchIcon, XIcon } from 'lucide-react' import { useRef } from 'react' import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from '@repo/ui/components/ui/input-group' import { useKeyPress } from '@/hooks/use-keypress' import { cn } from '@repo/ui/lib/utils' export function SearchForm({ placeholder, className, onChange, defaultValue = '', ...props }: { placeholder?: React.ReactNode className?: string onChange?: (value: string) => void defaultValue?: string } & React.HTMLAttributes) { const inputRef = useRef(null) useKeyPress('/', () => { inputRef.current?.focus() }) const debouncedOnChange = debounce((value: string) => { onChange?.(value) }, 200) return ( debouncedOnChange(e.target.value)} {...props} /> {placeholder && ( {placeholder} )} {defaultValue && ( { if (inputRef.current) { inputRef.current.value = '' } onChange?.('') inputRef.current?.focus() }} > )} ) }