Skip to content

Commit dfe7e8f

Browse files
authored
docs: dark mode for DocSearch (#12564)
1 parent 14dfaf3 commit dfe7e8f

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

docs/components/DocSearch/index.tsx

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

docs/components/DocSearch/wrapper.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import { DocSearch } from "@docsearch/react"
2+
import { useTheme } from "nextra-theme-docs"
3+
import { useEffect } from "react"
24

35
import "@docsearch/css"
46

57
function App() {
8+
const { resolvedTheme } = useTheme()
9+
10+
useEffect(() => {
11+
if (resolvedTheme) {
12+
// hack to get DocSearch to use dark mode colors if applicable
13+
document.documentElement.setAttribute("data-theme", resolvedTheme)
14+
}
15+
}, [resolvedTheme])
16+
617
return (
718
<DocSearch
819
appId={process.env.NEXT_PUBLIC_ALGOLIA_APP_ID!}

docs/pages/global.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,9 @@ html > head:has(meta[content*="reference/core/providers"]) + body .provider {
279279
font-size: 1rem;
280280
color: #000 !important;
281281
}
282+
283+
.nextra-sidebar-container {
284+
.DocSearch-Button {
285+
@apply hidden;
286+
}
287+
}

0 commit comments

Comments
 (0)