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

Polish matchVariant API #9313

Merged
merged 3 commits into from
Sep 16, 2022
Merged

Polish matchVariant API #9313

merged 3 commits into from
Sep 16, 2022

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Sep 12, 2022

This PR will polish the currently unreleased matchVariant API. This API will allow you to create
dynamic variants. E.g.: supports-[display:grid]:grid.

The API looks very similar to the addVariant API, but with a callback instead.

An example for demonstrating the API:

matchVariant('supports', ({ value }) => `@supports(${value})`, {
  values: {
    grid: 'display: grid', // Allows us to use just `supports-grid`
  },
})

Input:

<div class="supports-grid:grid supports-[color:red]:text-red-500"></div> 

Output:

@supports (display: grid) {
  .supports-grid\:grid {
    display: grid;
  }
}

@supports (color: red) {
  .supports-\[color\:red\]\:text-red-500 {
    --tw-text-opacity: 1;
    color: rgb(239 68 68 / var(--tw-text-opacity));
  }
}

Note: the API is still subject to change, this is currently a placeholder.

With the biggest difference that the `matchVariant` will have a callback
function that receives the current value of the variant.
This will allow us to add more properties in the future if needed
without breaking changes.

- This is a breaking change: `(value) => ...` -> `({ value, other }) => ...`
- This is **not** a breaking change: `({ value }) => ...` -> `({ value, other }) => ...`
@RobinMalfait RobinMalfait merged commit 4fddd2d into master Sep 16, 2022
@RobinMalfait RobinMalfait deleted the feat/match-variant-api branch September 16, 2022 13:37
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.

1 participant