How to support multi-theme
Last updated
Storybook set-up
There are many ways of setting up themes/brands inside Storybook, we recommend these two:
-
Use @storybook/addon-themes, requires 7.0+ Storybook.
-
Use Storybook globals. Please refer to how to add a theme switcher to Storybook for more details. You can, for example, create a Storybook global called
themewith possible values equal tobrandA,brandBorbrandC.
Loading different themes
From there, you can import your different brands in 3 ways:
- Generate a variant property for all your components.
- Generate multiple components, one with each brand selected.
- Generate multiple Figma files with all components of a brand in a file.
The method for generating your components will depend on your workflow and organization. Here are the details for each method:
Generate a variant property theme
This is done while importing each component.
Select the theme global as described in Storybook’s globals page.
The resulted components will have an extra variant property with the list of themes and all variants for each theme will be generated.
Generate multiple components
Add the theme global as a property, select at least two themes, and set Layout in Figma canvas to As multiple
components (or "axis": "split" in JSON mode, see How to split components): one import
creates one component per theme.
You can then organize them in folders appropriately.
Generate multiple Figma files
This is done by importing all components multiple time into different files.
You can enforce the file’s theme by setting the theme in the Import defaults for this file.
We are working on features to simplify the management of multiple files.