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

Support keyframes in JS theme config #14594

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

philipp-spiess
Copy link
Member

@philipp-spiess philipp-spiess commented Oct 4, 2024

Adds support for defining keyframes via the v3 JS config file. E.g.:

module.exports = {
  theme: {
    extends: {
      keyframes: {
        "fade-in": {
          "0%": { opacity: "0" },
          "100%": { opacity: "1" },
        },
        "fade-out": {
          "0%": { opacity: "1" },
          "100%": { opacity: "0" },
        },
      },
    },
  },
};

@philipp-spiess philipp-spiess marked this pull request as ready for review October 4, 2024 10:33
Comment on lines +70 to +81
@keyframes enter {
from {
opacity: var(--tw-enter-opacity, 1);
transform: translate3d(var(--tw-enter-translate-x, 0), var(--tw-enter-translate-y, 0), 0) scale3d(var(--tw-enter-scale, 1), var(--tw-enter-scale, 1), var(--tw-enter-scale, 1)) rotate(var(--tw-enter-rotate, 0));
}
}
@keyframes exit {
to {
opacity: var(--tw-exit-opacity, 1);
transform: translate3d(var(--tw-exit-translate-x, 0), var(--tw-exit-translate-y, 0), 0) scale3d(var(--tw-exit-scale, 1), var(--tw-exit-scale, 1), var(--tw-exit-scale, 1)) rotate(var(--tw-exit-rotate, 0));
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Uh oh wait what.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is interesting, in v3, plugins require an addBase to add the keyframes but if it was part of the JS config theme, it would be added automatically. That's lovely:
https://play.tailwindcss.com/YQLQchsWWW?file=config

Copy link
Contributor

Choose a reason for hiding this comment

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

In v3 the way this worked was keyframes were not emitted until used. So you had to do @keyframes …: theme('keyframes.whatever`) in your utility function. And we handle that already.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or we do in addUtilities at least. I don't think we do in matchUtilities which we should I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or at least I'm like 95% sure it works that way. Maybe we just de-duped them…

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh gotch you're right they're only added when used! If you use addBase and use it with an animate-* variable, it is emitted twice in v3 (at the end of the stylesheet).

Screenshot 2024-10-04 at 12 56 42

I guess it's fine if we always emit keyframes for compat now (we do this for v4 keyframes too!). However unsure if we should then guard against this case. Maybe it's ok if the keyframes are emitted twice here since it does no harm? WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah it's probably fine — would be nice to dedupe them but that can be an optimization done later. They should still be de-duped when minifying with lightingcss.

@philipp-spiess philipp-spiess marked this pull request as draft October 4, 2024 10:34
@philipp-spiess philipp-spiess changed the title Support keyframes in JS theme config WIP Support keyframes in JS theme config Oct 4, 2024
@philipp-spiess philipp-spiess marked this pull request as ready for review October 4, 2024 11:01
@philipp-spiess philipp-spiess changed the title WIP Support keyframes in JS theme config Support keyframes in JS theme config Oct 4, 2024
@philipp-spiess philipp-spiess merged commit bc18a57 into next Oct 4, 2024
1 check passed
@philipp-spiess philipp-spiess deleted the feat/parse-keyframes-in-js-themes branch October 4, 2024 11:58
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.

2 participants