1 | [](https://badge.fury.io/js/storybook-addon-styled-component-theme)
|
2 | [](https://travis-ci.org/echoulen/storybook-addon-styled-component-theme)
|
3 | [](https://codecov.io/gh/echoulen/storybook-addon-styled-component-theme)
|
4 |
|
5 | 
|
6 |
|
7 | This addon allows storybook to showcase components with multiple different styled-component themes.
|
8 | Supports storybook v4, v5, v6 and newer
|
9 |
|
10 | ## Installation
|
11 |
|
12 | ```bash
|
13 | yarn add storybook-addon-styled-component-theme --dev
|
14 | ```
|
15 |
|
16 | # Configuration
|
17 |
|
18 | ## storybook v6
|
19 |
|
20 | #### Add a decorator to stories in .storybook/preview.js
|
21 |
|
22 | ```javascript
|
23 |
|
24 | import { addDecorator } from "@storybook/react";
|
25 | import { withThemesProvider } from "storybook-addon-styled-component-theme";
|
26 | import { ThemeProvider } from "styled-components";
|
27 |
|
28 | const themes = [theme1, theme2];
|
29 | addDecorator(withThemesProvider(themes), ThemeProvider);
|
30 | ```
|
31 |
|
32 | #### Add to .storybook/main.js
|
33 |
|
34 | ```
|
35 | module.exports = {
|
36 | ...
|
37 | addons: [
|
38 | ...
|
39 | "storybook-addon-styled-component-theme/dist/preset"
|
40 | ]
|
41 | };
|
42 | ```
|
43 |
|
44 | ## storybook v5 and v4
|
45 |
|
46 | #### Add to .storybook/addons.js
|
47 |
|
48 | ```javascript
|
49 | // v1.3, storybook v5.2
|
50 | import "storybook-addon-styled-component-theme/dist/register";
|
51 |
|
52 | // v1.2, storybook v4, v5.0
|
53 | import "storybook-addon-styled-component-theme/dist/src/register";
|
54 | ```
|
55 |
|
56 | #### addDecorator to .storybook/preview.js
|
57 |
|
58 | ```javascript
|
59 | import { addDecorator } from "@storybook/react";
|
60 | import { withThemesProvider } from "storybook-addon-styled-component-theme";
|
61 |
|
62 | const themes = [theme1, theme2];
|
63 | addDecorator(withThemesProvider(themes));
|
64 | ```
|
65 |
|
66 | #### Remind
|
67 |
|
68 | Make sure every theme object has a `name` property
|
69 |
|
70 | ## Contributing
|
71 |
|
72 | ##### Build local library
|
73 |
|
74 | ```shell
|
75 | yarn
|
76 |
|
77 | yarn build
|
78 | ```
|
79 |
|
80 | ##### Start the local example
|
81 |
|
82 | ```shell
|
83 | cd example
|
84 |
|
85 | yarn
|
86 |
|
87 | yarn storybook
|
88 | ```
|
89 |
|
90 | #### Run all the spec
|
91 |
|
92 | ```shell
|
93 | yarn test
|
94 | ```
|