forked from u14app/gemini-next-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchBar.tsx
46 lines (42 loc) · 1.19 KB
/
SearchBar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use client'
import { useState, memo } from 'react'
import { Search, X } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { Input } from '@/components/ui/input'
import { cn } from '@/utils'
import { isFunction } from 'lodash-es'
type Props = {
className?: string
onSearch: (text: string) => void
onClear?: () => void
}
function SearchBar(props: Props) {
const { t } = useTranslation()
const [query, setQuery] = useState<string>('')
const handleClear = () => {
setQuery('')
if (isFunction(props.onClear)) props.onClear()
}
return (
<div className={cn('relative w-full', props.className)}>
<Search className="absolute left-2 top-3 h-4 w-4 text-muted-foreground" />
<Input
name="query"
placeholder={t('searchPlaceholder')}
className="px-7"
value={query}
onChange={(ev) => {
setQuery(ev.target.value)
props.onSearch(ev.target.value)
}}
/>
{query !== '' ? (
<X
className="absolute right-2 top-3 h-4 w-4 cursor-pointer text-muted-foreground"
onClick={() => handleClear()}
/>
) : null}
</div>
)
}
export default memo(SearchBar)