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

Self documented Storybook (A.K.A Addon Stories) #2885

Merged
merged 40 commits into from
Feb 18, 2018
Merged

Conversation

igor-dv
Copy link
Member

@igor-dv igor-dv commented Jan 31, 2018

So, I've been a bit annoyed about too many questions regarding documentation, like:

  • "You need to improve docs",
  • "How to do this or that"

One of the problems is that though we do have a lot of examples, they are not easily discoverable. So I thought what if we just show the code of the story as an addon. Then we can publish all the examples and link to them from docs. 🤔 Or even put them in the docs with Iframe.

What I did

So, I've added an experimental addon-stories, which probably won't have any sense for external usages.:

  1. It works with a custom loader that should be configured with a custom webpack.config ( maybe there is a better way 🤷‍♂️ ). This loader injects decorator with the source of the file. For the POC purposes, I've used some naive "string.indexOf" implementation, and probably should be replaced with some AST processing.
  2. Currently, the addon panel just shows the source as a plain text.

TBD:

  • Use syntax highlighting
  • Use AST parsing to find stories and inject decorator
  • Add option to highlight specific "add()" because we have multiple "adds" in one story file
  • Extract kind and use kind#story as a key in highlight locations map (only when kind is "Literal")
  • Rename package to something that makes sense

@igor-dv igor-dv added maintenance User-facing maintenance tasks documentation labels Jan 31, 2018
@igor-dv igor-dv requested a review from a team January 31, 2018 13:48
@codecov
Copy link

codecov bot commented Jan 31, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@343a695). Click here to learn what that means.
The diff coverage is 32.93%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2885   +/-   ##
=========================================
  Coverage          ?   37.23%           
=========================================
  Files             ?      435           
  Lines             ?     9328           
  Branches          ?      899           
=========================================
  Hits              ?     3473           
  Misses            ?     5302           
  Partials          ?      553
Impacted Files Coverage Δ
addons/storysource/loader.js 0% <0%> (ø)
addons/storysource/src/StoryPanel.js 0% <0%> (ø)
addons/storysource/src/index.js 0% <0%> (ø)
addons/storysource/src/loader/index.js 0% <0%> (ø)
addons/storysource/src/manager.js 0% <0%> (ø)
addons/storysource/src/preview.js 0% <0%> (ø)
addons/storysource/register.js 0% <0%> (ø)
addons/storysource/src/loader/parse-helpers.js 48.33% <51.78%> (ø)
addons/storysource/src/loader/inject-decorator.js 50.98% <55.31%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 343a695...e69de5a. Read the comment docs.

@shilman
Copy link
Member

shilman commented Jan 31, 2018

Awesome!!! Suggestion: addon-source? Addon-sourcecode?

@Hypnosphi
Copy link
Member

addon-storysource?

@igor-dv
Copy link
Member Author

igor-dv commented Feb 1, 2018

"addon-storysource" makes me happy =)

@igor-dv
Copy link
Member Author

igor-dv commented Feb 1, 2018

It looks much better with the syntax highlighting =)

image

@Hypnosphi
Copy link
Member

I have a crazy idea: what if we add CodeMirror?

@igor-dv
Copy link
Member Author

igor-dv commented Feb 1, 2018

Oh it's indeed crazy. So CodeMirror will allow code editing, but what's next 🙀

@igor-dv
Copy link
Member Author

igor-dv commented Feb 2, 2018

image

igor-dv and others added 3 commits February 16, 2018 10:30
# Conflicts:
#	examples/angular-cli/package.json
#	examples/polymer-cli/package.json
#	examples/vue-kitchen-sink/package.json
@Hypnosphi
Copy link
Member

a way we can publish every example to some static place

What's wrong with netlify deploys?

@igor-dv
Copy link
Member Author

igor-dv commented Feb 17, 2018

Can it be automated?

@Hypnosphi
Copy link
Member

Hypnosphi commented Feb 17, 2018

What do you mean? We currently deploy each commit
https://app.netlify.com/teams/storybook/sites

@igor-dv
Copy link
Member Author

igor-dv commented Feb 17, 2018

Is there any way to link netlify builds to docs? I think it will be nice to have a versioning of the examples like we wanted to do with the new docs. But that means all these static outputs should be persisted.

@Hypnosphi
Copy link
Member

There are branch deploys with permalinks

For example, this is a link to deploy of this branch that gets updated authomatically with each commit

https://addon-stories--storybooks-official.netlify.com/

On documentation site, we should use links to release/3.3 branch deploys (because master can contain usages of alpha features):
https://release-3-3--storybooks-official.netlify.com/

Copy link
Member

@Hypnosphi Hypnosphi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a README.md for the addon

/\.stories\.tsx?$/,
/index\.ts$/
],
loaders: [ ...originalTsRule.loaders, require.resolve('@storybook/addon-storysource/loader') ],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add this loader with enforce: 'pre' instead of patching the original rule:
https://webpack.js.org/configuration/module/#rule-enforce

@igor-dv
Copy link
Member Author

igor-dv commented Feb 18, 2018

I think I will add Netlify to docs in a separate PR.

@Hypnosphi
Copy link
Member

Hypnosphi commented Feb 18, 2018

Can we add scroll to the highlighted story (in separate PR)?

@Hypnosphi Hypnosphi merged commit 0ef47a6 into master Feb 18, 2018
@Hypnosphi Hypnosphi deleted the addon-stories branch February 18, 2018 14:05
@igor-dv
Copy link
Member Author

igor-dv commented Feb 18, 2018

Can we add scroll to the highlighted story (in separate PR)?

Sure

@igor-dv
Copy link
Member Author

igor-dv commented Feb 19, 2018

Can we make it as a patch to 3.3 ?

@Hypnosphi
Copy link
Member

Hypnosphi commented Feb 19, 2018

@shilman it's a new feature, but releasing it as patch could improve our documentation right now. WDYT?

@shilman
Copy link
Member

shilman commented Feb 21, 2018

I think we should just get 3.4 out sooner rather than back-patching a large new feature

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

Successfully merging this pull request may close these issues.

4 participants