-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
MDX ability to loop (map) <Preview> and <Story> #8392
Comments
@vinceumo Unfortunately I don't see this happening any time soon. Those story definitions get automatically compiled to named exports when the file is loaded, so they need to be static at this time. Making them dynamic is tricky, and a low priority unless somebody from the community wants to take it on. |
For simple and deterministic cases, you might consider using this. Kent Dodds is great, and he made this for pretty much exactly this use case, as you can see from the example. |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook! |
Are there any updates on this one? Would be highly interested in this feature as well. Especially when I think of Design Tokens (Colors, Icons, etc.) and using |
@lukaskoeller You can do that WITHIN a Story or JSX element in the page, no problem. The only limitation is you can't dynamically generate stories. But it doesn't sound like you need that for your use case. |
Does this also works for
This appears when I'm trying to use for (let [key, value] of Object.entries(tokens)) {
console.log(key, value);
} But also, seems like JSX does not like |
Hi @lukaskoeller, in JSX you should use .map. https://reactjs.org/docs/lists-and-keys.html Assuming you have an object you could have something like that: <Preview>
<Story name="My Story">
{Object.keys(tokens).map(key => (
<p>My key is {key} and my value is {tokens[key]}</p>
)}
</Story>
</Preview> |
Thank you @shilman and @vinceumo very much for your help. For anybody interested and feedback for improvements, I ended up using this code: <ColorPalette>
{
Object.entries(tokens.color.brand).map((token, i) => {
return(
<ColorItem
key={i}
title={`${token[0]} color`}
subtitle={ token[1].base.name.replace('Base', '[name]') }
colors={
Object.entries(token[1]).map((value) => {
return value[1].value
})
}
/>
)
})
}
</ColorPalette> |
Hi, Thanks for this project, I love using it.
I'm using MDX, I would like to be able to generate multiple stories using an array. Not sure if it is possible.
I tries something like that with
@storybook/react v5.2.3
:I have no error but the output is not as expected:
Thanks a lot
The text was updated successfully, but these errors were encountered: