用法
import { DocsSearch } from './DocsSearch.jsx'
// Fetch from your search route as the visitor types, and open the page they choose:
<DocsSearch
locale="en"
sections={[{ id: 'guides', name: 'Guides' }]}
items={results} // [{ id, section, title, text }]
filter={false} // the server already matched the query
loading={!results}
error={searchError}
onRetry={reloadIndex}
onSearch={(q) => setQuery(q)}
onOpen={(page) => router.push('/docs/' + page.id)}
/>属性
| 属性 | 类型 | 默认值 | 作用 |
|---|---|---|---|
locale | 'en' | 'zh-CN' | 'es' | 'ja' | 'en' | 内置文字和示例页面的语言。 |
sections | Array<{ id, name }> | sample sections | 结果按这些章节分组,按顺序排列。没有结果的章节不显示。 |
items | Array<{ id, section, title, text }> | sample pages | 要搜索的页面。传空数组会显示空状态。 |
defaultQuery | string | '' | 搜索框的初始内容。 |
filter | boolean | true | 在浏览器里按搜索词筛选。由服务端返回搜索结果时传 false。 |
loading / error | boolean / boolean | string | false | 显示骨架,或带重试按钮的错误提示(传字符串可替换说明)。 |
onSearch / onOpen / onRetry | (query) => void / (item) => void / () => void | — | 分别在搜索内容变化、点击或回车打开结果、点击重试时调用。 |
labels | object | — | 替换任意内置文字(键名见 copy.js)。 |
装进你的项目
把指令粘贴给 Codex 或 Claude Code。Agent 会读取公开的源码,先告诉你要写入哪些文件,再把区块连同它用到的组件一起加进项目。
DocsSearch.jsxdocs-search.csscopy.jskit.jsxkit.cssui/base-button/ui/empty-state/ui/kbd/ui/alert-banner/ui/text-input/ui/skeleton-shimmer/tokens.cssREADME.md
区块本身、样式和文案、共用的 kit、用到的组件和 tokens.css 会一起装进同一个文件夹。