({
result,
resultIndex,
autocomplete,
collection,
query,
}: {
result: Result
resultIndex: number
autocomplete: Autocomplete
collection: AutocompleteCollection<Result>
query: string
})
| 163 | } |
| 164 | |
| 165 | function SearchResult({ |
| 166 | result, |
| 167 | resultIndex, |
| 168 | autocomplete, |
| 169 | collection, |
| 170 | query, |
| 171 | }: { |
| 172 | result: Result |
| 173 | resultIndex: number |
| 174 | autocomplete: Autocomplete |
| 175 | collection: AutocompleteCollection<Result> |
| 176 | query: string |
| 177 | }) { |
| 178 | let id = useId() |
| 179 | |
| 180 | let sectionTitle = navigation.find((section) => |
| 181 | section.links.find((link) => link.href === result.url.split('#')[0]), |
| 182 | )?.title |
| 183 | let hierarchy = [sectionTitle, result.pageTitle].filter( |
| 184 | (x): x is string => typeof x === 'string', |
| 185 | ) |
| 186 | |
| 187 | return ( |
| 188 | <li |
| 189 | className={clsx( |
| 190 | 'group block cursor-default px-4 py-3 aria-selected:bg-zinc-50 dark:aria-selected:bg-zinc-800/50', |
| 191 | resultIndex > 0 && 'border-t border-zinc-100 dark:border-zinc-800', |
| 192 | )} |
| 193 | aria-labelledby={`${id}-hierarchy ${id}-title`} |
| 194 | {...autocomplete.getItemProps({ |
| 195 | item: result, |
| 196 | source: collection.source, |
| 197 | })} |
| 198 | > |
| 199 | <div |
| 200 | id={`${id}-title`} |
| 201 | aria-hidden="true" |
| 202 | className="text-sm font-medium text-zinc-900 group-aria-selected:text-red-500 dark:text-white" |
| 203 | > |
| 204 | <HighlightQuery text={result.title} query={query} /> |
| 205 | </div> |
| 206 | {hierarchy.length > 0 && ( |
| 207 | <div |
| 208 | id={`${id}-hierarchy`} |
| 209 | aria-hidden="true" |
| 210 | className="mt-1 truncate whitespace-nowrap text-2xs text-zinc-500" |
| 211 | > |
| 212 | {hierarchy.map((item, itemIndex, items) => ( |
| 213 | <Fragment key={itemIndex}> |
| 214 | <HighlightQuery text={item} query={query} /> |
| 215 | <span |
| 216 | className={ |
| 217 | itemIndex === items.length - 1 |
| 218 | ? 'sr-only' |
| 219 | : 'mx-2 text-zinc-300 dark:text-zinc-700' |
| 220 | } |
| 221 | > |
| 222 | / |
nothing calls this directly
no outgoing calls
no test coverage detected