Skip to content

Issues with css values with () #13

Description

@wedelgaard

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.

Activity

  1. codepunkt commented on Jun 22, 2017

    @codepunkt
    Owner

    @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!

  2. wedelgaard commented on Jun 22, 2017

    @wedelgaard
    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 :)

  3. codepunkt commented on Jul 10, 2017

    @codepunkt
    Owner

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

  4. wedelgaard commented on Jul 11, 2017

    @wedelgaard
    Author

    @codepunkt uh nice will look forward to it ;)

  5. jjenzz commented on Apr 19, 2021

    @jjenzz

    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 🙂

  6. codepunkt commented on Apr 26, 2021

    @codepunkt
    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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions