-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 first-class 3d transform utility support #10982
Add first-class 3d transform utility support #10982
Conversation
Hey thanks! Just to set expectations, 90% chance we will have to close this for now just because I can't drop everything and make this feature a top priority (especially the documentation effort). As I've mentioned in other PRs it just takes a lot of dedicated time and focus to ensure major new feature PRs are ready to be merged, because I have to go through the process of thinking about the feature from first principles and make sure the final solution matches what I think is the best solution for the framework, so it's always a lot more work than simply looking at the changed files in a PR. So because we don't like to have PRs sit open for a year or more (like they have in the past), we generally close things that we aren't ready to merge basically right away. That said the big blocker on this feature in the past has been designing a thoughtful scale for
|
@adamwathan No worries! Always a pleasure. It's too bad there isn't a way to archive these sorts of PRs for a later date, though I suppose you can do that internally and then always re-open them once they surface as priorities. I'm collecting a laundry list of TailwindCSS plugins on my end and have no issue keeping them all local, but seeing them supported as first-class utilities is always great. I understand where you're coming from on priorities. I'm a big spec pusher for CSS and interop, and only about 10% of those proposals gain any real traction. I think 3d transforms are something used quite often, and seeing as they've been around forever and are widely supported, it seemed a no-op to get some of those widely used properties added, but yeah, documentation can end up being 90%+ of the work, and that's no joke. If your team had some sort of public list of incoming priorities (with preferred impl spec), devs like me might be happy to snipe them off the list to clear up your plates too. Just thinking out loud. |
|
Btw here's a little demo showcasing some of these new utilities: Here is how it looks: Source: <!-- Wrapper -->
<div class="relative grid min-h-screen place-items-center transform [--s:20vmin]">
<!-- Cube -->
<div class="
animate-float h-[--s] w-[--s] transform-3d
[&>div]:absolute [&>div]:left-0 [&>div]:top-0 [&>div]:h-full [&>div]:w-full
[&>div]:border-2 [&>div]:border-black [&>div]:transform-gpu
">
<!-- Faces -->
<div class="bg-red-500/25"></div>
<div class="bg-purple-500/25 transform-origin-left rotate-y-[90deg]"></div>
<div class="bg-blue-500/25 transform-origin-right -rotate-y-[90deg]"></div>
<div class="bg-amber-500/25 transform-origin-top -rotate-x-[90deg]"></div>
<div class="bg-green-500/25 transform-origin-bottom rotate-x-[90deg]"></div>
<div class="bg-cyan-500/25 -translate-z-[--s]"></div>
</div>
</div> In that example ☝🏼 I moved those classes to the parent using an arbitrary variant that would have otherwise been redundant. When working with a JS framework, those classes would more likely be added to each child using a JS variable instead. |
@adamwathan Also, if The example I showed in my previous comment was made with an intrinsic perspective (essentially Tailwind Play | scroll to the related comment ☝🏼 I think it would still help to include the
So this would still all be valid even without a |
Some notes from my implementation of https://github.com/sambauers/tailwindcss-3d I went for modern alternatives to There are some rough edges to browser support here as well. There are various triggers for GPU versus CPU usage that can kick in unexpectedly https://developer.mozilla.org/en-US/docs/Learn/Performance/CSS - there is also still a need to add I do want to see 3D support in core, but maybe the demand can be gauged through stats on the plugin that exists (not huge usage number so far), I can also weed out various issues there. I'm also happy to have your input and support on development there @brandonmcconnell Side note: @adamwathan sorry for not adhering to the brand/naming conventions for the 3D plugin. I only became aware of that guideline last night - I'll work through renaming soon. UPDATE - I've changed the display name of the plugin on the README and in NPM, I haven't changed the package name yet (it is still |
On the question of https://github.com/sambauers/tailwindcss-3d/blob/main/src/css-utilities/perspective.ts#L17 |
@brandonmcconnell what is the thinking behind having seperate |
@sambauers Thanks for sharing your thoughts here!
Re the naming conventions note, would you mind sharing the link to those so I can also update my plugins to adhere to the recommended naming conventions? Thanks! |
They are animatable in the most basic keyframe progressions. Imagine a simplified multi-step animation like this: @keyframes example {
0% {
transform: rotateZ(0deg) translateY(0rem);
}
50% {
transform: translateY(-5rem);
}
100% {
transform: rotateZ(360deg) translateY(0rem);
}
} At the 50% mark, you have a problem. You need to interpolate the missing The other problem we face with the current approach is that CSS variables don't animate. If we could replace the current set of variables with CSS properties they could be animated in keyframes, but that approach may or may not overcome the interpolation problem (I think it might though). CSS properties also have worse browser support than the modern transform properties 😄 Note that core Tailwind uses raw values for transform functions inside keyframes for the above reasons. This creates sub-optimal behaviour when attempting to apply static transforms along with animations. This is partially overcome in the 3D plugin, but not completely due to support for
|
@sambauers Personally, I am all for TailwindCSS switching to the more modern approach, but that's a bigger change which—as you pointed out—would produce breaking changes for those already building around the current approach. This PR has no conflicts with the current methodology, making it a no-op, whereas introducing the newer transform properties would require at least an opt-in option that defaults to the legacy format to prevent any breaking changes, essentially the inverse of how your package is currently configured. In that way, this PR is actually the first essential step toward introducing the new transform properties. |
62bd582
to
8dc0e57
Compare
This reverts commit 39de866.
d885911
to
7c6cc6b
Compare
Circling back to this briefly just because found myself deep in the
I like that this keeps the options really limited and easy to pick through for people who don't want to get lost nitpicking on this stuff, and that we have arbitrary values as an easy escape hatch for anyone who needs a specific value 👍 |
ec5be97
to
4c85287
Compare
@adamwathan Yeah, I like that. I updated the PR to reflect that (using "normal", vs. "standard") and also added a I think it could be intuitive that using Other than that, I think this PR is in pretty good shape. It was a bit hard to test the CPU/GPU opt in/out logic without being able to run this exactly as is in a remote environment. StackBlitz and CodeSandbox don't seem to play nice with Tailwind CSS npm forks, but it builds fine for me locally. It would just help to have someone on the team do a once-over on it to ensure that CPU/GPU bit works as expected. It might require a small patch. |
is there any result ? |
Liking these semantics. Waiting eagerly for this feature |
Hey all! Thanks @brandonmcconnell for drafting this, and everyone else for the input. We're implementing this in Tailwind CSS v4 with #13248. As you'll see, we're closely following what was discussed here, with a few small changes:
Closing this PR in favour of #13248. Please follow along there! |
Adds first-class support for 3d transformations using the existing TailwindCSS architecture.
This PR also sees GPU acceleration activated by default, but this can be easily switched to using CPU by default. It may also be useful to trigger some sort of warning if a user uses the
transform-cpu
utility but then also attempts to use one of the 3d transform utilities, which would naturally disable 3d transformations.The new utilities added in this effort are:
rotate-x
rotateX()
rotate
value(s)rotate-y
rotateY()
rotate
value(s)rotate-z
rotateZ()
rotate
value(s)scale-z
scaleZ()
scale
value(s)perspective-self
perspective()
perspective
perspective
perspective-self
perspective-origin
perspective-origin
origin
(transform-origin
)transform-flat
transform-style
flat
transform-3d
transform-style
preserve-3d
transform-content
transform-box
content-box
transform-border
transform-box
border-box
transform-fill
transform-box
fill-box
transform-stroke
transform-box
stroke-box
transform-view
transform-box
view-box
backface-visible
backface-visibility
visible
backface-hidden
backface-visibility
hidden