Skip to content
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

[v4] Support arbitrary gradient angles #13783

Merged
merged 10 commits into from
Jun 4, 2024

Conversation

thecrypticace
Copy link
Contributor

This makes things like bg-gradient-[125deg] and bg-gradient-[1.3rad] work. Now the output will be:

.bg-gradient-\[1\.3rad\] {
  background-image: linear-gradient(1.3rad, var(--tw-gradient-stops, ));
}

.bg-gradient-\[125deg\] {
  background-image: linear-gradient(125deg, var(--tw-gradient-stops, ));
}

Copy link
Member

@adamwathan adamwathan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if we should do this under a bg-linear namespace instead of bg-gradient but keep gradient for BC? That way we could also do bg-conic and bg-radial as well 🤔

@thecrypticace
Copy link
Contributor Author

You know… I'm totally on board with that.

@thecrypticace thecrypticace force-pushed the feat/v4-bg-gradient-arbitrary branch from 1e08ff2 to 877b994 Compare June 3, 2024 20:38
Copy link
Member

@RobinMalfait RobinMalfait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

2 questions:

  1. For the bg-radial examples, will we do that in a new PR or in the same PR?
  2. This currently still allows you to type bg-gradient-[123deg]. Should we infer the angle data type in the 'bg' plugin and just return early so we don't fallback to background-color?

Something like:

diff --git a/packages/tailwindcss/src/utilities.ts b/packages/tailwindcss/src/utilities.ts
index 78d653b9d..53ac9a584 100644
--- a/packages/tailwindcss/src/utilities.ts
+++ b/packages/tailwindcss/src/utilities.ts
@@ -2532,9 +2532,13 @@ export function createUtilities(theme: Theme) {
           'bg-size',
           'length',
           'url',
+          'angle',
         ])
 
       switch (type) {
+        // Explicitly unsupported
+        case 'angle':
+          return
         case 'percentage':
         case 'position': {
           return [decl('background-position', value)]

@RobinMalfait
Copy link
Member

Just for completeness so we don't forget:

The last one I mentioned, where we infer the angle and mark it as not supported is a band-aid solution. Instead, we should bail earlier because we already know that it was invalid. bg-foo-bar-baz-[123deg] is not valid if bg-foo-bar-baz doesn't exist as a plugin root.

packages/tailwindcss/src/utilities.test.ts Outdated Show resolved Hide resolved
packages/tailwindcss/src/utilities.test.ts Outdated Show resolved Hide resolved
packages/tailwindcss/src/utilities.test.ts Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@thecrypticace
Copy link
Contributor Author

Just for completeness so we don't forget:

The last one I mentioned, where we infer the angle and mark it as not supported is a band-aid solution. Instead, we should bail earlier because we already know that it was invalid. bg-foo-bar-baz-[123deg] is not valid if bg-foo-bar-baz doesn't exist as a plugin root.

Yeah we need to do the proper fix but in a separate PR. It also doesn't need to land before this one so I'm gonna go ahead and merge this in. 👍

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@adamwathan adamwathan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just move that one changelog thing but otherwise rock and roll 🤘

@thecrypticace thecrypticace merged commit 7b63886 into next Jun 4, 2024
@thecrypticace thecrypticace deleted the feat/v4-bg-gradient-arbitrary branch June 4, 2024 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants