-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMistSearch.jsx
More file actions
202 lines (189 loc) · 7.94 KB
/
Copy pathMistSearch.jsx
File metadata and controls
202 lines (189 loc) · 7.94 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import React, { useState, useEffect, useRef } from 'react';
import { Link } from 'react-router-dom';
import {
MagnifyingGlassIcon,
XCircleIcon,
HashIcon,
} from '@phosphor-icons/react';
import useSearchableData from '../hooks/useSearchableData';
import { filterItems } from '../utils/search';
import { MistHorizon } from './mist';
const categoryToneMap = {
page: 'text-[#5F837B] bg-[#5F837B]/10',
command: 'text-[#8FA8BC] bg-[#8FA8BC]/15',
post: 'text-[#5F837B] bg-[#5F837B]/10',
project: 'text-[#8FA8BC] bg-[#8FA8BC]/15',
log: 'text-[#5C6B67] bg-[#5C6B67]/10',
app: 'text-[#5F837B] bg-[#5F837B]/10',
story: 'text-[#8FA8BC] bg-[#8FA8BC]/15',
notebook: 'text-[#5C6B67] bg-[#5C6B67]/10',
};
const getCategoryTone = (type) =>
categoryToneMap[type] || 'text-[#5C6B67] bg-[#5C6B67]/10';
const MistSearch = ({ isVisible, toggleSearch }) => {
const [searchTerm, setSearchTerm] = useState('');
const [searchResults, setSearchResults] = useState([]);
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
const { items, isLoading } = useSearchableData();
const searchRef = useRef(null);
const inputRef = useRef(null);
useEffect(() => {
if (isVisible && inputRef.current) inputRef.current.focus();
}, [isVisible]);
useEffect(() => {
if (searchTerm) {
const results = filterItems(items, searchTerm).slice(0, 8);
setSearchResults(results);
setIsDropdownOpen(true);
} else {
setSearchResults([]);
setIsDropdownOpen(false);
}
}, [searchTerm, items]);
useEffect(() => {
const handleClickOutside = (event) => {
if (searchRef.current && !searchRef.current.contains(event.target)) {
setIsDropdownOpen(false);
}
};
document.addEventListener('mousedown', handleClickOutside);
return () => document.removeEventListener('mousedown', handleClickOutside);
}, []);
const getResultLink = (result) => result.path || '/';
if (!isVisible) return null;
return (
<div
ref={searchRef}
className="w-full bg-[#EEF2F1]/90 backdrop-blur-md py-6 px-6 relative z-50"
>
{/* bottom edge — a horizon, never a hard border */}
<span
aria-hidden="true"
className="pointer-events-none absolute left-0 right-0 bottom-0 h-px"
style={{
background:
'linear-gradient(90deg, transparent, rgba(60,72,69,0.14), transparent)',
}}
/>
<form
onSubmit={(e) => e.preventDefault()}
className="relative w-full max-w-2xl mx-auto"
>
<div className="relative group">
<MagnifyingGlassIcon
size={18}
weight="light"
className={`absolute left-0 top-1/2 transform -translate-y-1/2 transition-colors ${
searchTerm
? 'text-[#5F837B]'
: 'text-[#8A9894] group-focus-within:text-[#5F837B]'
}`}
/>
<input
ref={inputRef}
type="text"
placeholder={isLoading ? 'condensing index…' : 'search the fog…'}
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
onFocus={() => setIsDropdownOpen(true)}
className="w-full bg-transparent text-[#3C4845] py-3 pl-9 pr-10 focus:outline-none font-ibm-plex-mono lowercase tracking-[0.16em] text-sm placeholder-[#8A9894]/70 selection:bg-[#8FA8BC]/30"
disabled={isLoading}
/>
{/* resting baseline — fading hairline */}
<span
aria-hidden="true"
className="pointer-events-none absolute left-0 right-0 bottom-0 h-px"
style={{
background:
'linear-gradient(90deg, transparent, rgba(60,72,69,0.14), transparent)',
}}
/>
{/* focus baseline — eucalyptus surfacing through the haze */}
<span
aria-hidden="true"
className="pointer-events-none absolute left-0 right-0 bottom-0 h-px opacity-0 group-focus-within:opacity-100 transition-opacity duration-[400ms]"
style={{
background:
'linear-gradient(90deg, transparent, rgba(95,131,123,0.6), transparent)',
}}
/>
{searchTerm && (
<button
type="button"
onClick={() => setSearchTerm('')}
className="absolute right-0 top-1/2 transform -translate-y-1/2 text-[#8A9894] hover:text-[#5F837B] transition-colors"
>
<XCircleIcon size={18} weight="light" />
</button>
)}
</div>
{isDropdownOpen && searchResults.length > 0 && (
<div className="absolute mt-4 w-full bg-white/80 backdrop-blur-md rounded-2xl shadow-[0_18px_50px_rgba(60,72,69,0.18)] z-[100] left-0 overflow-hidden">
<div className="flex flex-col">
{searchResults.map((result, index) => (
<React.Fragment
key={`${result.slug || result.commandId}-${index}`}
>
{index > 0 && <MistHorizon tint="rgba(60,72,69,0.10)" />}
<Link
to={getResultLink(result)}
onClick={() => {
setSearchTerm('');
setIsDropdownOpen(false);
if (toggleSearch) toggleSearch();
}}
className="flex items-center justify-between px-6 py-4 hover:bg-[#8FA8BC]/15 transition-colors duration-[250ms] group"
>
<div className="flex flex-col gap-1 min-w-0">
<span className="font-instr-serif italic text-[#3C4845] text-lg leading-snug truncate group-hover:text-[#5F837B] transition-colors duration-[250ms]">
{result.title}
</span>
{result.description && (
<span className="text-[9px] font-ibm-plex-mono lowercase tracking-[0.16em] text-[#8A9894] line-clamp-1">
{result.description}
</span>
)}
</div>
<div className="flex items-center gap-3 flex-shrink-0">
<span
className={`px-2.5 py-0.5 text-[8px] font-ibm-plex-mono lowercase tracking-[0.2em] rounded-full ${getCategoryTone(result.type)}`}
>
{result.type}
</span>
<HashIcon
size={13}
weight="light"
className="text-[#8A9894]/60 group-hover:text-[#5F837B] transition-colors duration-[250ms]"
/>
</div>
</Link>
</React.Fragment>
))}
</div>
<MistHorizon />
<div className="bg-[#E5EBE9]/60 px-6 py-2.5 flex justify-between items-center">
<span className="text-[8px] font-ibm-plex-mono lowercase tracking-[0.22em] text-[#8A9894]">
{searchResults.length} drifted to the surface
</span>
<span className="text-[8px] font-ibm-plex-mono lowercase tracking-[0.22em] text-[#8A9894]">
mist search · v1
</span>
</div>
</div>
)}
{isDropdownOpen && searchTerm && searchResults.length === 0 && (
<div className="absolute mt-4 w-full bg-white/80 backdrop-blur-md rounded-2xl p-8 text-center shadow-[0_18px_50px_rgba(60,72,69,0.18)] z-[100] left-0">
<p className="font-ibm-plex-mono text-xs text-[#5C6B67] lowercase tracking-[0.22em]">
nothing surfaced for{' '}
<span className="text-[#5F837B]">{searchTerm}</span>
</p>
<p className="mt-2 font-ibm-plex-mono text-[9px] text-[#8A9894] lowercase tracking-[0.22em]">
visibility: low
</p>
</div>
)}
</form>
</div>
);
};
export default MistSearch;