-
-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automated "All stories" story #505
Comments
I just found this: https://storybook.js.org/addons/storybook-addon-variants |
You can pretty easily make something like this happen with csf, excuse the formatting I'm just doing this from memory.
|
I can create a util function that I can reuse in my project: export function renderAllStories<T>(meta: Meta<T>, stories: StoryObj<T>[]) {
return (
<>
{stories.map((story, index) => (
<Fragment key={index}>
<InlineStorySectionHeader title={story.name ?? ''} />
{meta.component && <meta.component {...meta.args} {...story.args} />}
</Fragment>
))}
</>
);
} and use it like so: export const All: StoryObj<CookStatsProps> = {
render: () =>
renderAllStories(CookStatsMeta, [
WithEverything,
NoOrderCount,
NoRating,
NoOrderCountNoRating,
]),
}; Small question: how does Storybook get the name of the story objects (e.g. |
when you import/require a module it has all the named exports and the default export in there like
so when you import that file its like const file = require("location") this file has all of those things so yeah you could actually do this more automated yet probably by getting the current module and looping through it |
@sregg since you can get the current module from just accessing "module", you should be able to do this:
|
Sounds good. I'll see if I have time to build that into this package itself. |
Is your feature request related to a problem? Please describe.
When I have a lot of stories for a given component, it can be tedious to switch stories (i.e. side bar, click story, side bar, click story, etc...). I'd like to be able to see all stories in one screen. Especially for small components like buttons or list items.
Describe the solution you'd like
It'd be great to have the ability to automatically add an "All" story where all stories are rendered after an other with their title.
Describe alternatives you've considered
Infinite Red's Ignite had some cool components like
UseCase
for achieving this (see PR when they removed all that here) but the new CSF format doesn't support this (i.e. you can't easily render multiple components in one story).Are you able to assist bring the feature to reality?
Yes!
Additional context
Example of Story in Ignite:
Something similar but automated would be awesome.
The text was updated successfully, but these errors were encountered: