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

Keyframe animations #68

Closed
HeyHugo opened this issue Jan 2, 2017 · 12 comments
Closed

Keyframe animations #68

HeyHugo opened this issue Jan 2, 2017 · 12 comments
Labels

Comments

@HeyHugo
Copy link

HeyHugo commented Jan 2, 2017

Hi!
I was trying to do a keyframe animation with styled-jsx, but the produced css looks a bit strange and my animation doesn't work.

This is what I try to render:

<div>
  <span>test</span>
  <style jsx> {`
    span {
      animation-duration: 0.6s;
      animation-name: slidein;
      animation-iteration-count: infinite;
    }
    @keyframes slidein {
      from {
        margin-left: 100%;
        width: 300%;
      }

      to {
        margin-left: 0%;
        width: 100%;
      }
    }
  `}</style jsx>
</div>

and this is the produced css:

span[data-jsx="1065293759"] {-webkit-animation-duration:10652937590.6s;-moz-animation-duration:10652937590.6s;animation-duration:10652937590.6s;-webkit-animation-name:1065293759slidein;-moz-animation-name:1065293759slidein;animation-name:1065293759slidein;-webkit-animation-iteration-count:1065293759infinite;-moz-animation-iteration-count:1065293759infinite;animation-iteration-count:1065293759infinite;}@-webkit-keyframes 1065293759slidein {from {margin-left: 100%;width: 300%;}to {margin-left: 0%;width: 100%;}}@-moz-keyframes 1065293759slidein {from {margin-left: 100%;width: 300%;}to {margin-left: 0%;width: 100%;}}@keyframes 1065293759slidein {from {margin-left: 100%;width: 300%;}to {margin-left: 0%;width: 100%;}}

As you can see the data-jsx number (1065293759) seem to be prefixed before all animation property values.

Am I doing this wrong or could this be a real issue?

@rauchg
Copy link
Member

rauchg commented Jan 3, 2017

weird :D

@rauchg
Copy link
Member

rauchg commented Jan 3, 2017

Good catch @HeyHugo we should fix it!

@rauchg rauchg added the bug label Jan 3, 2017
@thysultan
Copy link
Contributor

Stylis does prefix keyframes and animations but there is an option to disable this @rauchg, I think a lot of these issue will be solved with updating the fork up stream.

@rauchg
Copy link
Member

rauchg commented Jan 3, 2017

In this case it's a bug with prefixing duration though, right?

Btw @thysultan would love to merge with upstream, but keep in mind we made the following changes:

  • disabling non-standard behavior (like top level properties without selectors)
  • we decided to add css-modules-like :global to skip prefixing. I saw you support :host etc now, but since we can't really emulate web components 100%, I thought it was better not to fake it
  • using attribute selectors suffixing. in the future we might also have an option to use classes too (Class re-writing mode #27)

@thysultan
Copy link
Contributor

@rauchg Yes upstream handles 2 ':global' and attribute selectors. I could send a PR that that updates it upstream with 1. And ':host' disabled?

@rauchg
Copy link
Member

rauchg commented Jan 3, 2017

@thysultan that would be wonderful. Thanks for your awesome work on stylis

@rauchg
Copy link
Member

rauchg commented Jan 6, 2017

Pushed a few patches for animations until we have @thysultan's permanent solution. 🕺

@rauchg rauchg closed this as completed Jan 6, 2017
@HeyHugo
Copy link
Author

HeyHugo commented Jan 6, 2017

Nice, now my first example works. However I think the shorthand version for animation is still broken.

e.g.

animation: 0.6s infinite slidein;

Produced css:

span[data-jsx="3080172011"] {-webkit-animation:a30801720110.6s infinite slidein;-moz-animation:a30801720110.6s infinite slidein;animation:a30801720110.6s infinite slidein;}@-webkit-keyframes a3080172011slidein {from {margin-left: 100%;width: 300%;}to {margin-left: 0%;width: 100%;}}@-moz-keyframes a3080172011slidein {from {margin-left: 100%;width: 300%;}to {margin-left: 0%;width: 100%;}}@keyframes a3080172011slidein {from {margin-left: 100%;width: 300%;}to {margin-left: 0%;width: 100%;}}

@thysultan
Copy link
Contributor

@HeyHugo once #73 is merged it should handle all cases, previously it was making the assumption that the animation name will always come first, but really it can be anywhere in the declaration.

@rauchg
Copy link
Member

rauchg commented Jan 6, 2017

That's remarkably helpful @thysultan, thank you so much!

@aga5tya
Copy link

aga5tya commented Jul 8, 2017

@giuseppeg @thysultan , I'm getting conflict in animation keyframe when i use only point based value in animation timing shorthands. Like .8s instead of 0.8s for example. The former syntax is accepted in the browser afaik. Not so important, just came across this.

Input:

animation: moveR .8s 1s linear;

@keyframes moveR {
        ...
        }

Output:

-webkit-animation: a1838729535moveR a1838729535.8s 1s linear;
-moz-animation: a1838729535moveR a1838729535.8s 1s linear;
animation: a1838729535moveR a1838729535.8s 1s linear;

@-webkit-keyframes a1838729535moveR {
  ...
}

@-moz-keyframes a1838729535moveR {
   ...
}

@keyframes a1838729535moveR {
   ...
}

@thysultan
Copy link
Contributor

@aga5tya Can't reproduce in stylis, what version of styled-jsx are you using?

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

No branches or pull requests

4 participants