-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Allows users to create a custom storybook preview config #2048
Conversation
This allows a user to create a custom Storybook preview file in `web/config/storybook.preview.js` and have it imported into the framework's version. I haven't added any documentation yet for two reasons. First, I want some confirmation that this approach is reasonable. But also, this actually took me a lot longer than it should have because I didn't realize that we're still on Storybook 5.3 and had to use the old `addDecorator` syntax. I suspect this will trip up other users as well, so perhaps it would be worthwhile to update to the latest Storybook before publicizing this feature? Anyone who tries to reference the Storybook docs for the content of this file will likely also be confused.
@@ -29,6 +29,10 @@ const baseConfig = { | |||
} | |||
} | |||
|
|||
if (fs.existsSync(getPaths().web.storybookPreviewConfig)) { | |||
sbConfig.resolve.alias['~__REDWOOD__USER_STORYBOOK_PREVIEW_CONFIG'] = getPaths().web.storybookPreviewConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since getPaths()
needs to run in a node context, we can't run it from preview.js
directly. Instead, I elected to run it on this side and expose the path to the user's preview file as a Webpack alias.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's 100% the way. I meant to document that in the comments, I hope it wasn't too painful to figure out.
@@ -14,3 +14,11 @@ require('~__REDWOOD__USER_WEB_DEFAULT_CSS') | |||
addDecorator((storyFn, { id }) => { | |||
return React.createElement(StorybookProvider, { storyFn, id }) | |||
}) | |||
|
|||
try { | |||
require('~__REDWOOD__USER_STORYBOOK_PREVIEW_CONFIG') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if there's a more idiomatic way to implement "require this path if it exists".
Thanks for getting this rolling @corbt!
^^ Yes, we have this on our radar but have yet to start implementation. Might you be available/interested in helping to upgrade? Looping in @peterp who has lead all the Storybook work. |
I can probably spend a few hours looking into it next week, yes! |
Closing in favor of #2054, which includes this commit and updates it to work with Storybook 6.1. |
This allows a user to create a custom Storybook preview file in
web/config/storybook.preview.js
and have it imported into the framework's version.I haven't added any documentation yet for two reasons. First, I want some confirmation that this approach is reasonable. But also, this actually took me a lot longer than it should have because I didn't realize that we're still on Storybook 5.3 and had to use the old
addDecorator
syntax. I suspect this will trip up other users as well, so perhaps it would be worthwhile to update to the latest Storybook before publicizing this feature? Anyone who tries to reference the Storybook docs for the syntax of this file will likely also be confused.Sample
web/config/storybook.preview.js
:And displayed component:

cc @peterp who opened #1595 and @Tobbe who pointed me to it from the Discord!