@@ -410,52 +410,58 @@ test('partial arbitrary variants', () => {
410
410
let config = {
411
411
content : [
412
412
{
413
- raw : html `
414
- <div class= "container-[sidebar] container-type-inline-size" >
415
- <div class= "contain-[sidebar,min:500px]:flex" > </ div>
416
- <div class= "contain-[sidebar,max:500px]:flex" > </ div>
417
- <div class= "contain-[min:500px]:flex" > </ div>
418
- <div class= "contain-[max:500px]:flex" > </ div>
419
- <div class= "contain-[500px]:flex" > </ div>
420
- </ div>
421
- ` ,
413
+ raw : html `<div class= "potato-[yellow]:bg-yellow-200 potato-[baked]:w-3" > </ div> ` ,
422
414
} ,
423
415
] ,
424
416
corePlugins : { preflight : false } ,
425
417
plugins : [
426
- ( { addUtilities, matchVariant, matchUtilities } ) => {
427
- addUtilities ( {
428
- '.container-type-size' : { 'container-type' : 'size' } ,
429
- '.container-type-inline-size' : { 'container-type' : 'inline-size' } ,
430
- '.container-type-block-size' : { 'container-type' : 'block-size' } ,
431
- '.container-type-style' : { 'container-type' : 'style' } ,
432
- '.container-type-state' : { 'container-type' : 'state' } ,
418
+ ( { matchVariant } ) => {
419
+ matchVariant ( {
420
+ potato : ( flavor ) => `.potato-${ flavor } &` ,
433
421
} )
422
+ } ,
423
+ ] ,
424
+ }
434
425
435
- matchUtilities ( {
436
- container : ( value ) => {
437
- return {
438
- 'container-name' : value ,
439
- }
440
- } ,
441
- } )
426
+ let input = css `
427
+ @tailwind utilities;
428
+ `
442
429
443
- matchVariant ( {
444
- contain : ( args ) => {
445
- if ( args . includes ( ',' ) ) {
446
- let [ name , query ] = args . split ( ',' )
447
- let [ type , value ] = query . split ( ':' )
448
- return `@container ${ name } (${
449
- { min : 'min-width' , max : 'max-width' } [ type ]
450
- } : ${ value } )`
451
- } else if ( args . includes ( ':' ) ) {
452
- let [ type , value ] = args . split ( ':' )
453
- return `@container (${ { min : 'min-width' , max : 'max-width' } [ type ] } : ${ value } )`
454
- } else {
455
- return `@container (min-width: ${ args } )`
456
- }
430
+ return run ( input , config ) . then ( ( result ) => {
431
+ expect ( result . css ) . toMatchFormattedCss ( css `
432
+ .potato-baked .potato-\[baked\]\:w-3 {
433
+ width : 0.75rem ;
434
+ }
435
+
436
+ .potato-yellow .potato-\[yellow\]\:bg-yellow-200 {
437
+ --tw-bg-opacity : 1 ;
438
+ background-color : rgb (254 240 138 / var (--tw-bg-opacity ));
439
+ }
440
+ ` )
441
+ } )
442
+ } )
443
+
444
+ test ( 'partial arbitrary variants with default values' , ( ) => {
445
+ let config = {
446
+ content : [
447
+ {
448
+ raw : html `<div class= "tooltip-bottom:mt-2 tooltip-top:mb-2" > </ div> ` ,
449
+ } ,
450
+ ] ,
451
+ corePlugins : { preflight : false } ,
452
+ plugins : [
453
+ ( { matchVariant } ) => {
454
+ matchVariant (
455
+ {
456
+ tooltip : ( side ) => `&${ side } ` ,
457
457
} ,
458
- } )
458
+ {
459
+ values : {
460
+ bottom : '[data-location="bottom"]' ,
461
+ top : '[data-location="top"]' ,
462
+ } ,
463
+ }
464
+ )
459
465
} ,
460
466
] ,
461
467
}
@@ -466,42 +472,66 @@ test('partial arbitrary variants', () => {
466
472
467
473
return run ( input , config ) . then ( ( result ) => {
468
474
expect ( result . css ) . toMatchFormattedCss ( css `
469
- .container-type-inline-size {
470
- container-type : inline-size ;
475
+ .tooltip-bottom\:mt-2 [ data-location = 'bottom' ] {
476
+ margin-top : 0.5 rem ;
471
477
}
472
478
473
- .container-\[sidebar \ ] {
474
- container-name : sidebar ;
479
+ .tooltip-top\:mb-2 [ data-location = 'top' ] {
480
+ margin-bottom : 0.5 rem ;
475
481
}
482
+ ` )
483
+ } )
484
+ } )
476
485
477
- @container sidebar (min-width : 500px ) {
478
- .contain-\[sidebar\2c min\:500px\]\:flex {
479
- display : flex;
480
- }
481
- }
486
+ test ( 'matched variant values maintain the sort order they are registered in' , ( ) => {
487
+ let config = {
488
+ content : [
489
+ {
490
+ raw : html `<div
491
+ class= "alphabet-c:underline alphabet-a:underline alphabet-d:underline alphabet-b:underline"
492
+ > </ div> ` ,
493
+ } ,
494
+ ] ,
495
+ corePlugins : { preflight : false } ,
496
+ plugins : [
497
+ ( { matchVariant } ) => {
498
+ matchVariant (
499
+ {
500
+ alphabet : ( side ) => `&${ side } ` ,
501
+ } ,
502
+ {
503
+ values : {
504
+ a : '[data-value="a"]' ,
505
+ b : '[data-value="b"]' ,
506
+ c : '[data-value="c"]' ,
507
+ d : '[data-value="d"]' ,
508
+ } ,
509
+ }
510
+ )
511
+ } ,
512
+ ] ,
513
+ }
482
514
483
- @container sidebar (max-width : 500px ) {
484
- .contain-\[sidebar\2c max\:500px\]\:flex {
485
- display : flex;
486
- }
515
+ let input = css `
516
+ @tailwind utilities;
517
+ `
518
+
519
+ return run ( input , config ) . then ( ( result ) => {
520
+ expect ( result . css ) . toMatchFormattedCss ( css `
521
+ .alphabet-a\:underline [data-value = 'a' ] {
522
+ text-decoration-line : underline;
487
523
}
488
524
489
- @container (min-width : 500px ) {
490
- .contain-\[min\:500px\]\:flex {
491
- display : flex;
492
- }
525
+ .alphabet-b\:underline [data-value = 'b' ] {
526
+ text-decoration-line : underline;
493
527
}
494
528
495
- @container (max-width : 500px ) {
496
- .contain-\[max\:500px\]\:flex {
497
- display : flex;
498
- }
529
+ .alphabet-c\:underline [data-value = 'c' ] {
530
+ text-decoration-line : underline;
499
531
}
500
532
501
- @container (min-width : 500px ) {
502
- .contain-\[500px\]\:flex {
503
- display : flex;
504
- }
533
+ .alphabet-d\:underline [data-value = 'd' ] {
534
+ text-decoration-line : underline;
505
535
}
506
536
` )
507
537
} )
0 commit comments