-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
Displaying imported HTML in Storysource #8297
Comments
Just a quick follow up to this, in older versions of @storybook/html (v5.1.9) I used to do this with success: .storybook/config.js import { withStorySource } from '@storybook/addon-storysource';
addDecorator((storyFn, context) => {
const source = storyFn()
return withStorySource(source)(storyFn, context)
}) However with @storybook/[email protected] upwards I get the following error with this technique:
|
I believe this is the change that has introduced the issue: https://github.com/storybookjs/storybook/pull/7272/files#diff-904dad7f92c7bbfac64aca74960bbf33 |
@libetl do you have any time to look at @danhead 's error above?
|
@shilman You added a "TODO" label but didn't re-open the issue. It still appears to have problems, which appear to be related to the changes mentioned by @danhead: I am trying to use the following:
(to overwrite the source inserted automatically by register) but nothing changes in the Storysource panel. I debugged the "storybook/source-loader/set" event parameters, and the source added by register has the following event parameters:
but the events triggered by "withStorysource" have the following event parameters:
I guess that setStorySource() needs updating to work with the new format? |
I created a pull request with a fix for the issue I described above:
If you try to use If this is the expected behaviour, how can I override it so that I can overwrite the storysource in specific stories? |
@LeeBurton thanks for taking the time to file this pull request. For 6+, storybook is moving away from addDecorator: #9506 and I just filed a refactor of source-loader here: #9547 Would you like us to work together on adapting your use case to use parameters instead of addDecorator with the new code base? @shilman ? |
An example of using storySource parameters: |
We are using the HTML version to include web components, rather than React, so I guess that we are a little limited with what we can do in the stories. It would be useful if I could somehow set a parameter within the stories, then access that parameter within a global decorator to emit an event to update the source panel. Currently, the only solution I have found is to emit the event in the stories. This also solves the problem that the Webpack loader injected decorator story source is overwriting the story decorator source (but only with my pull request changes, otherwise the wrong parameters are provided to emit(). This is causing me real difficulties on my client’s project, and I’m struggling to make progress after trying various solutions for a week 😳 When is version 6 scheduled to be released? |
Plus, this should also be tagged as a bug, I guess. |
@LeeBurton - did you check the example, it does not use events at all and this makes it to also work for the docs tab (the source-loader events were only working for the StorySource panel):
|
I’ll explain a little more about what I’m trying to achieve, as I’m not sure how this helps with my problem. The story uses a template string with our custom elements, such as:
and I am then populating it with data by setting the “data” attribute. So I need to document our grid component HTML code, but also the necessary code populating various attributes, including the example JSON data. The grid component includes pagination. When a paging button is clicked, the next page of data is fetched from the backend API and used to update the “data” attribute. I need to show the developers how the data is changing when events such as paging occurs. |
Thanks @LeeBurton I think we can have a 'dynamic' @shilman - any thoughts? |
@atanasster @LeeBurton Parameters cascade, so global parameters can be overridden at a story level, just as you have done in your comment above @atanasster . I don't think we need to do anything special to support user configuration. Maybe just better documentation on how to do it. |
|
you can create separate stories for each state that you want to show. in the future we may try to support more interaction scenarios, but we have our hands pretty full with doing a great job of simply showing every state. you can also link between stories with |
I greatly appreciate the hard work you guys are doing, but any assistance in achieving my goals would be greatly appreciated. My client is a government department responsible for building web components that various other government departments can use, and we are trying to convince them that Storybook is the best choice for documenting their components for developers in the other departments. If we cannot make progress quickly, they may start looking at other options. For this particular component, I have a story that uses knobs, and interactions. I need to be able to show documentation for the current story HTML with the attributes set (which I could get from Is it not currently possible to update a parameter in stories (that I can access in a decorator)? |
As far as I know it's not possible to update parameters dynamically this way. @atanasster and @ndelangen have been working on powerful addon APIs (shared state hooks) that could make sharing state between stories & addons much easier. It might be fairly easy to implement your use case using that shared state hook, and not have to deal with the entirety of storysource for that purpose. |
@LeeBurton as michael mentioned, its not possible to modify parameters dynamically. |
Okay, thanks. Unfortunately, I’m too much under pressure with my client’s project at the moment. If I have more time later, I’d love to help. When is v.6.0 release planned? When will my bug fix pull request likely be merged to fix the storySource event parameters to the correct format? Currently my workaround won’t work without these changes merged... |
@atanasster When I set the |
@LeeBurton - are you trying the PR, its not yet merged. If yes, please try the html-kitchen sink example https://github.com/storybookjs/storybook/pull/9547/files#diff-f9e4c1787dc63502454a68f7ff88245c |
@atanasster I don’t understand what you mean by “are you trying the PR”... which PR? The one you just included? When are your changes likely to be merged and available? |
@LeeBurton - yes i meant the listed PR from above. That PR is meant for 6.0 and @shilman would know about the merging, but i think he is currently very busy with the 5.3 updates. |
I can probably merge/release an alpha today, but I want to do another review & test it first. Juggling a lot. |
|
Will release this in 6.0-alpha on Thu at earliest, Sat at latest. Currently in a remote area with poor network connection, and unfortunately the release process requires a good connection. Thanks for your patience. |
This works great, now could someone say how write a storydocs for a example like that? |
@juniovitorino like this? import button from './button.html';
export default {
title: 'Addons/Source loader',
};
export const Button = () => button;
Button.story = {
parameters: {
storyDescription: 'some description here',
storySource: {
source: button,
},
},
}; |
@shilman Am I right that the correct format now is import button from './button.html';
export default {
title: 'Addons/Source loader',
};
export const Button = () => button;
Button.parameters = {
storyDescription: 'some description here',
storySource: {
source: button,
},
}; Also is this documented anywhere? |
We’re cleaning house! Storybook has changed a lot since this issue was created and we don’t know if it’s still valid. Please open a new issue referencing this one if:
|
Support request summary
I would like to be able to display imported HTML in the Storysource panel, rather than the contents of the
.stories.js
file.Steps to reproduce
html/button.html:
stories/index.stories.js:
.storybook/addons.js
.storybook/webpack.config.js
Please specify which version of Storybook and optionally any affected addons that you're running
Expected result
I would like the Storysource panel to display the contents of
html/button.html
Actual result
Storysource panel shows contents of
stories/index.stories.js
Any advice on how to achieve this is greatly appreciated.
Thanks!
The text was updated successfully, but these errors were encountered: