Skip to content

feat(getValueDoppelganger): Ignore css property values with var() #62

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

Merged
merged 4 commits into from
Nov 13, 2021

Conversation

ling1726
Copy link
Contributor

@ling1726 ling1726 commented Nov 11, 2021

What:

Fixes #61 which illustrates a concrete example of the problem

Since the original issue is only with boxShadow or textShadow I'm
open to any suggestions that move the containsCssVar check only for
that property value converter.

How:

Created an extra containsCssVar regex match and used it with the existing checks
for boolean and undefined property values. Extracted the check to a separate utility
to avoid too much complexity in the function.

I was initially worried about some edge cases:

  • translateX(var())
  • padding: '2px var(--foo)';

but after testing, it seems that the results are the same before and after the changes in this PR.

Checklist:

  • Documentation
  • Tests
  • Ready to be merged
  • Added myself to contributors table

Fixes #

Since css variables can be more or less anything, added an extra utility
function to match for the presence of `var()` in the css property value,
since there's really no way to know how to actually compute the RTL
doppelganger.

I was initially worried that `translateX(var())` might be an edge case
that needs to be handled, but after testing, the result is currently the
same since the regexp will never match with the `var()` being used
inside the `translateX` call.

Since the original issue is only with `boxShadow` or `textShadow` I'm
open to any suggestions that move the `containsCssVar` check only for
that property value converter.
@@ -431,6 +431,12 @@ const unchanged = [
[{opacity: () => {}}],
[{objectPosition: 'center bottom'}],
[{objectPosition: '5px 10px'}], // There's no RTL-flipped equivalent for the 5px. :-(
[{boxShadow: 'var(--shadow16)'}],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the exception of boxShadow the below tests were all passing before and after the changes in this PR

@kentcdodds
Copy link
Owner

Thanks for this! I hadn't thought about css variables. I wonder if it would ever make sense for someone to have two different variables assigned and hope that they would get swapped for them: var(--padding-left-lg) -> var(--padding-right-lg)

Do you think there'd be a way to support this?

@ling1726
Copy link
Contributor Author

ling1726 commented Nov 11, 2021

Thanks for this! I hadn't thought about css variables. I wonder if it would ever make sense for someone to have two different variables assigned and hope that they would get swapped for them: var(--padding-left-lg) -> var(--padding-right-lg)

Do you think there'd be a way to support this?

In the scope of a library that does transforms, that seems to me like some shaky logic. Wouldn't it just be string replacing any variable we see with right-> left and vice versa ? which might (or might not) be what the users would want

There might also be other libraries that follow start -> end convention (or other conventions) respectively

Perhaps I'm misunderstanding you, an example might help in that case

@kentcdodds
Copy link
Owner

Nah, you're right. That would not be advisable to rely on. Let's go with this as a bug fix 👍

@codecov
Copy link

codecov bot commented Nov 13, 2021

Codecov Report

Merging #62 (cbae506) into main (76be258) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main       #62   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines          220       225    +5     
  Branches        41        43    +2     
=========================================
+ Hits           220       225    +5     
Impacted Files Coverage Δ
src/internal/convert.js 100.00% <100.00%> (ø)
src/internal/utils.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 76be258...cbae506. Read the comment docs.

Copy link
Owner

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kentcdodds kentcdodds merged commit 66582a7 into kentcdodds:main Nov 13, 2021
@ling1726
Copy link
Contributor Author

@kentcdodds thx for merging, just wondering when this would be released?

Also did I add myself to contributors correctly?

@kentcdodds
Copy link
Owner

@all-contributors please add @ling1726 for code and tests

@allcontributors
Copy link
Contributor

@kentcdodds

I've put up a pull request to add @ling1726! 🎉

@kentcdodds
Copy link
Owner

Sorry about that. I'm not sure why a release didn't go out and I forgot to fix the contributor thing. I use a bot so you don't have to add yourself manually :)

@ling1726
Copy link
Contributor Author

Thx! Couldn't ask for more for a first time oss contribution

kentcdodds added a commit that referenced this pull request Nov 13, 2021
There was an issue with a patch release, so this manual-releases.md
change is to release a new patch version.

Reference: #62
@kentcdodds
Copy link
Owner

We're having trouble with the release: https://github.com/kentcdodds/rtl-css-js/runs/4197260969?check_suite_focus=true#step:7:137

I'm not sure why this is happening 😬 I'll figure out how to get it fixed though.

kentcdodds added a commit that referenced this pull request Nov 13, 2021
There was an issue with a patch release, so this manual-releases.md
change is to release a new patch version.

Reference: #62
@kentcdodds
Copy link
Owner

Fixed and released!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

css vars being transformed incorrectly with textShadow converter
2 participants