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

Dynamic source rendering for Vue #11400

Closed
shilman opened this issue Jul 3, 2020 · 10 comments
Closed

Dynamic source rendering for Vue #11400

shilman opened this issue Jul 3, 2020 · 10 comments

Comments

@shilman
Copy link
Member

shilman commented Jul 3, 2020

Follow-up to #11332 but for Vue

@shilman shilman self-assigned this Jul 3, 2020
@shilman shilman added this to the 6.0 docs milestone Jul 4, 2020
@shilman shilman added the vue label Jul 4, 2020
@shilman shilman modified the milestones: 6.0 docs, 6.1 docs Jul 10, 2020
@stale stale bot added the inactive label Aug 1, 2020
@shilman shilman added the todo label Aug 1, 2020
@stale stale bot removed the inactive label Aug 1, 2020
@storybookjs storybookjs deleted a comment from stale bot Aug 16, 2020
@i-void
Copy link

i-void commented Sep 11, 2020

First of all, thank you for your efforts. You are doing great work. It would be very good to see this feature in production. Just wanted to say. Also I need to say showing source is not properly work in Vue when using standard npx sb init. All story sources are showing this code for button example:

(args, { argTypes }) => ({
  props: Object.keys(argTypes),
  components: { MyButton },
  template: '<my-button @onClick="onClick" v-bind="$props" />',
})

@zackkrida
Copy link

Dynamic behavior aside, Storybook doesn't display the correct source for Vue components at all, correct?

This is the output I get:
Screen Shot 2020-09-11 at 6 05 44 PM

@shilman
Copy link
Member Author

shilman commented Sep 12, 2020

@zackkrida that's the source code of the story, which is the intended behavior

@zackkrida
Copy link

@shilman Apologies if I came off as rude in any way—I understand that's the 'source', as written.

It's probably also an impossible or difficult problem, but I'm just referring to the idea that the source of a Vue component would reflect what folks would write in user land as consumers of a component library.

@shilman
Copy link
Member Author

shilman commented Sep 12, 2020

@zackkrida No offense taken. As we've evolved storybook the story source is getting more abstracted/efficient (e.g. auto-generated controls), but further away from what you'd write in an app. This issue exists both to show the dynamically updated arg values and also render the component usage in a more natural way. Let's see what we can do!

@richardhuf84
Copy link
Contributor

Just adding a +1 here. WOuld love to see those Vue code snippes resemble the Vue source if possible.

@shilman
Copy link
Member Author

shilman commented Oct 15, 2020

@richardhuf84 please add a 👍 to the original issue description. that's the most direct way to help us prioritize.

pocka added a commit that referenced this issue Oct 18, 2020
#11400

This commit adds dynamic source code rendering feature to Docs addon for
Vue.js. The goals are 1) reflecting Controls' value to code block and
2) showing a code similar to what component consumers would write.

To archive these goals, this feature compiles a component with Vue, then
walks through vdom and stringifys the result. It could be possible to
parse components' template or render function then stringify results,
but it would be costly and hard to maintain (especially for parsing).
We can use vue-template-compiler for the purpose, but it can't handle
render functions so it's not the way to go IMO.

Speaking of the goal 2, someone wants events to be in the output code.
But it's so hard to retrieve component definitions (e.g. `methods`,
`computed`). I think it's okay to skip events until we figure there is a
high demand for that.
@shilman
Copy link
Member Author

shilman commented Oct 19, 2020

Huzzah!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.1.0-alpha.27 containing PR #12812 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb upgrade --prerelease

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed Oct 19, 2020
@richardhuf84
Copy link
Contributor

Thanks @shilman

I've updated to 6.1.0 alpha, and can confirm that the code snippets look correct for Vue. Thanks alot for your work, and being so responsive.

@shilman
Copy link
Member Author

shilman commented Oct 19, 2020

All credit goes to @pocka who saved the day on this one. 🎉

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

4 participants