嵌入故事
嵌入故事,向团队成员和广大开发者社区展示您的作品。要使用嵌入功能,您的 Storybook 必须已发布并且可以公开访问。
Storybook 原生支持 <iframe> 嵌入。如果您使用 Chromatic 发布 Storybook,您还可以将故事嵌入到 Notion、Medium 和无数其他支持 oEmbed 标准的平台中。
使用工具栏嵌入故事
使用工具栏嵌入故事,然后粘贴已发布的 Story URL。例如:
// oEmbed
https://5ccbc373887ca40020446347-wtuhidckxo.chromatic.com/?path=/story/shadowboxcta--default
// iframe embed
<iframe
src="https://5ccbc373887ca40020446347-wtuhidckxo.chromatic.com/?path=/story/shadowboxcta--default&full=1&shortcuts=false&singleStory=true"
width="800"
height="260"
></iframe>嵌入无工具栏的故事
要嵌入一个不带 Storybook 工具栏的纯故事,请点击 Storybook 右上角的“在新标签页中打开画布”图标以获取画布 URL。例如:
// oEmbed
https://5ccbc373887ca40020446347-wtuhidckxo.chromatic.com/iframe.html?id=/story/shadowboxcta--default&viewMode=story
// iframe embed
<iframe
src="https://5ccbc373887ca40020446347-wtuhidckxo.chromatic.com/iframe.html?id=shadowboxcta--default&viewMode=story&shortcuts=false&singleStory=true"
width="800"
height="200"
></iframe>嵌入文档
通过将 viewMode=story 替换为故事自动生成的唯一文档入口,来嵌入文档页面。
// oEmbed
https://5ccbc373887ca40020446347-wtuhidckxo.chromatic.com/iframe.html?id=shadowboxcta--docs&viewMode=docs&shortcuts=false&singleStory=true
// iframe embed
<iframe
src="https://5ccbc373887ca40020446347-wtuhidckxo.chromatic.com/iframe.html?id=shadowboxcta--docs&viewMode=docs&shortcuts=false&singleStory=true"
width="800"
height="400"
></iframe>在其他平台嵌入故事
每个平台的嵌入支持程度不同。请查阅您所用服务的文档,了解他们推荐的外部内容嵌入方式。
如何在 Medium 中嵌入
将 Storybook URL 粘贴到您的 Medium 文章中,然后按 Enter 键。嵌入内容将自动调整大小以适应故事的高度。
在编辑文章时,Medium 会将所有嵌入内容渲染为不可交互的。一旦文章发布,它将变得可交互。 预览 Medium 上的演示。
如何在 Notion 中嵌入
在您的 Notion 文档中,输入 `/embed`,按 Enter 键,然后将 Story URL 粘贴为嵌入链接。您可以根据需要调整嵌入的大小。

如何在 Ghost 中嵌入
在您的 Ghost 文章中输入 /html,按 Enter 键,然后粘贴 iframe URL。您可以根据需要通过 `width` 和 `height` 属性调整嵌入的大小。

