storybook-addon-styled-component-theme icon indicating copy to clipboard operation
storybook-addon-styled-component-theme copied to clipboard

Support for Storybook v7

Open kirandash opened this issue 1 year ago • 2 comments

In storybook v7, addDecorator has been removed.

kirandash avatar Apr 10 '23 10:04 kirandash

For anyone hitting this issue, I tried the new way of adding decorators as described here but its throwing errors so this library does not work with storybook 7 yet.

As alternative, you could look into this styled components recipe on storybook documentation, where they use @storybook/addon-styling to add a styled components theme:

Add a decorator to stories in .storybook/preview.js

import { Preview } from '@storybook/react';
import { withThemeFromJSXProvider } from '@storybook/addon-styling';
import { createGlobalStyle, ThemeProvider } from 'styled-components';

import { theme1, theme2 } from './themes';


const GlobalStyles = createGlobalStyle`
  // some global style if needed
`;

const preview: Preview = {
  decorators: [
    withThemeFromJSXProvider({
      themes: {
        theme1,
        theme2,
      },
      defaultTheme: 'theme1',
      Provider: ThemeProvider,
      GlobalStyles,
    }),
  ],
};

export default preview;

Add to .storybook/main.js

module.exports = {
  ...
  addons: [
    ...
    "@storybook/addon-styling"
  ]
};

VincentVW avatar Jun 02 '23 13:06 VincentVW

For anyone hitting this issue, I tried the new way of adding decorators as described here but its throwing errors so this library does not work with storybook 7 yet.

As alternative, you could look into this styled components recipe on storybook documentation, where they use @storybook/addon-styling to add a styled components theme:

Add a decorator to stories in .storybook/preview.js

import { Preview } from '@storybook/react';
import { withThemeFromJSXProvider } from '@storybook/addon-styling';
import { createGlobalStyle, ThemeProvider } from 'styled-components';

import { theme1, theme2 } from './themes';


const GlobalStyles = createGlobalStyle`
  // some global style if needed
`;

const preview: Preview = {
  decorators: [
    withThemeFromJSXProvider({
      themes: {
        theme1,
        theme2,
      },
      defaultTheme: 'theme1',
      Provider: ThemeProvider,
      GlobalStyles,
    }),
  ],
};

export default preview;

Add to .storybook/main.js

module.exports = {
  ...
  addons: [
    ...
    "@storybook/addon-styling"
  ]
};

That is awesome, thanks Vincent you saved my day!

arange avatar Jun 08 '23 12:06 arange