Skip to content
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

Issues with css values with () #13

Open
wedelgaard opened this issue Jun 22, 2017 · 6 comments
Open

Issues with css values with () #13

wedelgaard opened this issue Jun 22, 2017 · 6 comments

Comments

@wedelgaard
Copy link

First of all, awesome little plugin! I've noticed that passing spring start and target values with () seems to break the code. At least thats my assumption.

Uncaught TypeError: Cannot convert undefined or null to object : css-spring.js:647

Lets say I want to translateX(50px), this won't work. I know I could use the "formatter" to fix this issue, but it would be awesome to just have start and target to be plain style objects.

@codepunkt
Copy link
Owner

codepunkt commented Jun 22, 2017

@wedelgaard thanks!

I agree, being able to simply use translateX(50px) in start or end styles would be great. For the time being, i recommend using a custom formatter to animate transforms.

Apart from that, i see two ways to resolve this without having to resort to formatters:

  1. Hand-coding support for transforms, or specifically, translate or translateX. Might even be more generic by targeting css values that consist of interpolatable values in between parentheses. This would be possible with the current code-base, but it would lead to a larger footprint of the library and quite possibly, harder to understand code
  2. Changing the whole project to use a css parser on both start and end styles, built abstract syntax trees for both, identify matching interpolatable values and interpolate based on those. That's a whole different can of worms and i have to admit that i don't have the best understanding of ASTs or css parsers, in general. I'm not even sure if CSS parsers exist that split property values into their integral parts.

Help and pull requests are always welcome!

@wedelgaard
Copy link
Author

I'ved found out its actually the regex in line 439 that seems to be the problem:

var regex = /^([+-]?(?:\d+|\d*.\d+))([a-z]*|%)$/

This regex won't catch "translate(50px)"

I'll try to look into it if I get the time :)

@codepunkt
Copy link
Owner

Started playing around with a css parser based version in next branch.

@wedelgaard
Copy link
Author

@codepunkt uh nice will look forward to it ;)

@jjenzz
Copy link

jjenzz commented Apr 19, 2021

Is this project still maintained? I notice the last updates were several years back now but I'd love to play with this and I've been struggling to get transforms working using the object syntax. The example in the repo doesn't appear to work either:

https://codesandbox.io/s/affectionate-villani-y30kz?file=/src/index.js:680-712

Cannot use 'in' operator to search for '0' in transform: translateX(100px);

I can't use the formatter from toString because I need an object representation of the keyframes to pass to a CSS-in-JS library.

Thought I'd post in case it was a simple fix 🙂

@codepunkt
Copy link
Owner

Not maintained anymore. Feel free to pull request a bugfix.

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

No branches or pull requests

3 participants