文档
Storybook 文档

ArgTypes

观看视频教程

ArgTypes 块可用于显示给定组件的 arg types 的静态表格,以此方式记录其接口。

如果您正在寻找一个动态表格,显示 story 当前的 arg 值并支持用户更改它们,请参阅 Controls 块。

Screenshot of ArgTypes block

ButtonDocs.mdx
import { Meta, ArgTypes } from '@storybook/blocks';
import * as ButtonStories from './Button.stories';
 
<Meta of={ButtonStories} />
 
<ArgTypes of={ButtonStories} />

ArgTypes

import { ArgTypes } from '@storybook/blocks';
使用 props 参数进行配置

ℹ️ 像大多数块一样,ArgTypes 块通过 MDX 中的 props 进行配置。 许多这些 props 的默认值都来自块的命名空间 parameters.docs.argTypes 中对应的参数

以下 exclude 配置是等效的

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,
  parameters: {
    docs: {
      controls: { exclude: ['style'] },
    },
  },
};
 
export default meta;
ButtonDocs.mdx
<ArgTypes of={ButtonStories} exclude={['style']} />

上面的示例在组件(或元数据)级别应用了参数,但它也可以应用于项目story 级别。

exclude

类型: string[] | RegExp

默认值: parameters.docs.argTypes.exclude

指定要从 args 表中排除的 arg types。任何名称与正则表达式匹配或属于数组的 arg types 都将被排除在外。

include

类型: string[] | RegExp

默认值: parameters.docs.argTypes.include

指定要包含在 args 表中的 arg types。任何名称与正则表达式不匹配或不属于数组的 arg types 都将被排除在外。

of

类型: Story 导出或 CSF 文件导出

指定要从中获取 arg types 的 story。如果提供了 CSF 文件导出,它将使用文件中的主要(第一个)story。

sort

类型: 'none' | 'alpha' | 'requiredFirst'

默认值: parameters.docs.argTypes.sort'none'

指定 arg types 的排序方式。

  • none:不排序,按照 arg types 被处理的顺序显示
  • alpha:按字母顺序排序,按 arg type 的名称
  • requiredFirst:与 alpha 相同,但任何必需的 arg types 优先显示