Skip to content

Commit f6191f1

Browse files
committed
feat: add search on the client side
1 parent 39aca5f commit f6191f1

File tree

5 files changed

+71
-2
lines changed

5 files changed

+71
-2
lines changed

docs/app/layout.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import "@/app/global.css"
2-
import { RootProvider } from "fumadocs-ui/provider"
2+
// import { RootProvider } from "fumadocs-ui/provider"
3+
import { Provider } from "./provider"
4+
35
import { Inter } from "next/font/google"
46

57
const inter = Inter({
@@ -10,7 +12,7 @@ export default function Layout({ children }: LayoutProps<"/">) {
1012
return (
1113
<html lang="en" className={inter.className} suppressHydrationWarning>
1214
<body className="flex flex-col min-h-screen">
13-
<RootProvider>{children}</RootProvider>
15+
<Provider>{children}</Provider>
1416
</body>
1517
</html>
1618
)

docs/app/provider.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use client"
2+
import { RootProvider } from "fumadocs-ui/provider"
3+
// your custom dialog
4+
import SearchDialog from "@/components/search"
5+
import type { ReactNode } from "react"
6+
7+
export function Provider({ children }: { children: ReactNode }) {
8+
return (
9+
<RootProvider
10+
search={{
11+
SearchDialog
12+
}}
13+
>
14+
{children}
15+
</RootProvider>
16+
)
17+
}

docs/components/search.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"use client"
2+
import {
3+
SearchDialog,
4+
SearchDialogClose,
5+
SearchDialogContent,
6+
SearchDialogHeader,
7+
SearchDialogIcon,
8+
SearchDialogInput,
9+
SearchDialogList,
10+
SearchDialogOverlay,
11+
type SharedProps
12+
} from "fumadocs-ui/components/dialog/search"
13+
import { useDocsSearch } from "fumadocs-core/search/client"
14+
import { create } from "@orama/orama"
15+
import { useI18n } from "fumadocs-ui/contexts/i18n"
16+
17+
function initOrama() {
18+
return create({
19+
schema: { _: "string" },
20+
// https://docs.orama.com/docs/orama-js/supported-languages
21+
language: "english"
22+
})
23+
}
24+
25+
export default function DefaultSearchDialog(props: SharedProps) {
26+
const { locale } = useI18n() // (optional) for i18n
27+
const { search, setSearch, query } = useDocsSearch({
28+
type: "static",
29+
initOrama,
30+
locale
31+
})
32+
33+
return (
34+
<SearchDialog search={search} onSearchChange={setSearch} isLoading={query.isLoading} {...props}>
35+
<SearchDialogOverlay />
36+
<SearchDialogContent>
37+
<SearchDialogHeader>
38+
<SearchDialogIcon />
39+
<SearchDialogInput />
40+
<SearchDialogClose />
41+
</SearchDialogHeader>
42+
<SearchDialogList items={query.data !== "empty" ? query.data : null} />
43+
</SearchDialogContent>
44+
</SearchDialog>
45+
)
46+
}

docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"postinstall": "fumadocs-mdx"
1414
},
1515
"dependencies": {
16+
"@orama/orama": "^3.1.11",
1617
"fumadocs-core": "15.7.2",
1718
"fumadocs-mdx": "11.8.0",
1819
"fumadocs-ui": "15.7.2",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)