-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsearch-suggestions.tsx
121 lines (116 loc) · 4.38 KB
/
search-suggestions.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { AsteriskIcon, HistoryIcon, SparklesIcon } from 'lucide-react'
const SUGGESTIONS_SEARCH = [
'books for learning TypeScript',
'librerías para autenticación',
'how to build a blog using Next.js, Tailwind and markdown',
'platforms for sending emails',
'plataformas open source para analíticas'
]
function SearchSuggestionsAI({
searchSuggestionsAI,
handleSearch
}: {
searchSuggestionsAI: string[]
handleSearch: (term: string) => void
}) {
return (
<div className='flex flex-col gap-2'>
<span className='text-xs font-semibold text-light-900 dark:text-white uppercase'>
ai Suggestions
</span>
<div className='flex flex-wrap gap-2 items-center w-full'>
{searchSuggestionsAI.map((suggestion) => (
<button
aria-label={`Search for ${suggestion}`}
key={suggestion}
onClick={() => {
handleSearch(suggestion)
}}
className='group flex items-center border border-neutral-600/30 dark:border-neutral-600/50 bg-light-300 dark:bg-neutral-800 hover:bg-light-600/40 dark:hover:bg-neutral-900 p-2 rounded-md cursor-pointer transition-colors duration-300'
>
<SparklesIcon className='mr-2 text-yellow-700 dark:text-yellow-300 size-4' />
<span className='text-gray-900 dark:text-gray-300 group-hover:text-black dark:group-hover:text-white text-sm text-left'>
{suggestion}
</span>
</button>
))}
</div>
</div>
)
}
function SearchHistory({
searchHistory,
handleSearch
}: {
searchHistory: string[]
handleSearch: (term: string) => void
}) {
return (
<div className='flex flex-col gap-2 mt-4'>
<span className='text-xs font-semibold text-light-900 dark:text-white uppercase'>
search history
</span>
<div className='flex flex-wrap gap-2 items-center w-full'>
{searchHistory.map((suggestion) => (
<button
aria-label={`Search for ${suggestion}`}
key={suggestion}
onClick={() => {
handleSearch(suggestion)
}}
className='group flex items-center border border-neutral-600/30 dark:border-neutral-600/50 bg-light-300 dark:bg-neutral-800 hover:bg-light-600/40 dark:hover:bg-neutral-900 p-2 rounded-md cursor-pointer transition-colors duration-300'
>
<HistoryIcon className='mr-2 text-yellow-700 dark:text-yellow-300 size-4' />
<span className='text-gray-900 dark:text-gray-300 group-hover:text-black dark:group-hover:text-white text-sm text-left'>
{suggestion}
</span>
</button>
))}
</div>
</div>
)
}
type SearchSuggestionsProps = {
handleSearch: (term: string) => void
searchHistory: string[]
searchSuggestionsAI: string[]
}
export function SearchSuggestions({
handleSearch,
searchHistory,
searchSuggestionsAI
}: SearchSuggestionsProps) {
return (
<div className='size-full border-t border-light-700 dark:border-t-neutral-700/40 overflow-y-auto scrollbar-hide p-3.5 hidden group-focus-within:block'>
<>
{searchHistory.length === 0 && searchSuggestionsAI.length === 0 ? (
<div className='flex flex-wrap gap-2 items-center w-full'>
{SUGGESTIONS_SEARCH.map((suggestion) => (
<button
aria-label={`Search for ${suggestion}`}
key={suggestion}
onClick={() => {
handleSearch(suggestion)
}}
className='group flex items-center border border-neutral-600/30 dark:border-neutral-600/50 bg-light-300 dark:bg-neutral-800 hover:bg-light-600/40 dark:hover:bg-neutral-900 p-2 rounded-md cursor-pointer transition-colors duration-300'
>
<AsteriskIcon className='mr-2 text-yellow-700 dark:text-yellow-300 size-4' />
<span className='text-gray-900 dark:text-gray-300 group-hover:text-black dark:group-hover:text-white text-sm text-left'>
{suggestion}
</span>
</button>
))}
</div>
) : (
<>
<SearchSuggestionsAI
searchSuggestionsAI={searchSuggestionsAI}
handleSearch={handleSearch}
/>
<SearchHistory searchHistory={searchHistory} handleSearch={handleSearch} />
</>
)}
</>
</div>
)
}