Component-level css not loading into stories
See original GitHub issueI created a react app using create-react-app, and added a button component, a css for the button. When I load the story for the button, the styles are not loaded for the button. Pasting below, the related files. Is there any configuration that I am to do, to get this up and running with styles?
Component: index.js
import React, { Component } from 'react';
import styles from './style.css';
class CustomButton extends Component{
render(){
return (
<button className={styles.customButton}>Hello</button>
);
}
}
export default CustomButton;
style.css:
.customButton {
border: 1px solid red;
padding: 10px;
background-color: rgb(223, 19, 19);
}
Story file:
import React from 'react';
import CustomButton from '../../src/index';
import { storiesOf } from '@storybook/react';
const story = storiesOf("Custom button",module);
story.addWithJSX("simple",() => <CustomButton/>);
System info:
Environment Info:
System:
OS: Windows 7 6.1.7601
CPU: (2) x64 Intel(R) Core(TM) i3-2370M CPU @ 2.40GHz
Binaries:
Node: 10.16.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 84.0.4147.125
npmPackages:
@storybook/addon-info: ^5.3.19 => 5.3.19
@storybook/components: ^5.3.19 => 5.3.19
@storybook/preset-create-react-app: ^3.1.4 => 3.1.4
@storybook/react: ^5.3.19 => 5.3.19
Issue Analytics
- State:
- Created 3 years ago
- Reactions:12
- Comments:28 (5 by maintainers)
Top Results From Across the Web
Storybook Component-level css file not working - Stack Overflow
I have added them within the config.js file. Storybook is loading for me. Just that the css is not applied to my component....
Read more >Styling and CSS - Storybook
Storybook is a frontend workshop for building UI components and pages in ... To use your CSS in all stories, you import it...
Read more >Next.js: Global CSS cannot be imported from files other than ...
When migrating to Next.js 9+, I was running into an issue where I could not import global styles from any file other than...
Read more >Styling - Remix
You can also import CSS files directly into your modules and Remix will: ... Keep in mind each component must be imported already,...
Read more >6 Ways To Configure Global Styles for Storybook | by Jennifer Fu
We want to configure it to a different color, without going to each story to set it. Pink Background: Use Stylesheet in preview-head.html....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I had the same issue where styles using SCSS in Vue Single File Components where ignored when building the Storybook using
build-storybook
:When the style was marked as
css
it worked fine. I managed to fix it forscoped
styles, too, with the same solution.Note that my Vue components are in a Yarn workspace and they are split in several packages that are marked as ES Modules using
"type": "module"
in theirpackage.json
. They are also marked as"sideEffects": false
to enable tree-shaking.I managed to fix this by adding a new rule for
scss
files and marking them as having side-effects. WithoutsideEffects: true
this didn’t work for me either.I have been encountering the same issue, only when building storybook and deploying it. Launching storybook in dev mode, it seems to load the styles correctly.