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

Remove the negative flag from the Candidate AST #14938

Merged
merged 6 commits into from
Nov 11, 2024

Conversation

RobinMalfait
Copy link
Member

This PR removes the negative flag from the Candidate AST. The system itself doesn't this information at all, but it's up to each plugin to handle the negative flag themselves.

This also means that if you don't handle it, that foo and -foo results in the same CSS output.

To make sure that the negative version of utilities that supported it still work, this PR also adds the negative versions as separate utilities. E.g.: -scale is registered in addition to scale.

This is an internal refactor only, and doesn't change any behavior.

@RobinMalfait RobinMalfait requested a review from a team as a code owner November 10, 2024 12:13
Comment on lines +1176 to +1188
utilities.functional('-scale', handleScale({ negative: true }))
utilities.functional('scale', handleScale({ negative: false }))
Copy link
Member

Choose a reason for hiding this comment

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

Could these use functionalUtility?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe if we apply some gymnastics. But I think we didn't use functionalUtility before because we register scale-x, scale-y and scale-z as separate functional utilities as well. If we make scale a functional utility, then candidates such as scale-x-50 will be handled by the scale functional utility with a value of x-50.

Copy link
Member

Choose a reason for hiding this comment

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

Looked into it quickly, looks like the real reason we don't do it this way is because we handle arbitrary values differently than regular values — scale-[4_6] just produces scale: 4 6 and bypasses all the composition variables and stuff.

Copy link
Member Author

Choose a reason for hiding this comment

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

That is also true. We could handle that when handling the functional utility.

Don't think that's worth it 🤔

Comment on lines +1258 to +1270
utilities.functional('-rotate', handleRotate({ negative: true }))
utilities.functional('rotate', handleRotate({ negative: false }))
Copy link
Member

Choose a reason for hiding this comment

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

Could these use functionalUtility?

Copy link
Member

@philipp-spiess philipp-spiess left a comment

Choose a reason for hiding this comment

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

Awesome change!

I think it's a bit unclear now when to use staticUtility vs. using the raw utilities.static. The only difference now is that you can avoid typing decl()? 🤔 Makes me wonder if we should remove this indirection.

Comment on lines -258 to -263
// Candidates that start with a dash are the negative versions of another
// candidate, e.g. `-mx-4`.
if (base[0] === '-') {
negative = true
base = base.slice(1)
}
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if there are any migrations in the upgrade script that will no longer work now because we compare the base ignoring a potential -. I looked over simple-legacy-classes and it looks fine though. max-w-screen-* looked sus but didn't support negative prefixes in v3 either.

@@ -228,8 +228,7 @@ export function buildPluginApi(
)
}

designSystem.utilities.static(name.slice(1), (candidate) => {
if (candidate.negative) return
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

Comment on lines +370 to +373
if (supportsNegative) {
utilities.static(`-${name}-px`, () => handle('-1px'))
}
utilities.static(`${name}-px`, () => handle('1px'))
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if this should use staticUtility for consistency now, since we also use the functionalUtility helper for the case below (Is it even necessary to add the staticUtility abstraction now in the first place though? 🤔)

Comment on lines 504 to 505
utilities.static(`${name}-full`, () => [decl(property, '100%')])
utilities.static(`-${name}-full`, () => [decl(property, '-100%')])
Copy link
Member

Choose a reason for hiding this comment

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

For consistency I think these should also use staticUtility:

Suggested change
utilities.static(`${name}-full`, () => [decl(property, '100%')])
utilities.static(`-${name}-full`, () => [decl(property, '-100%')])
staticUtility(`${name}-full`, () => [property, '100%'])
staticUtility(`-${name}-full`, () => [property, '-100%'])

@thecrypticace
Copy link
Contributor

Thinking out loud: maybe suggest shouldn't have a supportsNegative option any longer since it's a function of the utility/root itself and not of specific values of the utility.

@adamwathan adamwathan force-pushed the feat/remove-negative-flag branch from 8d323b2 to ca8e0c1 Compare November 11, 2024 15:25
@adamwathan adamwathan force-pushed the feat/remove-negative-flag branch from ca8e0c1 to a95c2d6 Compare November 11, 2024 15:27
@adamwathan adamwathan merged commit 292efa5 into next Nov 11, 2024
1 check passed
@adamwathan adamwathan deleted the feat/remove-negative-flag branch November 11, 2024 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants