#storybook, tailwindcss and storybook addon styling issue
1 messages Β· Page 1 of 1 (latest)
theme: {
extend: {
/* Backgrounds */
backgroundColor: {
button: "var(--bg-button)",
elevated: "var(--bg-elevated)",
main: "var(--bg-main)",
primary: "var(--bg-primary)",
"primary-action": "var(--bg-primary-action)",
"primary-action-hover": "var(--bg-primary-action-hover)",
quaternary: "var(--bg-quaternary)",
"react-select": "var(--bg-react-select)",
secondary: "var(--bg-secondary)",
"secondary-action": "var(--bg-secondary-action)",
tertiary: "var(--bg-tertiary)",
"tertiary-action": "var(--bg-tertiary-action)",
tag: "var(--tag-bg)",
},
...
}
}```
@layer base {
:root {
/* Backgrounds */
--bg-button: #fff;
--bg-elevated: #fff;
--bg-main: #fafafa;
--bg-primary: #fff;
--bg-primary-action: #171717;
--bg-primary-action-hover: #313131;
--bg-quaternary: #f0f0f0;
--bg-react-select: #fff;
--bg-secondary: #fafafa;
--bg-secondary-action: #e5e5e5;
--bg-tertiary: #f5f5f5;
--bg-tertiary-action: #fff;
--tag-bg: #f5f5f5;
}
...
}
this is in a seperate file called colors.css
and importing that file in globals.css:
@tailwind base;
@tailwind components;
@tailwind utilities;
@import "./fonts.css";
@import "./colors.css";```
importing this global file within preview.
Hey @fallow nimbus let's see what's going on here
What version of Storybook and @storybook/addon-styling are you using?
Also can you share your .storybook/main.js with me here?
module.exports = {
stories: ["../src/stories/**/*.stories.@(ts|tsx|js|jsx)"],
addons: [
"@storybook/addon-links",
"@storybook/addon-actions",
"@storybook/addon-essentials",
"@storybook/addon-styling",
{
name: "@storybook/addon-postcss",
options: {
postcssLoaderOptions: {
implementation: require("postcss"),
},
},
},
],
staticDirs: ["../public"],
framework: "@storybook/react",
core: {
builder: "@storybook/builder-webpack5",
},
typescript: {
check: true, // type-check stories during Storybook build
},
}
"@storybook/react": "^6.5.16",```
Ahhhh, so there's a potential problem! @storybook/[email protected] is for Storybook 7
If you're using SB 6.5 you should use version 0.3.2 of addon styling
would it be possible to upgrade to storybook 7?
what would the changes i have to do be?
We offer some codemods to make it fairly straightforward for you π
run npx storybook@latest upgrade
Also, what does your postcss.config.js file look like?
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
It looks like tailwind recommends using the postcss-import plugin if you have your tailwind files across multiple css files
https://tailwindcss.com/docs/adding-custom-styles#using-multiple-css-files
Best practices for adding your own custom styles to Tailwind.
what should i do about this?
Attention: We've detected that you're using the following addons in versions which are known ββ to be incompatible with Storybook 7: ββ ββ - @storybook/[email protected]
You can remove addon-postcss as it's deprecated and replaced by addon-styling π
It's okay! Seems scarier than it is β€οΈ
Did the upgrade command ask you about running some migration scripts?
got a file called font.css
which i am importing in globals.css
font-family: SuisseIntl;
font-weight: 100;
font-display: block;
font-style: normal;
src: url("/fonts/SuisseIntl-Thin.otf") format("otf");
}
@font-face {
font-family: SuisseIntl;
font-weight: 200;
font-display: block;
font-style: normal;
src: url("/fonts/SuisseIntl-Ultralight.otf") format("otf");
}
@font-face {
font-family: "SuisseIntl";
font-weight: 300;
font-display: block;
font-style: normal;
src: url("/fonts/SuisseIntl-Light.otf") format("otf");
}
@font-face {
font-family: "SuisseIntl";
font-weight: 400;
font-display: block;
font-style: normal;
src: url("/fonts/SuisseIntl-Regular.otf") format("otf");
}
@font-face {
font-family: "SuisseIntl";
font-weight: 500;
font-display: block;
font-style: normal;
src: url("/fonts/SuisseIntl-Medium.otf") format("otf");
}
@font-face {
font-family: "SuisseIntl";
font-weight: 600;
font-display: block;
font-style: normal;
src: url("/fonts/SuisseIntl-SemiBold.otf") format("otf");
}
@font-face {
font-family: "SuisseIntl";
font-weight: 700;
font-display: block;
font-style: normal;
src: url("/fonts/SuisseIntl-Bold.otf") format("otf");
}
@font-face {
font-family: "SuisseIntl";
font-weight: 900;
font-display: block;
font-style: normal;
src: url("/fonts/SuisseIntl-Black.otf") format("otf");
}
we had a call regarding this one remember?
importing globals.css in preview.
thanks again for all the help. i know you don't have to π means a lot!
I do remember! The font name was a give away
So two things!
format("otf"); needed to be format("opentype");
And we switched to relative imports for the font file paths π
ahaha stranger things have happened
got it.
this time leave yourself a note in the comments
is there a new way to write stories?
!! will do this. haha
thanks
huzzah! it's working now?
Well then we're getting better! last time it took us a few hours
export default {
title: "Atoms/Bar",
component: Bar,
} as ComponentMeta<typeof Bar> <------ HERE IS it's saying MISSING SEMICOLON
const Template: ComponentStory<typeof Bar> = (args) => <Bar {...args} />
export const Default = Template.bind({})```
is this still a valid way to write stories?
Right! so one of those auto-migration scripts is to add some eslint checks to storybook files. missing semicolons is still valid. I guess we were trying to recommend best practices
By the way I see that you're using the Component Story Format 2 (CSF2) format for your story files π
This is totally valid but if you want an even easier way to write your stories try out our new version CSF3
ye will use this
was never sure on what the best or most optimal way of writing these was π
hahah
I'll admit we haven't been the best at declaring best practices. We're going to work on changing that π