Skip to content

Instantly share code, notes, and snippets.

@bdsqqq
Created December 6, 2023 16:42
Show Gist options
  • Save bdsqqq/8107c641ed6e0baa8c892c1805283316 to your computer and use it in GitHub Desktop.
Save bdsqqq/8107c641ed6e0baa8c892c1805283316 to your computer and use it in GitHub Desktop.
tailwind animations plugin
/**
* 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