-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Storybook for HTML cannot import components #10326
Comments
@emanuelepane did you try: import { Button } from "./button"; |
Thank you @shilman yes I did! As a result, the warning goes away, which is great and I understood why by looking it up (thanks!). However there is no actual Button displayed in Storybook. |
Hey @emanuelepane, the reason you're not seeing anything is because you're not exporting any variation of your button. This worked because there was a named export defined in your story file: // button.stories.js
export default {
title: 'Button',
};
export const Button = () => '<a role=button>Start</a>'; // <-- named export In your second case, there was none. // button.stories.js
import Button from "./button";
// missing named export, could be fixed with this:
// export { Button };
export default {
title: 'Button',
component: Button
}; Usually in stories you have multiple variations of a base component, so it's common to see multiple named exports, one for each variation. For example: // button.js
export const Button = (text = '') => {
const btn = document.createElement('button');
btn.innerHTML = text;
return btn;
};
// button.stories.js
import { Button } from "../components/button";
export const Empty = () => new Button();
export const WithText = () => new Button('Hello World');
export default {
title: 'Buttons',
component: Button
}; The |
Please refer to the docs for more info, but there is a section which states:
|
Hey @yannbf, Now I get it :) Thank you so much for taking the time to write this super clear explanation! I believe this can be closed! |
Crikey!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.0.0-alpha.32 containing PR #10357 that references this issue. Upgrade today to try it out! You can find this prerelease on the |
I am trying to use Storybook for HTML.
I want to follow the CSF approach and keep component and stories separated.
These are my doc references:
To Reproduce
Steps to reproduce the behavior:
button.stories.js
and watch it work withnpm run storybook
button
component, adjust the code to import it (see https://storybook.js.org/docs/guides/guide-html/) and runnpm run storybook
Expected behavior
The
Button
is importedSystem:
The text was updated successfully, but these errors were encountered: