Docs
Storybook Docs

功能和行为

要控制 Storybook 的 UI 布局,你可以在 .storybook/manager.js 中使用 addons.setConfig

¥To control the layout of Storybook’s UI you can use addons.setConfig in your .storybook/manager.js:

.storybook/manager.js
import { addons } from '@storybook/manager-api';
 
addons.setConfig({
  navSize: 300,
  bottomPanelHeight: 300,
  rightPanelWidth: 300,
  panelPosition: 'bottom',
  enableShortcuts: true,
  showToolbar: true,
  theme: undefined,
  selectedPanel: undefined,
  initialActive: 'sidebar',
  sidebar: {
    showRoots: false,
    collapsedRoots: ['other'],
  },
  toolbar: {
    title: { hidden: false },
    zoom: { hidden: false },
    eject: { hidden: false },
    copy: { hidden: false },
    fullscreen: { hidden: false },
  },
});

下表详细说明了如何使用 API 值:

¥The following table details how to use the API values:

名称类型描述示例值
navSize数字(像素)显示故事列表的侧边栏的大小300
bottomPanelHeight数字(像素)插件面板处于底部位置时的大小200
rightPanelWidth数字(像素)插件面板处于正确位置时的大小200
panelPosition字符串在哪里显示插件面板'bottom''right'
enableShortcuts布尔值启用/禁用快捷方式true
showToolbar布尔值显示/隐藏工具栏true
theme对象Storybook 主题,请参阅下一节undefined
selectedPanel字符串用于选择插件面板的 ID'storybook/actions/panel'
initialActive字符串选择移动设备上的默认活动选项卡'sidebar''canvas''addons'
sidebar对象侧边栏选项,见下文{ showRoots: false }
toolbar对象使用插件 ID 修改工具栏中的工具{ fullscreen: { hidden: false } }

以下选项可在 sidebar 命名空间下配置:

¥The following options are configurable under the sidebar namespace:

名称类型描述示例值
showRoots布尔值在侧边栏中将顶层节点显示为 "root"false
collapsedRoots数组设置默认在视觉上折叠的根节点 ID['misc', 'other']
renderLabel函数为树节点创建自定义标签;必须返回一个 ReactNode(item, api) => <abbr title="...">{item.name}</abbr>

以下选项可在 toolbar 命名空间下配置:

¥The following options are configurable under the toolbar namespace:

名称类型描述示例值
id字符串切换工具栏项的可见性{ hidden: false }

通过 URL 参数进行配置

¥Configuring through URL parameters

你可以使用 URL 参数来配置一些可用的功能:

¥You can use URL parameters to configure some of the available features:

配置选项查询参数支持的值
enableShortcutsshortcutsfalse
---(全屏)fulltrue, false
---(显示侧边栏)navtrue, false
---(显示面板)panelfalse, 'right', 'bottom'
selectedPaneladdonPanel任何面板 ID
showTabstabstrue
instrumentfalse, true