-
Notifications
You must be signed in to change notification settings - Fork 44
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
Fix Storybook incompatibility with Tailwindcss (fixes #62) #74
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @linh! Thank you, this looks much better. However it looks like the heading isn't getting styled as I'd expect (it should be larger). I think this is because the styles in https://github.com/mozilla/glean-dictionary/blob/main/src/Tailwindcss.svelte aren't getting imported. Could you see if there's a way for them to be imported by default for all stories? You'll see that the main application includes them like this:
glean-dictionary/src/App.svelte
Line 36 in 5e78700
<Tailwindcss /> |
What I’ve tried I imported Tailwind to the story file itself to use as a styling wrapper with
My solution Currently, Tailwindcss is compiled to a separate CSS file at run time. The output of this file, according to the rollup configuration, is at Looking forward to feedback. Thank you! |
@linh Would this not work? Import Tailwindcss from “../Tailwind”
export const Basic = () => {
Component: SchemaViewer,
decorators: [(Story) => <div><Tailwindcss/><Story/></div>]
}; Using the bundle css directly might be ok, though I'd worry about it being kept up to date (I'm not sure if storybook will recompile it when it changes?). Regardless, thanks for your persistence on this! |
Hi @wlach, your code would cause an error in storybook. I believe because you used JSX ( The reason why I went with my solution because to fix this bug, the goal was to import the styling currently in For now it does the job. Any changes to
What do you think? I appreciate your time and feedback! |
You are of course totally right on this. Apologies for the misdirection.
I think this sounds like the way to go! The main piece of functionality we're looking for here are the storybook components reloading when people modify the top-level tailwind component. If that works, I think we're good to merge. Thanks so much for your persistence on this. |
This update is looking to fix 2 problems. 1) Tailwind incompatibility with StorybookCurrently Tailwind doesn't work properly in Storybook. This is fixed by updating the webpack configuration to include 2) Global styles not available globally
To fix this problem, we need to keep global styles in a different file. 3 main requirements:
I believe the best option is to replace Tailwindcss.svelte with a css file for global styles, because:
With this change, all stories will independently inherit global styles. We also don't have to rely on development build as the css file is imported directly to storybook. Looking forward to feedback @wlach. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in storybook, this works great! Unfortunately we lose live reloading inside the dev environment. I think what we need is a hybrid approach: the current approach in storybook, and the component approach in the actual app (by importing the css file inside of it, instead of defining it inline). I just tested and this seems possible, but I'll leave the solution to you.
This guide will be helpful for figuring it out: https://www.apostrof.co/blog/getting-tailwind-css-to-integrate-nicely-with-svelte-sapper/
Extra hint: You'll need to add postcss-import
.
package.json
Outdated
@@ -4,7 +4,7 @@ | |||
"scripts": { | |||
"build": "rollup --config", | |||
"build-storybook": "build-storybook --static-dir ./public --config-dir .storybook", | |||
"dev": "rollup --config --watch", | |||
"dev": "rollup --config --watch & postcss src/tailwind.css -o public/build/global.css -w", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not be necessary (see review)
Hi @wlach thank you for your feedback! I've updated my code with the hybrid approach. Looks like CircleCI failed my PR because of some code format error in ps Sorry about the messy commit history, I was changing the file around hoping it would pass Circleci. |
Format code Change css file name Fix linter error for circleci
@linh try running |
@wlach YES that fixed it, thank you so much! I learned so many new things this week. This PR is ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
This PR fixes issue #62 by adding the correct Tailwind CSS components, using https://github.com/jerriclynsjohn/svelte-storybook-tailwind as template.