简体   繁体   English

在 Storybook 中排序:可以强制嵌套故事的顺序吗?

[英]Sorting in Storybook: Possible to force an order for nested stories?

My Storybook uses the following grouping for stories:我的故事书对故事使用以下分组:

Introduction
Styleguide
Atoms
  Component
    📄 README
    📁 Examples
  Component
    📄 README
    📁 Examples
Molecules
  Component
    📄 README
    📁 Examples
Organisms
  Component
    📄 README
    📁 Examples
  • Basically three groups: Atoms, Molecules, and Organisms.基本上分为三组:原子、分子和有机体。
  • Each group should have alphabetized components.每个组都应该有按字母顺序排列的组件。 This currently works.这目前有效。
  • Each component has a README mdx file, and then all stories nested under Examples.每个组件都有一个 README mdx 文件,然后所有的故事都嵌套在 Example 下。

I'm currently sorting stories like this:我目前正在整理这样的故事:

options: {
    storySort: {
        method: 'alphabetical',
        order: ['Introduction', 'Styleguide', 'Atoms', 'Molecules', 'Organisms'],
        locales: 'en-US',
    }
},

This gets me close , but the README and Examples within component stories appear in alphabetical order when I want README to appear first.这让我很接近,但是当我希望自述文件首先出现时,组件故事中的自述文件和示例会按字母顺序出现。

Is this possible?这可能吗?

I had a similar problem, and I could find a way of doing as you requested, after finding this info on the storybook documentation :我遇到了类似的问题,在故事书文档中找到此信息后,我可以找到按照您的要求进行操作的方法: 在此处输入图片说明

For your specific case, I think that you could do something like this:对于您的具体情况,我认为您可以执行以下操作:

options: {
    storySort: {
        method: 'alphabetical',
        order: ['Introduction', 'Styleguide', 'Atoms', ['Readme', '*'], 'Molecules', ['Readme', '*'], 'Organisms', ['Readme', '*']],
        locales: 'en-US',
    }
},

Basically, you just have to add , ['Readme', '*'] after every group that you like to sort by using the Readme first custom order.基本上,您只需要在您喜欢使用Readme first自定义顺序排序的每个组之后添加, ['Readme', '*'] This just indicates storybook to display the Readme story first, and then the rest of the stories.这只是指示 storybook 首先显示Readme故事,然后显示其余的故事。

This approach solves the problem, but I think that the solution could be improved by writing your own storySort functions, as indicated on this comment in github这种方法解决了问题,但我认为可以通过编写自己的 storySort 函数来改进解决方案,如github 中的此评论所示

I hope this answer would be helpful for your scenario too.我希望这个答案对你的场景也有帮助。

Regards问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM