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 Web components #11588

Closed
shilman opened this issue Jul 16, 2020 · 9 comments
Closed

Dynamic source rendering for Web components #11588

shilman opened this issue Jul 16, 2020 · 9 comments

Comments

@shilman
Copy link
Member

shilman commented Jul 16, 2020

Follow-up to #11332 but for Web components

@maggiewachs
Copy link

maggiewachs commented Aug 3, 2020

@shilman thank you for adding this! Anything I can do to help get some traction here?

@shilman
Copy link
Member Author

shilman commented Aug 3, 2020

@maggiewachs thanks for your enthusiasm for this. after 6.0 is released i can write more about what this might look like. but the core idea is that for each framework we need a decorator that takes the rendered output of the story function and converts it to an appropriate human-readable string. if you can contribute a proof of concept for web components, i'd be happy to point you at how to integrate that into Storybook.

@maggiewachs
Copy link

@shilman:

we need a decorator that takes the rendered output of the story function

If you can point me to an example of how to access the rendered output, I'm game to hack something together. :) Is there an API that describes each story?

@maggiewachs
Copy link

@shilman *bump* This issue could be a real blocker for us, we need working code samples for clients. LMK if you or someone on the team can provide a little direction, I'd be happy to at least take a look and see if it's something I can do. TY!

@shilman
Copy link
Member Author

shilman commented Aug 11, 2020

@maggiewachs It looks like the result of the storyFn is either TemplateResult or Node (or string already):

https://github.com/storybookjs/storybook/blob/master/app/web-components/src/client/preview/render.ts#L19

https://github.com/storybookjs/storybook/blob/master/app/web-components/src/client/preview/render.ts#L31

So, given a function that takes one of those values and outputs a useful String, ideally with tests, I'd be happy to do the integration on the Storybook side (which is not necessarily straightforward and subject to change).

@shilman
Copy link
Member Author

shilman commented Apr 10, 2021

As a workaround until this is ready: if you're using args stories, you can set the docs.source.type parameter to "code" and it will use the static source code of the story function.

@bennypowers
Copy link
Contributor

cc @Matsuuu

@shilman
Copy link
Member Author

shilman commented Jul 10, 2021

Yippee!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.4.0-alpha.14 containing PR #15337 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 Jul 10, 2021
@jbruni
Copy link

jbruni commented Aug 3, 2021

@shilman - I'm a Storybook newbie, and I've been happily using the HTML "framework" for vanilla Web Components (non-lit).

I could resolve my own willing for dynamic source there, quick and easy, if only the code (or other docs.source property from story parameters) accepted a function which received the "args" and provided the code string as output.

This PR as well as #11332 are overwhelming to me... And I think that even if someone introduces a given solution for the HTML "framework", others may have their own custom needs.

If people can provide their own function... we would be able to provide whatever dynamic source code strategy we want, without the need of knowing Storybook internals and changing each framework's implementation.

P.S.: I'm sorry if this is not the proper place for a feature request... at least I have the context here. Thank you!

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