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

Add new in-* variant #15025

Merged
merged 12 commits into from
Nov 18, 2024
Merged

Add new in-* variant #15025

merged 12 commits into from
Nov 18, 2024

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Nov 17, 2024

This PR adds a new in-* variant that allows you to apply utilities when you are in a certain selector.

While doing research for codemods, we notice that some people use group-[]:flex (yep, the arbitrary value is empty…). The idea behind is that people want to know if you are in a .group or not.

Similarly, some people use group-[]/name:flex to know when you are in a .group/name class or not.

This new in-* variant allows you to do that without any hacks.

If you want to check whether you are inside of a p tag, then you can write in-[p]:flex. If you want to check that you are inside of a .group, you can write in-[.group].

This variant is also a compound variant, which means that you can write in-data-visible:flex which generates the following CSS:

:where([data-visible]) .in-data-visible\:flex {
  display: flex;
}

This variant also compounds with not-*, for example: not-in-[.group]:flex.

Additionally, this PR also includes a codemod to convert group-[]:flex to in-[.group]:flex.


This was proposed before for v3 in #13912

@RobinMalfait RobinMalfait force-pushed the feat/in-variant branch 2 times, most recently from 93af82b to a7feae7 Compare November 18, 2024 11:17
@RobinMalfait RobinMalfait changed the title [WIP] Add new in-* variant Add new in-* variant Nov 18, 2024

// Replace `&` in target variant with `*`, so variants like `&:hover`
// become `:where(*:hover) &`. The `*` will often be optimized away.
node.selector = `:where(${node.selector.replaceAll('&', '*')}) &`
Copy link
Member Author

Choose a reason for hiding this comment

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

This is basically the same implementation as the has-* variant, but the selector is a bit different.

@RobinMalfait RobinMalfait marked this pull request as ready for review November 18, 2024 11:25
@RobinMalfait RobinMalfait requested a review from a team as a code owner November 18, 2024 11:25
Copy link
Contributor

@thecrypticace thecrypticace left a comment

Choose a reason for hiding this comment

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

Need to make sure suggestions work for in-*

packages/tailwindcss/src/variants.ts Show resolved Hide resolved
thecrypticace
thecrypticace previously approved these changes Nov 18, 2024
@RobinMalfait RobinMalfait force-pushed the feat/in-variant branch 2 times, most recently from cbff570 to b189e55 Compare November 18, 2024 15:17
@RobinMalfait RobinMalfait dismissed thecrypticace’s stale review November 18, 2024 15:18

Removed codemods for migrating group-[]:flex until we handle prefixes

@RobinMalfait RobinMalfait enabled auto-merge (squash) November 18, 2024 15:18
@RobinMalfait RobinMalfait merged commit dd3441b into next Nov 18, 2024
1 check passed
@RobinMalfait RobinMalfait deleted the feat/in-variant branch November 18, 2024 15:28
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.

3 participants