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

Create an Addon that uses custom webpack loaders. #1121

Closed
cpsubrian opened this issue May 24, 2017 · 9 comments
Closed

Create an Addon that uses custom webpack loaders. #1121

cpsubrian opened this issue May 24, 2017 · 9 comments

Comments

@cpsubrian
Copy link

Howdy, I'm pretty close to finishing a pretty neat feature that I'm using on my storybook. I'd like to wrap it up into an addon so I can reuse it on other projects. In a nutshell it:

  • Lets you load *.story.src.js files as 'stories'.
  • These files just export a component that should be the story example.
  • It then loads those same files using both prismjs-loader and raw-loader.
  • It uses those to create syntax-highlighted code blocks showing you how the story is coded as well as parsing the original story source code for the first docblock.
  • This docblock is expected to follow a convenient format that provides the info needed to call storiesOf() with the proper category and whatnot.
  • The rest of the dockblock is assume to be a markdown description of the story.

See it in action here: https://terraeclipse.github.io/react-stack/?selectedKind=Mapbox&selectedStory=Controls&full=0&down=1&left=1&panelRight=0&downPanel=kadirahq%2Fstorybook-addon-actions%2Factions-panel

And the relevant code can be found here: https://github.com/TerraEclipse/react-stack/blob/master/tools/.storybook/util/loadSourceStories.js

I'm not too familiar with the addon API, so I'm not sure exactly how I'd ship this. It requires the prismjs-loader to be available. In theory then my 'addon' could just export a function you call and pass your directory to with possibly a customizable regex.

@cpsubrian
Copy link
Author

Perhaps it doesn't really work as an addon at all, and just needs to be up and documented somewhere so I/people can copy-paste.

@shilman
Copy link
Member

shilman commented May 25, 2017

Wow that's really beautiful. I think there are two ways to go with this.

  1. Make it an addon, where the source code displays in the addon pane. This would be pretty similar to https://github.com/Kilix/storybook-addon-jsx
  2. Make it a decorator, that just adds to the preview pane.

The benefit to option 1 is that you can then resize the preview pane as you want and you can test responsive behavior on the component, etc.

The benefit to option 2 is that it looks really great and integrated.

Long-term option 1 will be better because we'll improve Storybook's UI to make addons more powerful. But short term I don't have a strong opinion.

Either way, great work!

For more on writing addons: https://storybooks.js.org/docs/react-storybook/addons/writing-addons/

@shilman
Copy link
Member

shilman commented May 25, 2017

PS @cpsubrian Added you to our examples gallery (WIP) storybook-eol/storybooks.github.io#55

@cpsubrian
Copy link
Author

Oh awesome!

For the webpack loaders, would they be deps, devdeps, or peerDeps of an addon or decorator?

Due to how require contexts work, I think I'd have to have users pass in an actual require context, not a path, since webpack statically analyzes the 'require.context' call itself.

@cpsubrian
Copy link
Author

Looking forward to mobile UI, anything I could help with?

@ndelangen
Copy link
Member

@cpsubrian Would you please join us on our slack to discuss this ?

@stale
Copy link

stale bot commented Oct 31, 2017

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. We do try to do some housekeeping every once in a while so inactive issues will get closed after 90 days. Thanks!

@stale
Copy link

stale bot commented Dec 15, 2017

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 60 days. Thanks!

@stale stale bot added the inactive label Dec 15, 2017
@stale
Copy link

stale bot commented Dec 30, 2017

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!

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

No branches or pull requests

3 participants