Skip to content

Commit 65b37dd

Browse files
committed
chore: add new orama search widget
1 parent f55c9a0 commit 65b37dd

File tree

6 files changed

+243
-42
lines changed

6 files changed

+243
-42
lines changed

app/components/ClientOnlySearchButton.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { Suspense } from 'react'
33
import { ImSpinner2 } from 'react-icons/im'
44

55
const LazySearchButton = React.lazy(() =>
6-
import('@orama/searchbox').then((mod) => ({ default: mod.SearchButton }))
6+
import('@orama/react-components').then((mod) => ({
7+
default: mod.OramaSearchButton,
8+
}))
79
)
810

911
let defaultMounted = false

app/components/DocsLayout.tsx

+23-13
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import {
1313
useNavigate,
1414
useParams,
1515
} from '@tanstack/react-router'
16-
import type { AnyOrama, SearchParamsFullText, AnyDocument } from '@orama/orama'
17-
import { SearchBox } from '@orama/searchbox'
16+
import { OramaSearchBox } from '@orama/react-components'
1817
import { Carbon } from '~/components/Carbon'
1918
import { Select } from '~/components/Select'
2019
import { useLocalStorage } from '~/utils/useLocalStorage'
@@ -336,6 +335,8 @@ export function DocsLayout({
336335
[menuConfig]
337336
)
338337

338+
const [isSearchboxOpen, setIsSearchboxOpen] = React.useState(false)
339+
339340
const docsMatch = matches.find((d) => d.pathname.includes('/docs'))
340341

341342
const relativePathname = lastMatch.pathname.replace(
@@ -444,15 +445,6 @@ export function DocsLayout({
444445
)
445446
})
446447

447-
const oramaSearchParams: SearchParamsFullText<AnyOrama, AnyDocument> = {
448-
threshold: 0,
449-
where: {
450-
category: {
451-
eq: capitalize(libraryId),
452-
},
453-
},
454-
}
455-
456448
const logo = (
457449
<DocsLogo
458450
name={name}
@@ -499,7 +491,12 @@ export function DocsLayout({
499491
onSelect={versionConfig.onSelect}
500492
/>
501493
</div>
502-
<ClientOnlySearchButton {...searchButtonParams} />
494+
<ClientOnlySearchButton
495+
{...searchButtonParams}
496+
onClick={() => setIsSearchboxOpen(true)}
497+
>
498+
Search
499+
</ClientOnlySearchButton>
503500
{menuItems}
504501
</div>
505502
</details>
@@ -546,7 +543,20 @@ export function DocsLayout({
546543
className={`min-h-screen flex flex-col lg:flex-row w-full transition-all duration-300`}
547544
>
548545
<div className="fixed z-50">
549-
<SearchBox {...searchBoxParams} searchParams={oramaSearchParams} />
546+
<OramaSearchBox
547+
{...searchBoxParams}
548+
searchParams={{
549+
threshold: 0,
550+
where: {
551+
category: {
552+
eq: capitalize(libraryId!) as string,
553+
},
554+
} as any,
555+
}}
556+
facetProperty={undefined}
557+
open={isSearchboxOpen}
558+
onSearchboxClosed={() => setIsSearchboxOpen(false)}
559+
/>
550560
</div>
551561
{smallMenu}
552562
{largeMenu}

app/components/Orama.tsx

+15-25
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
1-
import type {
2-
RegisterSearchButtonProps,
3-
RegisterSearchBoxProps,
4-
} from '@orama/searchbox'
5-
import { OramaClient } from '@oramacloud/client'
6-
import '@orama/searchbox/dist/index.css'
7-
8-
const oramaInstance = new OramaClient({
9-
// The search endpoint for the Orama index
10-
endpoint: 'https://cloud.orama.run/v1/indexes/tanstack-dev-ur0ppd',
11-
// The public API key for performing search. This is commit-safe.
12-
api_key: 'xqfn8QcuImADRGPIlhWTo9cT5UNiqPDj',
13-
})
14-
15-
export const searchBoxParams: RegisterSearchBoxProps = {
16-
oramaInstance,
17-
colorScheme: 'system',
18-
backdrop: true,
1+
export const searchBoxParams = {
2+
index: {
3+
api_key: 'xqfn8QcuImADRGPIlhWTo9cT5UNiqPDj',
4+
endpoint: 'https://cloud.orama.run/v1/indexes/tanstack-dev-ur0ppd',
5+
},
6+
colorScheme: 'system' as 'light' | 'dark' | 'system',
197
facetProperty: 'category',
20-
resultsMap: {
8+
resultMap: {
219
description: 'content',
10+
section: 'category',
2211
},
12+
2313
themeConfig: {
24-
light: {},
25-
dark: {
26-
'--backdrop-bg-color': '#0d103591',
14+
colors: {
15+
light: {},
16+
dark: {
17+
'--backdrop-background-color-primary': 'rgba(0, 0, 0, 0.7)',
18+
},
2719
},
2820
},
29-
searchMode: 'hybrid',
3021
searchParams: {
3122
threshold: 0,
3223
},
3324
}
3425

35-
export const searchButtonParams: RegisterSearchButtonProps = {
26+
export const searchButtonParams = {
3627
colorScheme: 'system',
37-
fullWidth: true,
3828
}

app/routes/_libraries.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { CgClose, CgMenuLeft, CgMusicSpeaker } from 'react-icons/cg'
1010
import { MdLibraryBooks, MdSupport } from 'react-icons/md'
1111
import { twMerge } from 'tailwind-merge'
12-
import { SearchBox } from '@orama/searchbox'
12+
import { OramaSearchBox } from '@orama/react-components'
1313
import { sortBy } from '~/utils/utils'
1414
import logoColor100w from '~/images/logo-color-100w.png'
1515
import {
@@ -46,6 +46,8 @@ function LibrariesLayout() {
4646

4747
const [mounted, setMounted] = React.useState(false)
4848

49+
const [onSearchboxOpen, setOnSearchboxOpen] = React.useState(false)
50+
4951
React.useEffect(() => {
5052
setMounted(true)
5153
}, [])
@@ -255,7 +257,12 @@ function LibrariesLayout() {
255257
{logo}
256258
</div>
257259
<div className="p-2">
258-
<ClientOnlySearchButton {...searchButtonParams} />
260+
<ClientOnlySearchButton
261+
{...searchButtonParams}
262+
onClick={() => setOnSearchboxOpen(true)}
263+
>
264+
Search
265+
</ClientOnlySearchButton>
259266
</div>
260267
<div className="flex-1 flex flex-col gap-4 whitespace-nowrap overflow-y-auto text-base pb-[300px]">
261268
<div className="space-y-1 text-sm p-2 border-b border-gray-500/10 dark:border-gray-500/20">
@@ -278,7 +285,11 @@ function LibrariesLayout() {
278285
</div>
279286
{mounted ? (
280287
<div className="fixed z-50">
281-
<SearchBox {...searchBoxParams} />
288+
<OramaSearchBox
289+
{...searchBoxParams}
290+
open={onSearchboxOpen}
291+
onSearchboxClosed={() => setOnSearchboxOpen(false)}
292+
/>
282293
</div>
283294
) : null}
284295
</div>

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@octokit/graphql": "^7.0.2",
2222
"@octokit/rest": "^20.0.2",
2323
"@orama/searchbox": "1.0.0-rc42",
24+
"@orama/react-components": "^0.0.22",
2425
"@oramacloud/client": "^1.2.2",
2526
"@remix-run/node": "^2.8.1",
2627
"@sentry/react": "^8.2.1",

0 commit comments

Comments
 (0)