Skip to content

Commit dcdf708

Browse files
committed
chore(docs): cleanup new search behaviour
1 parent 6fe572f commit dcdf708

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

docs/components/Docsearch/hit.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
import { Highlight } from "react-instantsearch"
1+
import { Highlight, useInstantSearch } from "react-instantsearch"
22
import Link from "next/link"
33

44
export default function Hit({ hit }) {
5+
const { setIndexUiState } = useInstantSearch()
56
const hierarchy = Object.values(hit.hierarchy)?.filter(Boolean)
67
const path = new URL(hit.url_without_anchor).pathname
78

9+
const onClick = () => {
10+
setIndexUiState((prevIndexUiState) => ({
11+
...prevIndexUiState,
12+
query: "",
13+
}))
14+
}
15+
816
return (
917
<Link
1018
key={hit.objectID}
1119
href={hit.url}
20+
onClick={onClick}
1221
className="flex flex-col gap-2 p-4 px-2 rounded-md text-neutral-800 group dark:text-neutral-100 hover:dark:bg-neutral-900 hover:bg-neutral-200"
1322
>
1423
<h3 className="flex items-center text-sm font-semibold after:content-[''] whitespace-nowrap after:absolute after:bg-gradient-to-r after:h-6 after:right-0 after:w-12 after:from-transparent after:to-neutral-100 after:dark:to-neutral-800 relative overflow-hidden group-hover:dark:after:to-neutral-900 group-hover:after:to-neutral-200">

docs/components/Docsearch/index.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import dynamic from "next/dynamic"
22

3-
const DocSearch = dynamic(() => import("./search").then((mod) => mod.default), {
4-
ssr: false,
5-
loading: () => (
6-
<div className="relative max-md:ml-6 h-8 appearance-none rounded-lg px-3 py-1.5 transition-colors text-base leading-tight md:text-sm bg-black/[.05] dark:bg-gray-50/10 focus:!bg-transparent pr-2 w-48 text-gray-500 dark:text-gray-400">
7-
Search...
8-
<kbd className="flex absolute top-0 right-0 gap-1 items-center px-1.5 my-1.5 h-5 font-mono font-medium text-gray-500 bg-white rounded border transition-opacity pointer-events-none select-none ltr:right-1.5 rtl:left-1.5 text-[10px] contrast-more:border-current contrast-more:text-current contrast-more:dark:border-current max-sm:hidden dark:border-gray-100/20 dark:bg-black/50">
9-
CTRL K
10-
</kbd>
11-
</div>
12-
),
13-
})
3+
const DocSearch = dynamic(
4+
() => import("./wrapper").then((mod) => mod.default),
5+
{
6+
ssr: false,
7+
loading: () => (
8+
<div className="relative max-md:ml-6 h-8 appearance-none rounded-lg px-3 py-1.5 transition-colors text-base leading-tight md:text-sm bg-black/[.05] dark:bg-gray-50/10 focus:!bg-transparent pr-2 w-48 text-gray-500 dark:text-gray-400">
9+
Search...
10+
<kbd className="flex absolute top-0 right-0 gap-1 items-center px-1.5 my-1.5 h-5 font-mono font-medium text-gray-500 bg-white rounded border transition-opacity pointer-events-none select-none ltr:right-1.5 rtl:left-1.5 text-[10px] contrast-more:border-current contrast-more:text-current contrast-more:dark:border-current max-sm:hidden dark:border-gray-100/20 dark:bg-black/50">
11+
CTRL K
12+
</kbd>
13+
</div>
14+
),
15+
}
16+
)
1417

1518
export default DocSearch

docs/components/Docsearch/search.tsx renamed to docs/components/Docsearch/wrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect } from "react"
22
import algoliasearch from "algoliasearch/lite"
33
import { Hits, useInstantSearch } from "react-instantsearch"
44
import { InstantSearchNext } from "react-instantsearch-nextjs"
5-
import { CustomSearchBox } from "./searchbox"
5+
import { CustomSearchBox } from "./searchInput"
66
import Hit from "./hit"
77

88
const algoliaClient = algoliasearch(

0 commit comments

Comments
 (0)