该 layout 参数 允许您配置故事在 Storybook 的画布选项卡中的位置。
layout
您可以将参数添加到您的 ./storybook/preview.js 中,如下所示
./storybook/preview.js
// 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
您也可以在组件级别设置它,如下所示
// 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;
或者甚至像这样将其应用于特定故事
// 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', }, };