Storybook:如何强制 Storybook 不为我的组件创建文件夹

发布于 2025-01-11 19:44:38 字数 804 浏览 0 评论 0原文

对于我的所有其他组件,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({});

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

近箐 2025-01-18 19:44:38

发生这种情况是因为故事名称是自动开始大小写的。因此,您打算为故事提供的名称 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;

网名女生简单气质 2025-01-18 19:44:38

如果 中的 title 属性与为 提供的 name 属性一致,则不会围绕故事创建补充目录:

<Meta 
    title="Notifications/Success Notification" 
    component={SuccessNotification}
/>

<Preview>
    <Story
        name='Success Notification'
        // props etc.>            
        {(args) => {return (<SuccessNotification {...args}/>)}}
    </Story>
</Preview>

If the title prop in <Meta> coincides with the name prop provided for <Story>, it won't create a supplementary directory around the story:

<Meta 
    title="Notifications/Success Notification" 
    component={SuccessNotification}
/>

<Preview>
    <Story
        name='Success Notification'
        // props etc.>            
        {(args) => {return (<SuccessNotification {...args}/>)}}
    </Story>
</Preview>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文