Skip to content

Migrate keyframes from JS to CSS#14666

Merged
philipp-spiess merged 3 commits into
nextfrom
feat/migrate-keyframes-to-css
Oct 15, 2024
Merged

Migrate keyframes from JS to CSS#14666
philipp-spiess merged 3 commits into
nextfrom
feat/migrate-keyframes-to-css

Conversation

@philipp-spiess

Copy link
Copy Markdown
Contributor

This PR adds support for rewriting JS theme config keyframes to CSS as part of the JS config to CSS migration.

Example:

import { type Config } from 'tailwindcss'

module.exports = {
  theme: {
    extend: {
      keyframes: {
        'spin-clockwise': {
          '0%': { transform: 'rotate(0deg)' },
          '100%': { transform: 'rotate(360deg)' },
        },
        'spin-counterclockwise': {
          '0%': { transform: 'rotate(0deg)' },
          '100%': { transform: 'rotate(-360deg)' },
        },
      },
      animation: {
        'spin-clockwise': 'spin-clockwise 1s linear infinite',
        'spin-counterclockwise': 'spin-counterclockwise 1s linear infinite',
      },
    },
  },
} satisfies Config

Will be printed as:

@theme {
  --animate-spin-clockwise: spin-clockwise 1s linear infinite;
  --animate-spin-counterclockwise: spin-counterclockwise 1s linear infinite;

  @keyframes spin-clockwise {
    0% {
      transform: rotate(0deg);
    }
    100% {
      transform: rotate(360deg);
    }
  }
  @keyframes spin-counterclockwise {
    0% {
      transform: rotate(0deg);
    }
    100% {
      transform: rotate(-360deg);
    }
  }
}

Base automatically changed from feat/migrate-plugins to next October 14, 2024 15:45
@philipp-spiess philipp-spiess force-pushed the feat/migrate-keyframes-to-css branch from e34365f to ef049c0 Compare October 14, 2024 15:51
Comment on lines +256 to +258
let ast: AstNode[] = []
applyKeyframesToAst(ast, { theme: { keyframes } })
return toCss(ast).trim() + '\n'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a sneaky way of handling this. I love it!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for real this is a pretty sweet way of doing it 💯

Comment thread packages/@tailwindcss-upgrade/src/migrate-js-config.ts Outdated
@philipp-spiess philipp-spiess merged commit 782bc26 into next Oct 15, 2024
@philipp-spiess philipp-spiess deleted the feat/migrate-keyframes-to-css branch October 15, 2024 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants