Storybook Addon Styled Component Theme screenshot

Storybook Addon Styled Component Theme

Author Avatar Theme by Echoulen
Updated: 25 Feb 2022
192 Stars

storybook addon

Categories

Overview:

The styled-components-addon is an npm addon that enables Storybook to showcase components with multiple different styled-component themes. It supports Storybook versions 4, 5, 6, and newer.

Features:

  • Multiple styled-component themes support
  • Compatible with Storybook versions 4, 5, 6, and newer

Installation:

To install the styled-components-addon, follow these steps:

Storybook v6:

  1. Add the following code snippet to .storybook/preview.js:

    import { addDecorator } from '@storybook/react';
    import { withThemesProvider } from 'styled-components-addon';
    
    // Add your theme objects here
    const themes = [...];
    
    addDecorator(withThemesProvider(themes));
    
  2. Add the following code snippet to .storybook/main.js:

    module.exports = {
      addons: [
        {
          name: 'styled-components-addon',
          options: {
            themeNameSelector: '.theme-selector',
          },
        },
      ],
    };
    

Storybook v5 and v4:

  1. Add the following code snippet to .storybook/addons.js:

    import 'styled-components-addon/register';
    
  2. Add the following code snippet to .storybook/preview.js:

    import { addDecorator } from '@storybook/react';
    import { withThemesProvider } from 'styled-components-addon';
    
    // Add your theme objects here
    const themes = [...];
    
    addDecorator(withThemesProvider(themes));
    

Summary:

The styled-components-addon is a helpful npm package that integrates styled-components themes with Storybook. It provides support for showcasing components with multiple different themes and is compatible with Storybook versions 4, 5, 6, and newer. The installation process involves adding code snippets to the Storybook configuration files.