-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Add transition utilities #1273
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
Add transition utilities #1273
Conversation
Here are documents about the
They included this example. I can see it added but disabled by default. I personally never needed to use it. |
For
|
The way you handle the transition properties into groups here is really good. Is ‘transition-colors’ plural because it has multiple properties? |
@codytooker The only issue with numbers in this case is that it forces you to memorize which ones exist, like With colors it's not so bad because it's always steps of 100. That said I'm not vehemently opposed to it, there's definitely a higher chance of regretting |
@FrankyFrankFrank Yeah exactly 👍 |
My only comment to Cody’s number suggestion is that it would become slightly more “gotta check the docs to see if this exists”. It’s also true that the difference between 100ms and 200ms is a wide gulf. Even the difference between 100ms and 150ms is negotiable in between sometimes. You would need to include a lot of values. |
@hawezo Thanks for this, super useful to know. I think if that property is only useful for people doing JS animations that it's better to let them manage that property using the same JS instead of with Tailwind. |
Looks super useful, and love the research you did! Also concerned about the naming for the duration classes however. As others have pointed out already, with duration times you might need a lot of different values to get the feeling of your transitions just right. Now if I need to add 125ms and 175ms duration classes, I need to consider "Which name expresses faster than I see how it's easier to memorize a) looking up stuff in the tailwind or design system documentation for some (surprisingly short amount of) time until you know it by heart is part of the tailwind learning curve already anyway b) the VSCode extension makes that way less of an issue by autocompleting the class names On another note, are the easing function class names so generic on purpose? Could lead to confusion if tailwind adds support for CSS animations at some point in the future, if we then have /* Why do I need a type prefix for animations but not for transitions? */
.animation-ease-linear {
animation-timing-function: ease;
}
.ease-linear {
transition-timing-function: ease;
} Or is your plan to make them truly generic and use the same class for animations and transitions? :) .ease-linear {
transition-timing-function: ease;
animation-timing-function: ease;
} |
@adamwathan I think delay utilities that match the duration ones would be great for staggered animations. That’s the main reason for delays usually. |
@brandonpittman From my understanding, you shouldn't use
According to this, if you use EDIT - Apparently, two comments from Brandon were deleted. |
Good stuff. Regarding numbers for duration, I'd keep it at named values. In this case it's simpler to get started quick, and builds upon known conventions, so better DX. |
@adamwathan I think that does make some sense. The default scale being more of a named scale does make sense for new comers, It's easily editable to a custom scale so, fast, faster, fastest, should work. I'm just always hesitant on that because people inevitably will try and keep the scale but add in their own values in between or after so the naming get's a little weird, but again if someone is editing the scale they can come up with their own names at that point anyways. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should try to avoid all of the !important
That's only when the |
Good thought @jonaskuske. My two cents: I think it probably makes sense to prefix all ease classes with |
Looks really awesome! Regarding the duration utilities, i agree that using numbers has a trade-off on initial productivity but i believe that almost any meaningful project will be required to add more durations between the default values and having the named scale will make that more difficult. |
This is great, thanks so much! I'm wondering if it makes sense to extract {
durations: {
fastest: '75ms',
faster: '100ms',
fast: '150ms',
medium: '200ms',
slow: '300ms',
slower: '500ms',
slowest: '700ms',
},
easing: {
linear: 'linear',
in: 'cubic-bezier(0.4, 0, 1, 1)',
out: 'cubic-bezier(0, 0, 0.2, 1)',
'in-out': 'cubic-bezier(0.4, 0, 0.2, 1)',
},
transitionDelay: theme => theme('durations'),
transitionDuration: theme => theme('durations'),
transitionTimingFunction: theme => theme('easing'),
} Regarding This middle-ground approach would look something like this: <div class="transition duration-fast ease-in-out">foo</div> And the relevant generated CSS would look like this: .transition.duration-fast {
transition-duration: 150ms;
}
.transition.ease-in-out {
transition-timing-function: ease-in-out;
} I've been using this approach for production sites for a couple of months and I really don't have any complaints. And being that I work at a web design studio that uses tons of transitions, I use these utilities a lot. |
@jonaskuske @tomhermans @codytooker @romansndlr I just finished opening a new issue for some more general work on Tailwind class names—feel free to chime in #1277 |
Bunch of thoughts on some of the things that have been mentioned so far... Adding delaysI've been thinking about the real-world use-cases for adding Very often you use delays for staggered animations, so transitioning x elements offset by 50ms each. In these situations you are very often generating these elements in some sort of loop and doing some basic That means this sort of thing is often better handled by an inline style, or by whatever JS you are probably already writing to manage the whole thing. Similarly you often want something to stagger in, but not stagger out, which means the delay values need to be in place for the "enter" phase of a transition but not be in place for the "exit" phase, so since they need to be managed conditionally that basically necessitates managing it with JS already. I'm also not convinced that even if we did at delays that they should match the durations, again because in a stagger transition you are using some consistent offset (like 50ms) which would lead to delay values like Default duration valuesWe could just include a more comprehensive scale that jumped in 50ms increments and use it for both duration and delay, but in my opinion that is lazy and conflicts with the philosophy we've applied to come up with all of Tailwind's other default values, which has been to agonize over the defaults and make it as easy as possible for people to fall into the pit of success with their designs by making it as hard as possible to pick the "wrong" value for something. Offering a 600ms duration and a 650ms duration encourages people to nitpick and will slow them down instead of speeding them up. For this reason I think it's important that the default duration values get progressively longer, like the defaults I've used in this PR. I do worry that people may want a value higher than 700ms though (1s is not uncommon in sites I audited), so it's worth exploring how we might solve that. Naming the
|
A lot of IDEs will autocomplete making the difficulty of guessing not as big of an issue- on the other hand, I don't think having to deviate from the naming convention to extend would be too bad either since you could just prefix your changes. |
For duration utilities, I really dig the simple I also am in favor of More on that: ease of configuration is amazing in Tailwind, and And semantically named classes aren't impossible to add values to—they can have names like Take my opinion with a grain of salt though, because I'll definitely be applying a custom linear numeric naming convention to transition duration utilities 😅 |
Naming the
|
What if we did this by default? <div class="duration-fast delay-short ease-in"></div> .duration-fast {
animation-duration: theme(animationDuration.fast);
transition-duration: theme(transitionDuration.fast);
}
/* .delay-short .ease-in, etc. */ And if you want to override, say, the easing function for animations only, you can use a variant: <div class="duration-fast delay-short ease-in animation:ease-out"></div> .animation\:ease-out {
animation-timing-function: theme(animationTimingFunction.ease-out)
} Benefits:
Disadvantages:
Alternatively, we could approach this like <div class="duration-fast delay-short ease-in a-ease-out"></div> (or similar). Basically, |
a9d1e0b
to
d5199e4
Compare
One issue I have come across today is that iOS chrome seems to have issues with transforms, in that it doesn't transform them, it just jumps from one to the other. I don't think this is exclusive to Tailwind, but thought I would mention it. I am not sure of the solution (if there is one) yet, but I will try and do some research and post back here... |
This PR adds support for
transition-property
,transition-duration
, andtransition-timing-function
utilities.Here are the utilities generated by default:
transition-property
By default we include utilities for
transition
,transition-none
,transition-all
,transition-colors
,transition-opacity
, andtransition-transform
.The base
transition
utility enables transitions for colors, opacity, and transform all at once. I think this is the most popular/useful combination and makes sense as the default, since the alternative would be something horrific liketransition-colors-opacity-transform
. Transitioning color properties is not quite as performant as opacity and transform (it happens during the paint phase rather than the composite phase) but is still very fast compared to stuff like padding, and basically every website on the internet uses color transitions so I think it's fine.I considered trying to come up with a CSS Custom Properties based solution to make transition properties composable but there's not really a great way to do it.
Instead, if you wanted to transition say
opacity
andtransform
but not colors, I would recommend two approaches:opacity-transform
to yourtransformProperty
theme config.style="transition-property: opacity, transform"
— there's no magic numbers or anything to worry about here so an inline style introduces no maintainability issues other than potentially vendor prefixing.transition-timing-function
By default I've included utilities for
ease-in
,ease-out
,ease-in-out
, andease-linear
. These can be customized under thetransitionTimingFunction
key in your theme config.I agonized for a long time over what values to include here, and originally was planning to use familiar values from easings.net.
After a lot of time studying animation and reading different resources, the Material Design Motion Guidelines stood out to me as making the most sense and having the best justification for their chosen easing curves, so I've decided to use those three curves as the defaults for Tailwind.
I may add a couple more in the future that have a more exaggerated entrance/exit curve for a more cinematic look but lets see how far we can get with just these three. I did a call with Jonas Naimark who does motion design at Google and in his opinion these three curves are pretty sufficient, and he can achieve everything he needs by just tweaking the duration usually.
transition-duration
By default I've included utilities for
transition-fastest
,transition-faster
,transition-fast
,transition-medium
,transition-slow
,transition-slower
, andtransition-slowest
. These can be customized under thetransitionDuration
key in your theme config.These are loosely inspired by values used throughout the Material motion guidelines.
What's not included
transition-delay
utilities — we can add these later if people need them, I've personally never needed them though and I was having a hard time deciding on a class name so I've just punted on it for now.will-change
utilities — I never use this and don't really understand it, if someone can make a compelling case with a good demo that proves it's important we can definitely add.Try it out
Here's a quick and dirty demo (just using pre-compiled CSS):
https://tailwind.run/PfhdtG/1
Any feedback appreciated 👍🏻