question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v10 keyframe docs needs clarification on what you can and can't do

See original GitHub issue
  • emotion version: 10.0.1
  • react version: 16.6.3

Relevant code.

const rotate = keyframes`
    to { transform: rotate(360deg); }
`;

const idleRotation = `${
   rotate
  } 0.86s cubic-bezier(0.4, 0.15, 0.6, 0.85) infinite`;

const AnimatedSvg = styled.svg`
  ${() => css`
    animation: ${idleRotation};
  `}
`;

What you did: This is a rather simplified example, in my full example, I’m combining/picking from multiple animations dynamically depending on the props passed in. This used to work in Emotion 9, but in Emotion 10 it doesn’t. animation: ${keyframesArray.join(',')}; Is there some trick in Emotion 10 that can help me?

I did try work around this by doing the following but that ended up inserting label:var-name into the css and breaking it.

const idleRotation = css`${
   rotate
  } 0.86s cubic-bezier(0.4, 0.15, 0.6, 0.85) infinite`;

What happened: https://codesandbox.io/s/v3nx68owp5

Problem description: Keyframes appear to not interpolate correctly except when directly being inserted into css or styled string blocks.

Suggested solution: Not sure what the solution is for this, it could just be an extra section in the docs outlining how to dynamically use keyframes.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
Andaristcommented, Nov 12, 2019

This should work:

const MyComponent = styled.div`
  ${({ visible }) => `

    // ... some style rules

    ${visible &&
      css`
       animation-iteration-count: 1;
       opacity: 1 !important;
       // animation: ${fadeOut} 10s;
     `}
   `
 }

It’s important to always wrap your string styles with css for various reasons:

  • prettier formatting
  • babel plugin optimization
  • this issue with keyframes
2reactions
christianalfonicommented, Feb 14, 2019

Oh? Are they not evaluated? The explains it… oh wait, I see where I am going wrong now. I am refactoring from styled.div (with styled components) to css prop. To get going I just changed out styled-components with emotion and everything worked out of the box, except our animations. Which I tried to reproduce poorly in the codesandbox.

I see what was missing now was using css on the returned value, which is not needed in styled-components… and I confused it all with CSS property. Sorry about that.

Updated Sandbox shows old code and what we had to change to, to get it running: https://codesandbox.io/s/43q0ky8o69

Read more comments on GitHub >

github_iconTop Results From Across the Web

KeyFrame (JavaFX 8) - Oracle Help Center
Class KeyFrame. Defines target values at a specified point in time for a set of variables that are interpolated along a Timeline ....
Read more >
How to apply custom animation effect @keyframes in MUI?
My challenge is how I can write the Javascript code to custom my animations using the makeStyle() in MUI. I want to be...
Read more >
Keyframes, InterFrame & Video Compression
Learn what keyframes are in relation to video compression while describing the interframe process. Includes best practices to follow for ...
Read more >
JSS v10 - Oleg Isonen - Medium
In v10, keyframe IDs have a generated suffix, using the same generateId() function that is used for class names generation and makes sure...
Read more >
Keyframe Tracking - Foundry Learn
Calculating tracks using keyframes can be the better option for more complex patterns and movement. It requires a little more work to set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found