-
-
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
Importing global style of styled-component for all stories #5578
Comments
Hi @eldyvoon, The best approach here is to add a global decorator // in config.js
import { addDecorator } from '@storybook/react';
addDecorator(s => <><GlobalStyle />{s()}</>); |
How would I import into Angular Storybook all of my global styles (scss) with several imports such as: Normalize, Base, Mixins, Variables, Thirdparty? |
Is there any other approach? This causes the GlobalStyle to be mounted and unmounted on each story mount. Which is impacting the performance. For example, in our case, we have |
Maybe we could mount that component only once, i.e. in |
For now we have moved that into that import { render } from 'react-dom';
import { GlobalStyle } from '../../theme/GlobalStyle';
function loadStories() {
const globalStyleEl =
document.querySelector('#gen3-global-style') ||
(() => {
const el = document.createElement('div');
el.id = 'gen3-global-style';
document.head.append(el);
return el;
})();
render(<GlobalStyle />, globalStyleEl);
...
} and it works. I don't know if that function passed to |
Thank you jack-sf! It took me a while, because the render method wasn't working at first. This is how I called it now:
|
With Storybook 6x I loaded my global style like this; //.storybook/preview.js
import { addDecorator } from "@storybook/react";
import { GlobalStyle } from "./../pages/_app";
addDecorator((story) => (
<>
<GlobalStyle />
{story()}
</>
)); |
This is not really a bug but I'm stuck importing global style of styled-component, for now I have to include it in every single of my story
The text was updated successfully, but these errors were encountered: