Storybook Addon Themes
Greatly inspired by @storybook/addon-backgrounds.
This Storybook Theme Decorator can be used to add a custom HTML class or classes to the the preview in Storybook.
Compatibility
This version is compatible with storybook version 5.x.x
.
Installation
npm i -D storybook-addon-themes
Getting started
Then, configure it as an addon by adding it to your addons.js
file (located in the Storybook config directory):
;
Configuration
Configure the themes in your stories like this:
; // <- or your storybook framework ;
Or globally in the config.js
file:
; // <- or your storybook framework ;
And if you want to override themes for a single story or group of stories, pass the themes
parameter:
; ;
If you don't want to use themes for a story, you can set the themes
parameter to []
, or use { disable: true }
to skip the addon:
; ; ;
Also you can add multiple classes by passing an array in class
parameter:
; ;
Usage with decorator
By default the classes will be added to the body
element.
But in this case your theme will not be visible by other addons (like @storybook/addon-storyshots).
To fix this you can add the withThemes
decorator in your stories:
; // <- or your storybook framework; ;
Or setup the decorator globally in the config.js
file (located in the Storybook config directory):
; // <- or your storybook framework; ;
Framework Support Table
React | React Native | Vue | Angular | Polymer | Mithril | HTML | Marko | Svelte | Riot | Ember | Preact | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Usage without decorator | + | + | + | + | + | + | + | + | + | + | + | |
Usage with decorator | + |