-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[FEATURE PROPOSAL] utility for animation #456
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
Comments
you might be interested in participating here: #378 |
@ricricucit This issue is about animations, not transitions. Although I see some discussion about animations in there too. I propose animations could be added in the Tailwind config file and be added in the HTML via a class Config: // tailwind.config.js
animations: {
siren: {
from: {
backgroundColor: "red",
}
to: {
backgroundColor: "blue",
}
}
} Output: .animation-siren {
animation-name: siren;
}
@keyframes siren {
from {background-color: red;}
to {background-color: blue;}
} Usage: <div class="delay-1s duration-2s iteration-infinite animation-siren"> |
@royvanv Until CSS animations are added to Tailwind core, you can use my plugin: https://github.com/benface/tailwindcss-animations |
@benface Funny to see your implementation is the same as my proposal. Not directly looking for animations myself, though. |
It's similar, but I use different classes for delay and duration, to not conflict with Tailwind's transition classes. |
Hadn't considered the naming conflict, I was just proposing the |
Planning to add this for sure, API I am thinking is to just use the Haven't thought about it TOO much but probably something like: module.exports = {
theme: {
keyframes: {
spin: { from: { transform: 'rotate(0deg)' }, to: { transform: 'rotate(359deg)' } }
},
animation: {
spin: '500ms infinite spin'
},
}
} We could try to get clever with declaring the animation and keyframes in the same place too, just need to think of a way to define it that doesn't feel like it has any risk of regret. |
+1 for this, It would be a great addition so that we can create simple animations like loading spinners. (must have for devs) |
Working on these animation utilities this week and trying to nail down the configuration API... There are two high-level approaches I can think of: 1. Co-locate the animation and keyframe definitionsWe could use a single
Exact syntax subject to change but you get the idea. 2. Separate keyframes configurationAnother approach is to separate the keyframes and animation configuration into separate keys. This is much less clever and much closer to vanilla CSS:
In this version, we'd likely have two core plugins: I really can't decide which of these makes more sense. I think there's a good argument for option 2 because "less clever" usually === "less likely to regret" but there's something nice about being able to configure an animation together in a single place. Anyone have any strong thoughts on this? |
Number two makes it easier to reuse animations with pre-set configurations, something like: animation: {
card-enters: 'enter 1s ease-in',
small-card-enters: 'enter .5s ease-in'
} |
@adamwathan appro 2 looks clean n reusable imo |
Haven’t thought too much about it, but would a mix of 1. and 2. be possible? Keeping Both syntaxes would need to be supported too then, I guess. Maybe too complex. Just throwing it out there. |
Approach 2 mirrors the original CSS fashion, I like it. And it’s more readable. |
Option 1 is nicer in the sense it’s contained. And you only need to focus on reading 1 thing. It also makes it easier to package animations as you can just do like... animation: [...require(“animation-library”)] Option 2 looks nicer as there’s not a mixture of structures in the definition. Option 1 seems more re-usable as you can just create a variable with your definition, then plug it in where it fits. Whereas Option 2 is based on the assumption key/property names match up. Although Option 2 looks nicer (Whilst there’s minimal code), I’d probably lean towards Option 1 on the re-usability front |
It is nice keeping the animation and keyframes in the same place. Maybe something like this would make Option 1 more reusable:
|
For projectwallace.com I figured that there are two important configs to animations and transitions: duration/delay and the timing function. Perhaps these could be configurable at the theme level and the rest at the config level? Or would that become too complex? |
As someone who don't speak CSS I'd vote for option 1. Reasons:
But, why not both? (C) |
Approach 2 makes the most sense to me, both its syntax and reusability are better in my opinion. |
I think Option 2 is better, it's more readable on more maintainable. {
keyframes: {
spin: {
from: {
transform: 'rotate(0deg)',
'.child': {
opacity: '0'
}
},
to: {
transform: 'rotate(360deg)',
'.child': {
opacity: '1'
}
},
}
}
} |
e.g.
The text was updated successfully, but these errors were encountered: