0.0.4 • Published 1 year ago
postcss-when v0.0.4
postcss-when
PostCSS plugin that implements CSS conditions @when.
From a proposal of Martin Auswöger: https://discourse.wicg.io/t/css-conditions-with-variables/2048.
@when = @when ( <condition> ) { <declaration-list> }
<condition> = <var()-function> <operator> <declaration-value>
<operator> = '=' | '<' | '<=' | '>' | '>=' | '!='
.foo {
visibility: hidden;
@when (var(--foo-visible) = 1) {
visibility: visible;
}
}
.foo {
visibility: hidden;
animation: 1s when-animation-1 paused;
animation-delay: calc((1 - var(--selected-tab)) * 1s);
}
@keyframes when-animation-1 {
from { visibility: visible}
}
Usage
Step 1: Install plugin:
npm install --save-dev postcss postcss-when
Step 2: Check you project for existed PostCSS config: postcss.config.js
in the project root, "postcss"
section in package.json
or postcss
in bundle config.
If you do not use PostCSS, add it according to official docs and set this plugin in settings.
Step 3: Add the plugin to plugins list:
module.exports = {
plugins: [
+ require('postcss-when'),
require('autoprefixer')
]
}