-
-
Notifications
You must be signed in to change notification settings - Fork 75
postcss-logical : use variables #91
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
postcss-logical : use variables #91
Conversation
I tried to implement this strategy in some-element {
--radius: 4px;
border-start-start-radius: var(--radius);
} produces [dir="ltr"] {
--top-left-radius: var(--radius);
--top-right-radius: ;
}
[dir="rtl"] {
--top-left-radius: ;
--top-right-radius: var(--radius);
}
some-element {
--radius: 4px;
border-top-left-radius: var(--top-left-radius);
border-top-right-radius: var(--top-right-radius);
} That doesn't work unless Unfortunately, I haven't found a workaround yet... 😞 |
Ok, found an alternative approach: parcel-bundler/lightningcss#30 (comment) |
@devongovett Thank you for posting this here! |
…bles--persistent-common-buzzard-b4cb687e85
…bles--persistent-common-buzzard-b4cb687e85
FYI, discovered another problem with this approach. .foo {
border-radius: 20px;
}
.foo {
border-start-start-radius: 0;
} transforms to: .foo {
border-radius: 20px;
}
.foo {
border-top-left-radius: var(--ltr, 0);
border-top-right-radius: var(--rtl, 0);
}
[dir="ltr"] {
--ltr: initial;
--rtl: ;
}
[dir="rtl"] {
--ltr: ;
--rtl: initial;
} The problem is that, for example in ltr, I'm thinking of changing Parcel CSS to use the Using the |
@devongovett Thank you for this! I always appreciate it so much when you come back here and share your learnings!
This is where I gave up my last attempt. I hope to pick this up again when I have time to take a deep dive. I do wonder if maybe it's best to fallback everything to one base direction. Maybe configurable which fallback is created? |
Yeah. My current idea is something like this: .foo:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
/* ltr */
border-top-left-radius: 0;
}
.foo:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
/* rtl */
border-top-right-radius: 0;
} This way, if no |
That looks nice, and compression will make the overhead largely go away as it's always the same. https://developer.mozilla.org/en-US/docs/Web/CSS/:lang#browser_compatibility Didn't know that support for |
Side note : I should send a patch to fix the specificity display in VSCode. |
yeah that seems weird. but it got me thinking. Pseudo elements including .foo {
border-radius: 20px;
}
.foo {
border-start-start-radius: 0;
}
.foo {
border-radius: 50px;
} It could be possible to fix that using the |
We can raise the specificity of everything else by It's messy but it works. I initially started this PR to fix specificity issues with |
Ha, nice hack! |
Hello, any updates here? I have the same problem with selectors specifity. |
Hi all, |
Hi @SalimBensiali Thank you for suggesting this! |
To everyone following along here, I am closing this pull request because I will not continue working on this issue within the same approach to solve it. If you want to be notified of updates related to this issue it is best to subscribe to this issue : #90 |
related issues :
The current implementation of
postcss-logical
modifies the selector by adding:dir(lrt|rtl)
.This changes specificity and doesn't work for
@keyframes
.It also breaks down in code that uses multiple
dir
values in a single documentI think that using CSS Variables would resolve most of these issues.
The tradeoff is that we can't have both
ltr
andrtl
in a single document in older browsers that do not support CSS Variables.https://caniuse.com/css-variables
Browsers that do not support variables would fallback to
ltr
.The variable name used in the example below is a shortened md5 hash of the current "tree", combined with a simple incrementing counter.
This gives a unique variable name that is still consistent between multiple builds from the same source.
This change does not effect CSS output when the
dir
plugin option is provided.Input CSS :
Before this change :
After this change :
Any thoughts on this?