0.2.0 • Published 2 years ago

postcss-custom-themes v0.2.0

Weekly downloads
18
License
MIT
Repository
github
Last release
2 years ago

postcss-custom-themes

Generate theme specific classes, substituting initial css variables for the theme ones. Creates a global theme-{themeName} class that is prepended to every class that has css variables. Must be inserted before postcss-custom-properties.

Install

npm install -D postcss-custom-themes

Usage

// postcss.config.js

module.exports = {
  plugins: [
    require('postcss-custom-themes')({
      themes: ['dark'],
      importFrom: 'css/colors.css',
      modules: false,
    }),
    require('postcss-custom-properties')({
      preserve: true,
      importFrom: 'css/colors.css',
    })
  ]
}

Options

NameTypeRequiredDescription
themesArraytrueArray of theme prefixes
importFromStringtrueFile with css variables. Needed for substitution checks
modulesBooleanfalse default: falseIf you use CSSModules, set it to true in order to apply the theme class globally (wraps the theme class in :global selector).

Input CSS

:root {
  --theme-dark-mainColor: #000;
  --theme-dark-additionalColor: #fff;
}

:root {
  --mainColor: #fff;
  --additionalColor: #000;
}
.root {
  display: block;
  background: var(--mainColor);
  color: var(--additionalColor);
}

Output CSS

.theme-dark .root {
  background: #000;
  color: #fff;
}
.root {
  display: block;
  background: #fff;
  color: #000;
}