# postcss-themes

> PostCSS plugin to add themes in CSS file

Latest version **1.0.3** (published 2021-07-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install postcss-themes
pnpm add postcss-themes
yarn add postcss-themes
bun add postcss-themes
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2021-07-14 |
| First published | 2020-04-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 1 |
| Unpacked size | 8.2 KB |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | TonyXiang |
| Maintainers | xianglei |
| Keywords | postcss, css, postcss-plugin, theme |

## Links

- npm: https://www.npmjs.com/package/postcss-themes
- Repository: https://github.com/TonyXiang/postcss-themes
- Homepage: https://github.com/TonyXiang/postcss-themes#readme
- Issues: https://github.com/TonyXiang/postcss-themes/issues
- npm.io page: https://npm.io/package/postcss-themes

## Dependencies (1)

- [postcss](https://npm.io/package/postcss.md) ^7.0.18

## 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

- 1.0.3 (latest) — 2021-07-14
- 1.0.2 — 2021-07-14
- 1.0.1 — 2020-04-27
- 1.0.0 — 2020-04-20
- 0.0.1-0 — 2020-04-16

## README

# PostCSS Themes

[PostCSS] plugin to add themes in CSS file.

[PostCSS]: https://github.com/postcss/postcss

[![Build Status](https://travis-ci.com/TonyXiang/postcss-themes.svg?branch=master)](https://travis-ci.com/TonyXiang/postcss-themes)

Note about at-rules:
Except for [Conditional Group At-rules](https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule#conditional_group_rules), others will simply be ignored because of irrelevance. `@keyframes` may contain css varialbe, but it's not feasible to deduce their scope values at build time.

## Usage

```bash
npm install postcss-themes -D
```

```javascript
module.exports = {
  plugins: [
    'postcss-themes': {
      themes: {
        filePath: 'theme-aaa.css',
      }
    },
  ]
}
```

If you do not use PostCSS, add it according to [official docs]
and set this plugin in settings.

[official docs]: https://github.com/postcss/postcss#usage

### Input CSS
```css
:root {
  --main-color: green;
}
.foo {
  font-size: 16px;
  color: var(--main-color);
}
```

### theme-aaa.css
```css
:root {
  --main-color: red;
}
```

### Output CSS
```css
:root {
  --main-color: green;
}
.foo {
  font-size: 16px;
  color: var(--main-color);
}
.theme-aaa {
  --main-color: red;
}
.theme-aaa .foo {
  color: var(--main-color);
}
```

### Change Theme
```javascript
document.body.className = document.body.className + ' theme-aaa'
```

### Work With Other Postcss Plugins
```javascript
module.exports = {
  plugins: [
    'postcss-themes': {
      themes: {
        filePath: 'theme-aaa.css',
      }
    },
    'postcss-css-variables': {},
    'postcss-preset-env': {
      ...
    }
  ]
}
```

### Attribute
| attribute | intro | type | default |
| --- | --- | --- |  --- |
| themes | themes data | `ThemeObject`\|Array\<`ThemeObject`\> | - |

### ThemeObject
| attribute | intro | type | default |
| --- | --- | --- |  --- |
| className | the theme className. | string | - |
| filePath | The path of CSS file that define CSS variables; The fileName will be the theme `className` by default if `className` is not defined. | string | - |
| variables | CSS variables; The CSS variables in CSS files will bo ignored If the same CSS variables are defined not only in `variables` but also in the CSS file that `filePath` linked to. | object | - |

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