#Importing Tailwind & Material theme into my Storybook within NX namespace.
136 messages ยท Page 1 of 1 (latest)
Have you seen https://storybook.js.org/addons/@storybook/addon-styling from @narrow dome?
Oh shoot, I thought that got fixed.
try it from here: https://github.com/storybookjs/addon-styling
@narrow dome should I stop sharing the link to the addon on the storybook webpage, and share the github link instead?
ok got it, thanks. hopefully to get some success ๐
Hey Ian! Yes please โค๏ธ I still need to replace the links so that the addon page can link out
@oak crown Let me know if you need a hand ๐
I know scss and postcss can still be a little fiddly ๐ I'm trying to simplify it now
Is your NX project going to be Angular?
i might! ๐ i am new to storybook. I am in latest NX namespace, I generated shared angular library with some components and generated Storybook for it. Just having issues to add styles and assets similarly to how Apps leveraging these assets
for now i added styles to project.json under build-storybook > options
In the meantime, here's the correct link: https://github.com/storybookjs/addon-styling/blob/main/docs/getting-started/tailwind.md
Thanks, already there. Do i need something else for scss?
for example i have scss file with imports
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
At this point, I'll tag in the addon/recipe author, @narrow dome.
module.exports = {
core: { builder: 'webpack5' },
stories: ['..//*.stories.mdx', '..//*.stories.@(js|jsx|ts|tsx)'],
addons: [
'@storybook/addon-essentials',
'@storybook/addon-links',
'@storybook/addon-interactions',
'@storybook/addon-a11y',
// '@storybook/preset-scss',
// '@storybook/addon-styling',
],
framework: '@storybook/angular',
};
preview is empty atm
i also modified project.json for that shared library
"build-storybook": {
"executor": "@storybook/angular:build-storybook",
"outputs": ["{options.outputDir}"],
"options": {
"outputDir": "dist/storybook/lib-shared",
"configDir": "libs/lib-shared/.storybook",
"browserTarget": "lib-shared:build-storybook",
"compodoc": false,
"styles": [
"styles/default/colors.scss",
"styles/default/material-theme.scss",
"styles/default/tailwind-imports.scss"
]
},
"configurations": {
"ci": {
"quiet": true
}
}
}
So preview.js is where you'll want to import that scss file with your tailwind imports
ok
you'll want to import all those scss files
(It might not all work out of the box but we'll take it from there :D)
thank you for the hard work!
It's no problem at all, Bio ๐ I'm happy to help
import "styles/default/tailwind-imports.css";
export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
expanded: true,
hideNoControlsWarning: true,
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
};
in preview
lets see if works
then will try with .scss
Funnily enough, I think your scss imports are going to work but your tailwind.css might not ๐ ๐
ok kicked a build now, lets see
it does not import tailwind
the rest seems to work by just adding .scss files into the build process in project.json without doing any addons
Okay, perfect ๐ So that will be because tailwind needs postcss ๐
it didnt work with postcss
We'll get it working ๐
add this into your main.js addons:
{
name: "@storybook/addon-styling",
options: {
postCss: true,
},
},
Also add this postcss.config.js file to your project root:
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
}
}
trying now
still no luck even with postcss.config.js file
What error(s) do you get?
Interesting! That's okay ๐ we'll get it
If you look into the dev tools panel in your browser, are there any errors in there?
btw .scss file didnt work
importing as .css
i have just for missing svg files, that the next thing i would need to solve.
but its unrelated
Can you change the import for your tailwind files to this:
@tailwind base;
@tailwind components;
@tailwind utilities;
brb taking my dogs out ๐
sounds good
How did it go? Just trying to wrangle in the last dog
i think i saw the styles appear for a moment and then gone
removing stuff from build process
rebuilding again
Well that sounds like a positive! maybe we're onto something here ๐
Just checking in ๐ how'd it go?
It's all good ๐
still doesnt work
interesting if i put my own styles in that file with imports to tailwind
my styles work
Yeah, so the postcss setting aren't being applied
Oh!
Let me see your tailwind.config.js!!!
ok
tailwin.config.js is in application not in the library
const { createGlobPatternsForDependencies } = require('@nrwl/angular/tailwind');
const { join } = require('path');
/** @type {import('tailwindcss').Config} /
module.exports = {
content: [
join(__dirname, 'src/**/!(.stories|*.spec).{ts,html}'),
...createGlobPatternsForDependencies(__dirname),
],
theme: {
extend: {},
fontFamily: {
roboto: ['Roboto', 'sans-serif'],
},
},
plugins: [],
};
do i need to include this into main.js somehow?
Nope... but without reading the components in your library it won't build your tailwind classes for your library components
ok, so what do i need to do?
Can you copy this file into your library folder?
NX Generating @nrwl/angular:setup-tailwind
NX The target "build" was not found for project "lib-shared".
If you are using a different build target, please provide it using the "--buildTarget" option.
If the project is not a buildable or publishable library, you don't need to setup TailwindCSS for it.
Pass --verbose to see the stacktrace.
ok lemme copy
nx + angular libs + storybook + tailwind = is tricky ๐
copying tailwind.config.js into the root of the library didn't help. What should I try next?
Are you trying to use tailwind classes in your library components?
yes
the crazy thing, i see tailwind styles at the very 1st moment after i rebuild the app and it reloads the page
then it goes away
hmmm okay
like for a fraction of a second
That is odd
agreed
It might be helpful if you start a new project and slowly try to match your config, and see if you can reproduce the issue
I was about to ask, what steps can I take to reproduce your NX repro structure
Are you using storyStoreV7: false?
just one app, one lib that has a storybook
and 1 component
where do i need to set it?
you shouldn't have to
i have 6.5+ installed
ah, ok I thought you were on 7.
nop
I'm not super familiar with NX so you'll have to bare with me here. Are you using a package based project or integrated project?
Have you got some nx commands I can run to get something pulled together?
It's creating itself now
need to install @nrwl/storybook i think
i forgot the steps
here is my package.json deps:
ehh discord doesnt like it
and i dont have nitro
So NX says you shouldn't need tailwind in a library but it you want the components in your library to use tailwind classes it needs to be in there
Do you have a postcss.config.js file in your lib root?
I think I know why it wouldn't let you add tailwind to the library... It wants your library to be buildable or publishable
Where as for Storybook you typically want to have tailwind rebuild on change so you can see the changes without needing to rebuild the library and relaunch storybook
it has to be in root not in .storybook?
ok
Okay... so this is clearly a little bit trickier to fiddle with... I might need to work with the NX team on this one