#storybook, tailwindcss and storybook addon styling issue

1 messages Β· Page 1 of 1 (latest)

fallow nimbus
#

currently having an issue with storybook and tailwind where its not loading the correct colors.

#
  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;
    }
  ...
}
fallow nimbus
#

and importing that file in globals.css:

@tailwind base;
@tailwind components;
@tailwind utilities;

@import "./fonts.css";
@import "./colors.css";```
fallow nimbus
fallen yarrow
#

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?

fallow nimbus
#
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
  },
}
fallow nimbus
fallen yarrow
#

If you're using SB 6.5 you should use version 0.3.2 of addon styling

fallow nimbus
#

what would the changes i have to do be?

fallen yarrow
#

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?

fallow nimbus
#
module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}
fallen yarrow
fallow nimbus
fallen yarrow
#

You can remove addon-postcss as it's deprecated and replaced by addon-styling πŸ™‚

fallow nimbus
#

seems to me upgrading broke a lot of things 😦

fallen yarrow
#

It's okay! Seems scarier than it is ❀️

#

Did the upgrade command ask you about running some migration scripts?

fallow nimbus
#

yep

#

did all those

fallen yarrow
#

okay cool πŸ™‚

#

Where are you importing those SuisseIntl-Thin.otf files?

fallow nimbus
#

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.

fallow nimbus
fallen yarrow
#

I do remember! The font name was a give away

fallow nimbus
#

haha

#

πŸ™‚

fallen yarrow
#

So two things!

format("otf"); needed to be format("opentype");

#

And we switched to relative imports for the font file paths πŸ™‚

fallow nimbus
#

!!! why did it switch this

#

omg

fallen yarrow
#

ahaha stranger things have happened

fallow nimbus
#

got it.

fallen yarrow
#

this time leave yourself a note in the comments

fallow nimbus
#

is there a new way to write stories?

fallow nimbus
#

thanks

fallen yarrow
#

huzzah! it's working now?

fallow nimbus
#

ye font issues gone

#

a weird semicolon issue now tho

fallen yarrow
#

Well then we're getting better! last time it took us a few hours

fallow nimbus
#
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?

fallen yarrow
#

huh... it should be πŸ€”

#

Is it maybe an eslint based error?

fallow nimbus
#

yes but saying within storybook preview

#

like displayign the error there

fallen yarrow
#

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

fallow nimbus
#

was never sure on what the best or most optimal way of writing these was πŸ™‚

#

hahah

fallen yarrow
#

I'll admit we haven't been the best at declaring best practices. We're going to work on changing that πŸ™‚