-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Add composable transform utilities #1272
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
Conversation
Bumps [eslint](https://github.com/eslint/eslint) from 6.7.2 to 6.8.0. - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md) - [Commits](eslint/eslint@v6.7.2...v6.8.0) Signed-off-by: dependabot-preview[bot] <[email protected]>
…ter/eslint-6.8.0
Beautiful. 🤟 |
Love this. Any thought on supporting
|
It works if you add |
Awesome sauce |
Looks like the sensible approach. Was reading this and also immediately thought of custom properties. |
It's nice, but the use of CCP means that children elements will also inherit the transform if they have the "transform" class. |
@georges-gomes I rarely nest transformed elements deeply honestly, but I can see it being an issue. Maybe your original design @adamwathan might be better, resetting the properties on each |
In straight HTML I agree with you. But if a light-dom framework is used, you nested tons of components and you don't even realize they do use transforms. I think it's easy to translate a nested scaled element, specially when you want to animate transitions or hover. The result will be unexpected. |
Good call @tlgreg I’ll switch back to that approach, will fix the transform inheritance 👍🏻 |
I’m thinking of elements that grow in one direction on hover, or something like a progress bar. Scaling x and y separately are needed for cases like that, and that’s why I included them in my transitions plugin. |
Just pushed an update that fixes the inheritance issue and also adds negative values for translate (originally left out by mistake) as well as @brandonpittman any chance you can point me to a site you've seen that uses scaleX/Y for that purpose? What you're saying makes total sense and it would be helpful for me to see some real world examples to make sure I get the approach right. |
@adamwathan Forgive me for using a site I worked on as an example, but the nav links on this page have an :after element with scaleY(0). On hover, they transition to scaleY(1). Sure, you could do the same thing with overflow-hidden and translateY. But scaleY is more representative of the effect I want. Using just scale could get a weird effect where it's also growing out of the center as well. |
As for IE11 support, I think the Postcss Custom Variables plugin will at least make sure that whatever variable is defined at build time will work as a default value. |
@adamwathan In my own transistions plugin, I used tx, -tx, ty, and -ty for translate shorthand (similar to existing margin and padding utilities). How to you feel about using something like that? |
…or a single themeKey
238e267
to
dee2446
Compare
Updated to support
I think I'd rather be a bit more verbose for this one since translate isn't as commonly used as margin/padding 👍 |
This is already enabled (as is focus) for all three of the supported transforms in this PR 👍 |
@adamwathan That’s a nice little Christmas present! Thanks. |
Merging 😘 |
Very clever solution. I'm thinking this method could be used on my images to stack up different images/gradients. |
I like this approach. Transform vs. animation will be the killer feature |
This PR adds a set of basic transform utilities to Tailwind.
It includes support for the following properties:
transform
transform-origin
...and the following transform functions:
scale
rotate
translateX
translateY
One of the biggest challenges with this feature is that CSS does not inherently support composable transforms — you can only specify one
transform
property that must include all of your transform functions in one list.That sucks when you want to take a utility-based approach, because it would be nice to be able to add
rotate-45 scale-110
to an element and have both transforms be applied.This PR solves this problem using CSS custom properties.
First, we define a
transform
class that looks like this:You can think of this as "enabling" the transform feature — it sets the
transform
property to accept four custom properties and provides a "no-op" default for each one.To specify the
transform-origin
, use theorigin-{side}
utilities:We include
top
,top-right
,right
,bottom-right
,bottom
,bottom-left
,left
,top-left
, andcenter
out of the box, and they can be configured using thetransformOrigin
property in your theme.Then each transform function has its own set of utilities that simply modify the custom property:
By doing things this way, you can combine multiple transforms on an element like this:
translate
uses ourspacing
scale right now, and I will be updating it to include percentages soon as well (at least 50% and 100%). It can be configured using thetranslate
key in your theme.rotate
includes0deg
,45deg
,90deg
, and180deg
(plus the negative versions) out of the box, and can be configured using therotate
key in your theme.scale
includes0
,0.5
,0.75
,0.9
,0.95
,1
,1.05
,1.1
,1.25
, and1.5
. It can be customized using thescale
key in your theme.I've opted to make these functions separate theme keys because eventually all browsers will support CSS Individual Transforms for these three properties, so in a couple of years we can migrate to those without breaking the theme config.
What's not included
3D Transforms
This PR intentionally excludes support for 3D transform related stuff, like
backface-visibility
,perspective
, and the 3D transform functions. We can iterate on support for that later without any BC breaks.Scaling x and y separately
We can add this without making it a breaking change separately if there is demand for it, but I audited many sites and found no usage of
scaleX
orscaleY
outside of complex keyframe animations so I don't think it will be missed.Complex rotations
This PR only supports
rotate()
, notrotateX
orrotateY
. If there is enough demand for this we can add it later without a BC break.Skew
This can be added later if there is demand, but I found essentially no usage of this in the wild aside from Stripe. It is challenging to come up with reasonable default values for
skew
because it's usually used in a very brand-specific way rather than to solve general purpose problems.IE 11 support
IE 11 doesn't support CSS custom properties so this approach can't work there. Rather than cripple this feature in really frustrating ways, I've decided to forgo IE 11 support. If someone needs to support IE 11 and wants to use transforms in their project, they will have to do it with their own custom utilities.
Try it out
Here's a Tailwind.run where I've implemented this in user land so you can play with it:
https://tailwind.run/hpLzYj/8 (Updated 2019-12-23 7:35pm)
Let me know what you think of what I've done here! I don't want to bike-shed over this stuff too much since it's all configurable anyways, but if there are any obvious problems with how I've put this together it would be great to find out before I merge it in.