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:
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));Add the following code snippet to .storybook/main.js:
module.exports = { addons: [ { name: 'styled-components-addon', options: { themeNameSelector: '.theme-selector', }, }, ], };
Storybook v5 and v4:
Add the following code snippet to .storybook/addons.js:
import 'styled-components-addon/register';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.