Created
December 6, 2023 16:42
-
-
Save bdsqqq/8107c641ed6e0baa8c892c1805283316 to your computer and use it in GitHub Desktop.
tailwind animations plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generates tailwindcss-animate compatible animation utilities from the keyframes defined in theme.keyframes. | |
* | |
* @see [tailwindcss-animate](https://github.com/jamiebuilds/tailwindcss-animate) | |
*/ | |
const generateAnimationUtilitiesFromKeyframes = plugin(({ addUtilities, theme }) => { | |
function generateAnimationUtilities(keyframes) { | |
const animationUtilities = {}; | |
Object.entries(keyframes).forEach(([animationName, animationKeyframes]) => { | |
const animationCss = {}; | |
Object.entries(animationKeyframes).forEach(([keyframe, styles]) => { | |
animationCss[keyframe] = styles; | |
}); | |
animationUtilities[`@keyframes ${animationName}`] = animationCss; | |
animationUtilities[`.animate-${animationName}`] = { | |
animationName: animationName, | |
animationDuration: 'theme("animationDuration.DEFAULT")', | |
transitionTimingFunction: 'theme("transitionTimingFunction.DEFAULT")', | |
}; | |
}); | |
return animationUtilities; | |
} | |
addUtilities(generateAnimationUtilities(theme('keyframes'))); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment