Skip to content

Commit 34fd0fb

Browse files
committed
Feature flag matchVariant API
1 parent d2fdf9e commit 34fd0fb

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/featureFlags.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let defaults = {
77

88
let featureFlags = {
99
future: ['hoverOnlyWhenSupported', 'respectDefaultRingColorOpacity'],
10-
experimental: ['optimizeUniversalDefaults', 'variantGrouping'],
10+
experimental: ['optimizeUniversalDefaults', 'variantGrouping', 'matchVariant'],
1111
}
1212

1313
export function flagEnabled(config, flag) {

src/lib/setupContextUtils.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import postcss from 'postcss'
44
import dlv from 'dlv'
55
import selectorParser from 'postcss-selector-parser'
66

7+
import { flagEnabled } from '../featureFlags.js'
78
import transformThemeValue from '../util/transformThemeValue'
89
import parseObjectStyles from '../util/parseObjectStyles'
910
import prefixSelector from '../util/prefixSelector'
@@ -484,7 +485,10 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
484485
insertInto(variantList, variantName, options)
485486
variantMap.set(variantName, variantFunctions)
486487
},
487-
matchVariant: function (variants, options) {
488+
}
489+
490+
if (flagEnabled(tailwindConfig, 'matchVariant')) {
491+
api.matchVariant = function (variants, options) {
488492
for (let variant in variants) {
489493
for (let [k, v] of Object.entries(options?.values ?? {})) {
490494
api.addVariant(`${variant}-${k}`, variants[variant](v))
@@ -496,7 +500,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
496500
options
497501
)
498502
}
499-
},
503+
}
500504
}
501505

502506
return api

tests/match-variants.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { run, html, css } from './util/run'
22

33
test('partial arbitrary variants', () => {
44
let config = {
5+
experimental: { matchVariant: true },
56
content: [
67
{
78
raw: html`<div class="potato-[yellow]:bg-yellow-200 potato-[baked]:w-3"></div> `,
@@ -37,6 +38,7 @@ test('partial arbitrary variants', () => {
3738

3839
test('partial arbitrary variants with at-rules', () => {
3940
let config = {
41+
experimental: { matchVariant: true },
4042
content: [
4143
{
4244
raw: html`<div class="potato-[yellow]:bg-yellow-200 potato-[baked]:w-3"></div> `,
@@ -75,6 +77,7 @@ test('partial arbitrary variants with at-rules', () => {
7577

7678
test('partial arbitrary variants with at-rules and placeholder', () => {
7779
let config = {
80+
experimental: { matchVariant: true },
7881
content: [
7982
{
8083
raw: html`<div class="potato-[yellow]:bg-yellow-200 potato-[baked]:w-3"></div> `,
@@ -113,6 +116,7 @@ test('partial arbitrary variants with at-rules and placeholder', () => {
113116

114117
test('partial arbitrary variants with default values', () => {
115118
let config = {
119+
experimental: { matchVariant: true },
116120
content: [
117121
{
118122
raw: html`<div class="tooltip-bottom:mt-2 tooltip-top:mb-2"></div>`,
@@ -155,6 +159,7 @@ test('partial arbitrary variants with default values', () => {
155159

156160
test('matched variant values maintain the sort order they are registered in', () => {
157161
let config = {
162+
experimental: { matchVariant: true },
158163
content: [
159164
{
160165
raw: html`<div
@@ -209,6 +214,7 @@ test('matched variant values maintain the sort order they are registered in', ()
209214

210215
test('matchVariant can return an array of format strings from the function', () => {
211216
let config = {
217+
experimental: { matchVariant: true },
212218
content: [
213219
{
214220
raw: html`<div class="test-[a,b,c]:underline"></div>`,

0 commit comments

Comments
 (0)