Skip to content

Theme switcher tool addon that changes the theme using CSS custom properties (vars)

License

Notifications You must be signed in to change notification settings

davidloiret/storybook-theme-css-vars

 
 

Repository files navigation

Storybook Theme CSS Custom Properties

Storybook theme css vars

This addon can be used to set a data attribute in Storybook's iframe HTML element triggering a toggle between dark and light theme.

Example styles:

:root {
  --white: #fff;
  --black: #000;
}

:root [data-theme="dark"] {
  --white: #000;
  --black: #fff;
}

Installation

npm i -D storybook-theme-css-vars

Add the addon to .storybook/main.js:

module.exports = {
  addons: ["storybook-theme-css-vars"],
};

Add parameters options to .storybook/preview.js:

export const parameters = {
  theme: {
    selector: "body (or your selector with data attribute)",
    dataAttr: "data-theme (or your data attribute)",
  },
};

Usage

Click on the new theme toggle in the toolbar to toggle between dark and light mode.

About

Theme switcher tool addon that changes the theme using CSS custom properties (vars)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 57.2%
  • JavaScript 37.4%
  • CSS 5.4%