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.

Keyframes should be added by Twin for the `animate-xxx` classes

See original GitHub issue

Following up on from a feature request by @fvanwijk in https://github.com/ben-rogerson/twin.macro/issues/92#issuecomment-678154951_

I’d like to … only include tailwindcss/dist/base.min.css and let twin do the rest. …the keyframes aren’t part of the base styles… I would expect twin to include them when I use one of the animate-xxx utils.

The animate-xxx classes added in tailwindcss:1.6.0 were originally added to base.min.css but were removed in 1.6.1.

So now twin needs to define the @keyframes somewhere to allow the animate classes to work.

The missing keyframes css
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes ping {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  75%, 100% {
    transform: scale(2);
    opacity: 0;
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: .5;
  }
}

@keyframes bounce {
  0%, 100% {
    transform: translateY(-25%);
    animation-timing-function: cubic-bezier(0.8,0,1,1);
  }
  50% {
    transform: translateY(0);
    animation-timing-function: cubic-bezier(0,0,0.2,1);
  }
}

Here are some initial ideas:

1. Use the keyframes import

styled-components / emotion both have a keyframes import that can help define the keyframes but it’s scoped to a component by default and so the keyframe definition would be repeated if the class is used more than once.

That said, Twin could potentially listen for the use of any of the animate classes and inject the matching keyframe class only once within the document.

2. Use the Global import

styled-components / emotion both have a Global import that can store the keyframe definitions, this can avoid any css duplication issues. Unfortunately, it would mean it’s a manual process to paste the missing keyframe css into the Global block.

3. Add a twin Global import

If twin offered a Global import (import { global } from 'twin.macro'), then it could inject the keyframes on your behalf. Plenty of people would only want the extra keyframe css added if they were using the animate classes so that would need to be conditional somehow. Twin doesn’t know which animate classes you’ve used so all of the keyframe definitions would need to be added at once.

I’m keen to hear any suggestions so feel free to chip in.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
fvanwijkcommented, Oct 9, 2020

Thanks for mentioning. I didn’t even know that this config feature existed 👍 That would mean that the custom keyframes could be inserted by twin.macro, but other regular custom global HTML will be inserted using the createGlobalStyle (or using a plain css file)

1reaction
ben-rogersoncommented, Oct 8, 2020

Looks like I missed adding the keyframes customization functionality. Adding the keyframes automatically through GlobalStyles seems like a good idea.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use frames and keyframes in Animate - Adobe Support
Use this guide to understand how to insert, select, label, and enable frames and keyframes in Animate.
Read more >
Classic VS Motion Tweening | Adobe Animate Tutorial
This time we take a quick look at the basics between classic tweening and motion tweening in Adobe Animate !Thanks for watching!
Read more >
keyframes - CSS: Cascading Style Sheets - MDN Web Docs
The @keyframes CSS at-rule controls the intermediate steps in a CSS animation sequence by defining styles for keyframes (or waypoints) along ...
Read more >
Keyframing | Unreal Engine 4.27 Documentation
Tracks and content in Sequencer are animated by creating Keyframes (also referred to as Keys) with defined properties at specific points along the...
Read more >
Creating Videos - Twinmotion
Keyframes can be added before or after other keyframes. To add a keyframe before another keyframe, click the Create keyframe (+) icon located...
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