-
Notifications
You must be signed in to change notification settings - Fork 61
Nesting edge case: custom variable is not getting replaced #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Where is It seems to work fine in my testing below: Input: :root {
--TRANSLUCENT-HOVER-BG: blue;
--ON-IMAGE: red;
}
.translucentHoverBG {
&:hover,
&:focus {
background: var(--TRANSLUCENT-HOVER-BG);
span,
i {
color: var(--ON-IMAGE);
}
}
} After :root {
--TRANSLUCENT-HOVER-BG: blue;
--ON-IMAGE: red;
}
.translucentHoverBG:hover, .translucentHoverBG:focus {
background: var(--TRANSLUCENT-HOVER-BG)
}
.translucentHoverBG:hover span, .translucentHoverBG:hover i, .translucentHoverBG:focus span, .translucentHoverBG:focus i {
color: var(--ON-IMAGE);
} After .translucentHoverBG:hover {
background: blue
}
.translucentHoverBG:focus {
background: blue
}
.translucentHoverBG:hover span {
color: red;
}
.translucentHoverBG:hover i {
color: red;
}
.translucentHoverBG:focus span {
color: red;
}
.translucentHoverBG:focus i {
color: red;
} |
Thanks for the quick reply @MadLittleMods. |
Please provide the exact input before it's passed to |
I am using postcss-loader in webpack for postcss. Here is my config. const path = require('path');
const { parseFilesSync } = require('./tools/css-variables-parser');
const variables = parseFilesSync([
path.resolve(__dirname, 'node_modules', 'tailwindcss', 'dist', 'base.css'),
path.resolve(__dirname, 'node_modules', 'tailwindcss', 'dist', 'utilities.css'),
path.resolve(__dirname, 'src', 'styles', 'themes', '_default.css'),
path.resolve(__dirname, 'src', 'styles', 'themes', '_tv.css'),
path.resolve(__dirname, 'src', 'styles', '_custom-variables-default.css'),
path.resolve(__dirname, 'src', 'styles', '_custom-variables-tv.css')
]);
let plugins = [
require('postcss-prepend-imports')({
path: path.resolve(__dirname, 'src', 'styles'),
files: ['_custom-variables-overrides.css']
}),
require('postcss-import')({
root: path.resolve(__dirname, 'src'),
plugins: [require('stylelint')]
}),
require('postcss-reporter')({
clearReportedMessages: true,
throwError: true
}),
require('postcss-aspect-ratio-polyfill'),
require('postcss-nested'),
require('postcss-sassy-mixins'),
require('tailwindcss'),
require('postcss-extend-rule'),
/*
* Note:
* rtlcss plugin generates separate css files for rtl styles.
* But we need to figure out a way of dynamically consuming the css files based on the dir attribute inside storybook as well as consumer applications.
* Hence using postcss-rtlcss for now.
*/
require('postcss-rtlcss'),
require('postcss-css-variables')({ variables, preserveInjectedVariables: false }),
require('cssnano')({
preset: 'default'
}),
require('autoprefixer')
];
plugins = plugins.filter((plugin) => !!plugin);
module.exports = {
plugins
}; Input css
.translucentHoverBG {
&:hover,
&:focus {
background: var(--TRANSLUCENT-HOVER-BG);
span,
i {
@apply ON_IMAGE;
}
}
} ON_IMAGE class refers to => color: var(--ON-IMAGE) as defined in tailwind config. CSS passed to postcss-css-variables plugin .translucentHoverBG:hover,
.translucentHoverBG:focus {
background: var(--TRANSLUCENT-HOVER-BG);
}
.translucentHoverBG:hover span, .translucentHoverBG:hover i, .translucentHoverBG:focus span, .translucentHoverBG:focus i {
color: var(--ON-IMAGE);
} |
@ajayjaggi97 Testing the "CSS passed to postcss-css-variables plugin" works just fine in the playground, https://madlittlemods.github.io/postcss-css-variables/playground/ :root {
--TRANSLUCENT-HOVER-BG: blue;
--ON-IMAGE: red;
}
.translucentHoverBG:hover,
.translucentHoverBG:focus {
background: var(--TRANSLUCENT-HOVER-BG);
}
.translucentHoverBG:hover span, .translucentHoverBG:hover i, .translucentHoverBG:focus span, .translucentHoverBG:focus i {
color: var(--ON-IMAGE);
} In your config, what does |
@MadLittleMods i logged the variables, among other key value pairs there exists these ones.
Also if i remove background: var(--TRANSLUCENT-HOVER-BG) from my input css or separate out the nested code, everything works fine.. |
hey @MadLittleMods. |
@ajayjaggi97 It looks like it might be |
Specific case is :root {
--processed: #FFF;
--unprocessed: #FFF;
}
.first, .second {
background: var(--processed);
.third, .four {
color: var(--unprocessed);
}
} |
See this too with comma separated selectors. |
Uh oh!
There was an error while loading. Please reload this page.
My postcss pipeline includes "postcss-nested" plugin before "postcss-css-variables" plugin.
You can see that in the output, var(--ON-IMAGE) is not replaced.
Input CSS
Output CSS
The text was updated successfully, but these errors were encountered: