Skip to content
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

Using conditional statements in the default export CSF format. #18233

Closed
mikokofuyu opened this issue May 16, 2022 · 3 comments
Closed

Using conditional statements in the default export CSF format. #18233

mikokofuyu opened this issue May 16, 2022 · 3 comments

Comments

@mikokofuyu
Copy link

Describe the bug

I am trying to use an environment variable to change the excludedStories property in the default export. But it causes the story to fail to build.

The following solutions do not work.

// handling the conditional in-line

export default {
    title: 'Atoms/Button',
    component: Button,
    excludeStories: isVisualTestingMode ? ['SecondaryButton', 'PlayButton'] : [];
};
// Handling the conditional in a const

const excludeStories = isVisualTestingMode ? ['SecondaryButton', 'PlayButton'] : [];

export default {
    title: 'Atoms/Button',
    component: Button,
    excludeStories: excludeStories
};

However I did manage to get a very odd solution to work (see below) this leads me to believe there is some issue with how the default export handles conditionals?

const objectOfStuff = { title: 'Atoms/Button', component: Button };

if (isVisualTestingMode) {
    objectOfStuff.excludeStories = ['SecondaryButton', 'PlayButton'];
}

export default objectOfStuff;
@hewelt
Copy link

hewelt commented May 20, 2022

Something like this would be really useful in my case too, where I'd like certain stories to be captured by Chromatic but not present in the sidebar 👍🏻

@mikokofuyu
Copy link
Author

Update I think upgrading to v6.5 actually breaks the hacky workaround solution I found too. So it would be really good to get this looked into.

@shilman
Copy link
Member

shilman commented Jan 14, 2024

RFC here: #25535

Implementation here: #25328

You can use two different config files depending on which environment you're in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

3 participants