-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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 css with global styles changes the Storybook UI, workaround? #5648
Comments
I dunno if it's related, but #4945 has similar issues with the iframe retaining styles between switching stories. CSS rules added to an iframe definitely should not affect the containing DOM. |
FYI the info addon is being deprecated and moved into an addons panel in v5. That's probably what's picking up the styles and that's exactly why we're deprecating it. The issue is old, but it's at the top of my queue as soon as Storybook 5 is released in a couple weeks. |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Still looking for an answer on how to properly include global sass files into all iFrames (once) within Storybook. Please let me know! |
Same here |
@omaracrystal @tnatanael Have you tried the |
@omaracrystal @tnatanael - you can import a sass file inside of your
|
Unfortunately i moved out from this package for now, tks for the help |
It didn't work for me. I had to create a decorator that has to be included with the center decorator.
|
Looks like we are probably using different frameworks, which would probably account for the difference. I'm using storybook with React and CSS Modules with SCSS. In my // Add SCSS Modules support.
config.module.rules.push({
test: /\.scss$/,
loaders: [
require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: {
importLoaders: 1,
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]'
}
},
require.resolve('sass-loader')
]
}); And in import '../src/global/_global.scss'; I would expect the requirements would vary a lot depending on the framework(s) you are using though. |
In my case, I wanted to have support for both, CSS and LESS. I have this: module.exports = async ({ config, mode }) => {
// In order to not override theme styles, we use CSS Modules only for
// imported CSS and use LESS only because of the theme
config.module.rules[2].use[1] = {
loader: 'css-loader',
options: {
importLoaders: 1,
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]',
},
}
config.module.rules.push({
test: /\.less$/,
use: ['style-loader', 'css-loader', 'less-loader'],
})
return config
} |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook! |
Any recent update on this? |
To load global styles for stories without affecting storybook UI I've created file Note: I use React and CRA. For Angular apps additional steps are probably needed. |
hey, I have the same issues with global styles being applied to storybook UI elements. I am using @storybook/angular 5.3.18 with angular 9. |
@dana-c0914 canvas components are completely isolated but unfortunately the docs tab specifically is not. if you have a good repro you can share, maybe file a separate issue and we'll see if we can solve it? it's kind of a game of whack-a-mole, but we'll do our best. |
Read this solution. |
@nirus This work BUT my chrome dev tool it really slow. Anyone have the same issue? |
@od-nikola-mitic are you using TypeScript? |
Any updates on this? We have few project with different :root styles, and they've all persisted in the story that should not have them. |
We are using Storybook together with Create-React-App + TypeScript (sample repo: https://github.com/johot/storybook4-cra2-typescript-react-docgen-typescript-demo).
Now in our component library we import a regular
.css
stylesheet with some global styles likeh1,h2,h3,h4
etc.We import it by just doing:
import './styles.css'
from our components.Now when previewing our components in Storybook the Storybook UI will pickup these global styles (for its headers and other parts) which we don't want since it looks messy/wrong.
I can see that each story is loaded into an iframe but the problem is ofc that all
.css
global styles will affect everything in this iframe since its added to the iframe<head>
.Is there any workaround for this? I've tried reading through all issues I could find but only found solutions like postcss (to add prefixes) and so on. Also read about
preview-head.html
but didn't help us either.Are there any plans of having that iframe wrap just around the component and not the entire story? That would be one way I guess of localizing any global changes. Or are there any other workarounds we can use?
Thanks!
The text was updated successfully, but these errors were encountered: