Skip to content

Commit b686914

Browse files
chore(composable): add DocSearchButton + DocSearchModal example (#2876)
1 parent 4b9fdba commit b686914

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

packages/website/docs/examples.mdx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ description: live demos showing how to use and extend docsearch beyond documenta
55
---
66

77
import { DocSearch } from '@docsearch/react';
8+
import { DocSearch as DocSearchProvider } from '@docsearch/core';
9+
import { DocSearchButton, DocSearchModal } from '@docsearch/modal';
810
import { DocSearchSidepanel } from '@docsearch/react/sidepanel';
911
import BrowserOnly from '@docusaurus/BrowserOnly';
1012
import '@docsearch/css/dist/style.css';
@@ -98,6 +100,51 @@ The sidepanel provides a persistent chat interface anchored to the side of the p
98100

99101
---
100102

103+
## Composable API: DocSearchButton + DocSearchModal
104+
105+
Use the [Composable API](/docs/composable-api) to render the button and modal as separate components. This gives you explicit control over where each piece is rendered and when the modal code is loaded.
106+
107+
```jsx
108+
import { DocSearch } from '@docsearch/core';
109+
import { DocSearchButton, DocSearchModal } from '@docsearch/modal';
110+
111+
import '@docsearch/css/style.css';
112+
113+
<DocSearch>
114+
<DocSearchButton translations={{ buttonText: 'Composable search (demo)' }} />
115+
<DocSearchModal
116+
appId="PMZUYBQDAK"
117+
indexName="docsearch"
118+
apiKey="a00716d83c64f6c61905c078b7d5ab66"
119+
askAi={{
120+
assistantId: 'ccdec697-e3fe-465b-a1c3-657e7bf18aef',
121+
agentStudio: true,
122+
}}
123+
/>
124+
</DocSearch>;
125+
```
126+
127+
<BrowserOnly>
128+
{() => (
129+
<DocSearchProvider>
130+
<DocSearchButton
131+
translations={{ buttonText: 'Composable search (demo)' }}
132+
/>
133+
<DocSearchModal
134+
appId="PMZUYBQDAK"
135+
indexName="docsearch"
136+
apiKey="a00716d83c64f6c61905c078b7d5ab66"
137+
askAi={{
138+
assistantId: 'ccdec697-e3fe-465b-a1c3-657e7bf18aef',
139+
agentStudio: true,
140+
}}
141+
/>
142+
</DocSearchProvider>
143+
)}
144+
</BrowserOnly>
145+
146+
---
147+
101148
## Custom hit rendering (`hitComponent`)
102149

103150
Replace the default hit markup to match your brand and layout. below is a minimal example of a custom component.

packages/website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@docsearch/core": "workspace:*",
2020
"@docsearch/css": "workspace:*",
2121
"@docsearch/docusaurus-adapter": "workspace:*",
22+
"@docsearch/modal": "workspace:*",
2223
"@docsearch/react": "workspace:*",
2324
"@docsearch/sidepanel": "workspace:*",
2425
"@docusaurus/core": "3.9.2",

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,6 +2669,7 @@ __metadata:
26692669
"@docsearch/core": "workspace:*"
26702670
"@docsearch/css": "workspace:*"
26712671
"@docsearch/docusaurus-adapter": "workspace:*"
2672+
"@docsearch/modal": "workspace:*"
26722673
"@docsearch/react": "workspace:*"
26732674
"@docsearch/sidepanel": "workspace:*"
26742675
"@docusaurus/core": "npm:3.9.2"

0 commit comments

Comments
 (0)