# storybook-theme-css-vars

> Theme switcher tool addon that changes the theme using CSS custom properties

Latest version **0.0.12** (published 2023-08-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install storybook-theme-css-vars
pnpm add storybook-theme-css-vars
yarn add storybook-theme-css-vars
bun add storybook-theme-css-vars
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.12 |
| Published | 2023-08-15 |
| First published | 2021-10-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 21.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | olejech |
| Maintainers | olejech |
| Keywords | storybook-addons, css, custom, properties, variables, vars, theme, dark |

## Links

- npm: https://www.npmjs.com/package/storybook-theme-css-vars
- Repository: https://github.com/olejech/storybook-theme-css-vars
- Homepage: https://github.com/olejech/storybook-theme-css-vars#readme
- Issues: https://github.com/olejech/storybook-theme-css-vars/issues
- npm.io page: https://npm.io/package/storybook-theme-css-vars

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 0.0.12 (latest) — 2023-08-15
- 0.0.9 — 2023-03-28
- 0.0.7 — 2023-03-28
- 0.0.6 — 2023-03-28
- 0.0.5 — 2022-07-31
- 0.0.4 — 2021-10-03
- 0.0.3 — 2021-10-03
- 0.0.2 — 2021-10-03
- 0.0.1 — 2021-10-03

## README

# Storybook Theme CSS Custom Properties

![Storybook theme css vars](storybook-theme-css-vars.gif?raw=true "Storybook addon theme css")

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:

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

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

## Installation

```bash
npm i -D storybook-theme-css-vars
```

Add the addon to `.storybook/main.js`:

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

Add parameters options to `.storybook/preview.js`:

```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.

---
_Source: https://npm.io/package/storybook-theme-css-vars · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
