故事布局
该 layout
参数 允许您配置故事在 Storybook 的画布选项卡中的位置。
全局布局
您可以将参数添加到您的 ./storybook/preview.js
中,如下所示
.storybook/preview.ts
// Replace your-framework with the framework you are using (e.g., react, vue3)
import { Preview } from '@storybook/your-framework';
const preview: Preview = {
parameters: {
layout: 'centered',
},
};
export default preview;
在上面的示例中,Storybook 会将 UI 中的所有故事居中。layout
接受以下选项
centered
:在画布中水平和垂直居中组件fullscreen
:允许组件扩展到画布的整个宽度和高度padded
:(默认)在组件周围添加额外的填充
组件布局
您也可以在组件级别设置它,如下所示
Button.stories.ts|tsx
// Replace your-framework with the name of your framework
import type { Meta } from '@storybook/your-framework';
import { Button } from './Button';
const meta: Meta<typeof Button> = {
component: Button,
// Sets the layout parameter component wide.
parameters: {
layout: 'centered',
},
};
export default meta;
故事布局
或者甚至像这样将其应用于特定故事
Button.stories.ts|tsx
// Replace your-framework with the name of your framework
import type { Meta, StoryObj } from '@storybook/your-framework';
import { Button } from './Button';
const meta: Meta<typeof Button> = {
component: Button,
};
export default meta;
type Story = StoryObj<typeof Button>;
export const WithLayout: Story = {
parameters: {
layout: 'centered',
},
};