Storybook:如何强制 Storybook 不为我的组件创建文件夹
对于我的所有其他组件,Storybook 直接显示故事(没有子文件夹)。但在我名为“IconButton”的组件中,它创建一个子文件夹,然后显示实际文件。如何让它不显示文件夹?
我的所有其他文件看起来都是这样的
import React from "react";
import { ComponentMeta, ComponentStory } from "@storybook/react";
import { IconButton } from "./IconButton";
import { IconButtonDemo } from "./IconButton.demo";
export default {
title: "Atoms/IconButton",
component: IconButton,
} as ComponentMeta<typeof IconButton>;
const IconButtonComponentStory: ComponentStory<typeof IconButton> = () => <IconButtonDemo />;
export const _IconButton = IconButtonComponentStory.bind({});
For all my other components, Storybook shows the story directly (there is no subfolder). But in my component called "IconButton", it creates a subfolder and then shows the actual file. How can I make it not show a folder?
All my other files look like this
import React from "react";
import { ComponentMeta, ComponentStory } from "@storybook/react";
import { IconButton } from "./IconButton";
import { IconButtonDemo } from "./IconButton.demo";
export default {
title: "Atoms/IconButton",
component: IconButton,
} as ComponentMeta<typeof IconButton>;
const IconButtonComponentStory: ComponentStory<typeof IconButton> = () => <IconButtonDemo />;
export const _IconButton = IconButtonComponentStory.bind({});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
发生这种情况是因为故事名称是自动开始大小写的。因此,您打算为故事提供的名称 IconButton 在渲染时将变为 Icon Button。
解决方案是手动设置 Story 名称并使其与 Component 名称匹配。
_IconButton.storyName = "图标按钮";
应该可以解决你的问题;
This is happpening because story names are start cased automatically. So the name IconButton that you intent to give as name for your story becomes Icon Button when rendered.
The solution is to set a Story name manuly and make it match the Component name.
_IconButton.storyName = "IconButton";
should fix your problem;
如果
中的
title
属性与为
提供的name
属性一致,则不会围绕故事创建补充目录:If the
title
prop in<Meta>
coincides with thename
prop provided for<Story>
, it won't create a supplementary directory around the story: