redwood: Storybook is not applying Tailwind CSS styles when working on components that use Redwood scaffold tailwind styles
When I use yarn rw storybook the styles applied from my project are not applied in storybook to the component. I’m not sure how to set that up or even where that is?
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 16 (6 by maintainers)
@jacebenson What about making/editing a
web/config/storybook.preview.jsto include?
[TSX] Ran into the exact same issue this morning. my workaround is that instead of using this:
I went with this:
Cleared cache, restarted both servers (redundant, I know), and it’s now working as expected.
“devDependencies”: { “@babel/core”: “^7.19.3”, “@storybook/addon-actions”: “^6.5.12”, “@storybook/addon-essentials”: “^6.5.12”, “@storybook/addon-interactions”: “^6.5.12”, “@storybook/addon-links”: “^6.5.12”, “@storybook/builder-vite”: “^0.2.4”, “@storybook/react”: “^6.5.12”, “@storybook/testing-library”: “^0.0.13”, “@types/react”: “^18.0.17”, “@types/react-dom”: “^18.0.6”, “@vitejs/plugin-react”: “^2.1.0”, “autoprefixer”: “^10.4.12”, “babel-loader”: “^8.2.5”, “postcss”: “^8.4.18”, “tailwindcss”: “^3.1.8”, “typescript”: “^4.6.4”, “vite”: “^3.1.0” }
if anyone runs into this issue again and they’ve configured a
prefixfor their classNames in tailwind.config, consider removing it. for me that was the reason the styles were not being applied.Hi @virtuoushub unfortunately no public repo. Running Index.css exactly as the above
and Importing it from
web/src/styles/index.cssand have tried running fromweb/src/index.cssI agree with you, I think it should only be communicated
Yup, that’s the issue. If you use tailwind css in your component like:
then
The styling applied.
So, the issue is that scaffold that use the RW tailwind stylesheet styles are not rending in storybook.
Edit: Updated issue title to be more descriptive.
In fact, Tailwind CSS discourages the use of @apply; see: https://tailwindcss.com/docs/reusing-styles#extracting-classes-with-apply
If you start using @apply for everything, you are basically just writing CSS again and throwing away all of the workflow and maintainability advantages Tailwind gives you, for example:
So, now the real only choice for me if I want to scaffold is to use custom scaffold templates for the generators and rework the css – which I may want to do since these displays all use tables instead.
I think what I really want are generator templates that use Tailwind UI markup and styles with a base color that is used for variants.
I’ll see if I can recreate it with a fresh project. This came up in a discussion on maker hour.