-
-
Notifications
You must be signed in to change notification settings - Fork 79k
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
Add a cssvar()
function
#36597
base: main
Are you sure you want to change the base?
Add a cssvar()
function
#36597
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a function to check for null values in Sass variables really solves the issue #36595. Now scss don’t produces broken css with missing values
We are only adressing here
Don't we want to wait for using this mixin everywhere? If it is applied everywhere, it'll have an impact on the documentation where we need to define if it remains understandable for the users. It becomes a little bit less obvious with Rather than using a mixin, can't we rather drop the empty CSS vars after/during the generation of the CSS file? |
That'd be awesome, @julien-deramond, and would keep things less abstracted. I haven't looked into a linter for this yet, let me know if you have one in mind :). |
I don't see options in our existing tooling I think, but I did find https://www.npmjs.com/package/postcss-dropunusedvars. |
I don't see neither options in our existing tooling. Let's try https://www.npmjs.com/package/postcss-dropunusedvars!. |
First basic test with https://www.npmjs.com/package/postcss-dropunusedvars. diff --git a/scss/_accordion.scss b/scss/_accordion.scss
index b306540d7..35576ad76 100644
--- a/scss/_accordion.scss
+++ b/scss/_accordion.scss
@@ -3,6 +3,9 @@
//
.accordion {
+ --test-component-unused-var: 10px;
+ --test-component-empty-var: ;
+
// scss-docs-start accordion-css-vars
--#{$prefix}accordion-color: #{color-contrast($accordion-bg)};
--#{$prefix}accordion-bg: #{$accordion-bg};
@@ -35,6 +38,7 @@
align-items: center;
width: 100%;
padding: var(--#{$prefix}accordion-btn-padding-y) var(--#{$prefix}accordion-btn-padding-x);
+ font-size: var(--test-component-empty-var);
@include font-size($font-size-base);
color: var(--#{$prefix}accordion-btn-color);
text-align: left; // Reset button style Without the plugin both variables stay in dist/bootstrap.css. Install the plugin with diff --git a/build/postcss.config.js b/build/postcss.config.js
index 7f8186d10..5b780fe35 100644
--- a/build/postcss.config.js
+++ b/build/postcss.config.js
@@ -10,6 +10,7 @@ module.exports = context => {
return {
map: context.file.dirname.includes('examples') ? false : mapConfig,
plugins: {
+ "postcss-dropunusedvars": {},
autoprefixer: {
cascade: false
}, With the plugin Haven't looked at if |
@@ -1,3 +1,9 @@ | |||
@mixin cssvar($name, $value) { | |||
@if $value != null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's invalid because css var can be null
too, it's can be useful to reset var, better solution:
@mixin cssvar($name, $value: false) {
@if $value != false {
@if $value == null {
$value: initial;
}
--#{$prefix}#{$name}: #{$value};
}
}
Potentially addresses #36595 by implementing a new
cssvar()
function that checks fornull
values in Sass variables.