Back to Storybook

Themes

docs/essentials/themes.mdx

10.3.61.4 KB
Original Source

Storybook's Themes addon allows you to switch between multiple themes for your components inside of the preview in Storybook.

Theme decorators

To make your themes accessible to your stories, @storybook/addon-themes exposes three decorators for different methods of theming.

JSX providers

For libraries that expose themes to components through providers, such as Material UI, Styled-components, and Emotion, use the withThemeFromJSXProvider.

<CodeSnippets path="storybook-addon-themes-jsx-provider-decorator.md" />

CSS classes

For libraries that rely on CSS classes on a parent element to determine the theme, you can use the withThemeByClassName decorator.

<CodeSnippets path="storybook-addon-themes-classname-decorator.md" />

Data attributes

For libraries that rely on data attributes on a parent element to determine the theme, you can use the withThemeByDataAttribute decorator.

<CodeSnippets path="storybook-addon-themes-data-attribute-decorator.md" />