-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
379cc11
commit 1870ace
Showing
8 changed files
with
599 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { DocSearchProps } from "@docsearch/react"; | ||
import "@docsearch/css/dist/style.css"; | ||
import "~/styles/docsearch.css"; | ||
import { useHydrated } from "~/ui/utils"; | ||
import { Suspense, lazy } from "react"; | ||
|
||
const OriginalDocSearch = lazy(() => | ||
import("@docsearch/react").then((module) => ({ | ||
default: module.DocSearch, | ||
})) | ||
); | ||
|
||
let docSearchProps = { | ||
appId: "RB6LOUCOL0", | ||
indexName: "reactrouter", | ||
apiKey: "b50c5d7d9f4610c9785fa945fdc97476", | ||
} satisfies DocSearchProps; | ||
|
||
// TODO: Refactor a bit when we add Vite with css imports per component | ||
// This will allow us to have two versions of the component, one that has | ||
// the button with display: none, and the other with button styles | ||
export function DocSearch() { | ||
let hydrated = useHydrated(); | ||
|
||
if (!hydrated) { | ||
// The Algolia doc search container is hard-coded at 40px. It doesn't | ||
// render anything on the server, so we get a mis-match after hydration. | ||
// This placeholder prevents layout shift when the search appears. | ||
return <div className="h-10" />; | ||
} | ||
|
||
return ( | ||
<Suspense fallback={<div className="h-10" />}> | ||
<div className="animate-[fadeIn_100ms_ease-in_1]"> | ||
<OriginalDocSearch {...docSearchProps} /> | ||
</div> | ||
</Suspense> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* this was copy/paste/modified from @docsearch/css/dist/_variables.css */ | ||
:root { | ||
&:where(.dark) { | ||
--docsearch-text-color: #f5f6f7; | ||
--docsearch-container-background: rgba(9, 10, 17, 0.8); | ||
--docsearch-modal-background: #15172a; | ||
--docsearch-modal-shadow: inset 1px 1px 0 0 #2c2e40, 0 3px 8px 0 #000309; | ||
--docsearch-searchbox-background: #090a11; | ||
--docsearch-searchbox-focus-background: #000; | ||
--docsearch-hit-color: #bec3c9; | ||
--docsearch-hit-shadow: none; | ||
--docsearch-hit-background: #090a11; | ||
--docsearch-key-gradient: linear-gradient(-26.5deg, #565872, #31355b); | ||
--docsearch-key-shadow: inset 0 -2px 0 0 #282d55, inset 0 0 1px 1px #51577d, | ||
0 2px 2px 0 rgba(3, 4, 9, 0.3); | ||
--docsearch-footer-background: #1e2136; | ||
--docsearch-footer-shadow: inset 0 1px 0 0 rgba(73, 76, 106, 0.5), | ||
0 -4px 8px 0 rgba(0, 0, 0, 0.2); | ||
--docsearch-logo-color: #fff; | ||
--docsearch-muted-color: #7f8497; | ||
} | ||
} | ||
|
||
.DocSearch-Button { | ||
@apply ml-0 h-10 bg-gray-100 px-3 hover:bg-gray-200 hover:shadow-none focus:bg-gray-200 focus-visible:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 dark:focus-visible:bg-gray-700; | ||
|
||
@media screen and (min-width: theme(screens.lg)) { | ||
width: 100%; | ||
} | ||
@media not screen and (min-width: theme(screens.lg)) { | ||
@apply w-10 place-content-center px-0; | ||
.DocSearch-Button-Keys, | ||
.DocSearch-Button-Placeholder { | ||
display: none; | ||
} | ||
} | ||
@media print { | ||
display: none; | ||
} | ||
} | ||
|
||
.DocSearch-Button-Placeholder { | ||
@apply text-sm font-normal text-black dark:text-gray-200; | ||
} | ||
|
||
.DocSearch-Button-Keys { | ||
@apply justify-end gap-1; | ||
} | ||
|
||
.DocSearch-Button-Key { | ||
all: unset; | ||
|
||
@apply grid h-5 w-3.5 place-items-center rounded bg-white px-1 text-xs text-gray-600 dark:bg-gray-600 dark:text-gray-200; | ||
} | ||
|
||
.DocSearch-Container { | ||
cursor: auto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
let hydrating = true; | ||
|
||
export function useHydrated() { | ||
let [hydrated, setHydrated] = useState(() => !hydrating); | ||
useEffect(() => { | ||
hydrating = false; | ||
setHydrated(true); | ||
}, []); | ||
return hydrated; | ||
} |
Oops, something went wrong.