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 support for custom variants via CSS #13992

Merged
merged 25 commits into from
Jul 16, 2024
Merged

Conversation

RobinMalfait
Copy link
Member

This PR adds support for custom variants, both via CSS and JS.

We can define simple variants:

Via CSS:

@variant foo (.foo &);

Or via JS:

addVariant('foo', '.foo &')

We can define simple parallel variants:

Via CSS:

@variant hocus (&:focus, &:hover);

Or via JS:

addVariant('hocus', ['&:focus', '&:hover'])

But we can also define more complex variants where you might want to use media queries and selectors and nesting and anything you want.

This also introduces a placeholder value named @slot that you can use to mark a specific spot where existing utilities and/or variants will be injected.

Via CSS:

@variant strict-hover {
  @media (hover: hover) {
    &:hover {
      @slot;
    }
  }
}

Or via JS:

addVariant('strict-hover', {
  '@media (hover: hover)': {
    '&:hover': '@slot',
  }
})

@RobinMalfait RobinMalfait changed the title Add support for custom variants Add support for custom variants via CSS Jul 11, 2024
@thecrypticace thecrypticace merged commit 5ebd589 into next Jul 16, 2024
1 check passed
@thecrypticace thecrypticace deleted the feat/custom-variants branch July 16, 2024 20:23
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