跳至主内容
版本:稳定版 (v4.x)

侧边栏 API 参考

非官方测试版翻译

本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →

appId

type: string | 必填

您的 Algolia 应用 ID。

apiKey

type: string | 必填

您的 Algolia 搜索 API 密钥。

assistantId

type: string | 必填

指定使用的 Ask AI 助手 ID。

indexName

type: string | 必填

用于 Ask AI 服务的索引名称。

agentStudio

type: boolean | 可选 | 实验性

实验性

agentStudio 目前是实验性属性,预计在 5.0.0 版本中稳定。

agentStudio 设为 true,Ask AI 聊天功能将使用 Algolia 的 Agent Studio 作为聊天后端,而非 Ask AI 后端。有关设置 Agent Studio 的更多信息,请参阅其专属文档页面

searchParameters

variant

type: 'floating' | 'inline' | 默认值: 'floating' | 可选

侧边栏的定位变体。

  • inline:展开时将页面内容推开

  • floating:悬浮在页面所有内容上方

side

type: 'right' | 'left' | 默认值: 'right' | 可选

侧边栏在页面的展开方向。

width

type: number | string | 默认值: '360px' | 可选

侧边栏默认状态下的宽度(像素或任意 CSS 宽度单位)。

expandedWidth

type: number | string | 默认值: '580px' | 可选

侧边栏展开状态下的宽度(像素或任意 CSS 宽度单位)。

suggestedQuestions

type: boolean | 默认值: false | 可选

在新对话界面显示推荐问题。

设置推荐问题的更多信息请参阅 Algolia 文档

keyboardShortcuts

type: { 'Ctrl/Cmd+I': boolean } | 可选

键盘快捷键配置,用于启用/禁用特定组合键。

默认行为:

  • Ctrl/Cmd+I:打开/关闭侧边栏

接口定义:

interface SidepanelShortcuts {
'Ctrl/Cmd+I'?: boolean; // default: true
}

theme

type: 'light' | 'dark' | 默认值: 'light' | 可选

portalContainer (仅限 React)

type: Element | DocumentFragment | 默认值: document.body | 可选

侧边栏应挂载到的容器元素,用于需要将侧边栏渲染到自定义 DOM 节点时。

警告

该属性仅存在于基于 React 的侧边栏版本。若使用 @docsearch/sidepanel-js 包,请改用 container 选项。

// assume you have a dedicated DOM node in your HTML
<div id="sidepanel-root" />

const portalEl = document.getElementById('sidepanel-root');

<Sidepanel
appId="YOUR_APP_ID"
apiKey="YOUR_SEARCH_API_KEY"
assistantId="YOUR_ASSISTANT_ID"
indexName="YOUR_INDEX_NAME"
// Render the Sidepanel inside of #sidepanel-root instead of document.body
portalContainer={portalEl}
/>