-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[Bug]: Reusing stories does not handle default args or mappings #30470
Comments
** Disclaimer** This information might be inaccurate, due to it being generated automatically
|
Hi @DEfusion Thank you for opening the issue. I can't follow you though. // Primary.args = {}
export const Primary = { args: { buttonArgs: ButtonsStories.Primary.args } }; In the first example, WithChildren.args = { children: 'basic' }
export const WithChildren = {
args: { buttonArgs: ButtonsStories.WithChildren.args },
}; In the second example the children is correctly set to |
Thanks for your response, that makes sense. So for the first problem it should be: For the second I'd need to copy the To prevent things getting too complex I've quickly done this: const composeStoryArgs = ({ source, story }) => {
const args = { ...source.default.args, ...story.args };
const argTypes = { ...source.default.argTypes, ...story.argTypes };
Object.keys(args).forEach((key) => {
if (argTypes[key] && argTypes[key].mapping) {
args[key] = argTypes[key].mapping[args[key]];
}
});
return args;
}
export const Primary = { args: { buttonArgs: composeStoryArgs({ source: ButtonsStories, story: ButtonsStories.Primary }) } };
export const WithChildren = { args: { buttonArgs: composeStoryArgs({ source: ButtonsStories, story: ButtonsStories.WithChildren }) } }; However it'd be nice to be able to just get the output from a story and reuse that if possible. I also haven't tried this in my actual storybook yet but I suspect that this will then trigger the other issue I was having which required me to use mappings in my stories. |
Describe the bug
Say I have a story like so, using default
args
andmapping
:I want to reuse the
Primary
story in another so following the docs I do something like so:The default arg value for
children
is not present.If the Buttons story I'm trying to compose does define the
children
argument like so:When I try to compose it the value of
children
is the string"basic"
not the mapped value.Reproduction link
https://stackblitz.com/edit/github-glatzagq
Reproduction steps
System
Additional context
No response
The text was updated successfully, but these errors were encountered: