storybook-theme-css-vars
TypeScript icon, indicating that this package has built-in type declarations

0.0.12 • Public • Published

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)",
    nameLightTheme: "light (or your name of light theme)",
    nameDarkTheme: "dark (or your name of dark theme)",
  },
};
  • nameLightTheme (optional, default — "light")
  • nameDarkTheme: (optional, default — "dark")

Usage

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

Package Sidebar

Install

npm i storybook-theme-css-vars

Weekly Downloads

272

Version

0.0.12

License

MIT

Unpacked Size

22.3 kB

Total Files

35

Last publish

Collaborators

  • olejech