@@ -96,7 +96,7 @@ test('colors defined as functions work when opacity plugins are disabled', () =>
96
96
} )
97
97
} )
98
98
99
- it ( 'can use rgb helper when defining custom properties for colors (opacity plugins enabled)' , ( ) => {
99
+ it ( 'can use <alpha-value> defining custom properties for colors (opacity plugins enabled)' , ( ) => {
100
100
let config = {
101
101
content : [
102
102
{
@@ -117,9 +117,9 @@ it('can use rgb helper when defining custom properties for colors (opacity plugi
117
117
} ,
118
118
] ,
119
119
theme : {
120
- colors : ( { rgb } ) => ( {
121
- primary : rgb ( ' --color-primary' ) ,
122
- } ) ,
120
+ colors : {
121
+ primary : ' rgb(var( --color-primary) / <alpha-value>)' ,
122
+ } ,
123
123
} ,
124
124
}
125
125
@@ -192,9 +192,9 @@ it('can use rgb helper when defining custom properties for colors (opacity plugi
192
192
} ,
193
193
] ,
194
194
theme : {
195
- colors : ( { rgb } ) => ( {
196
- primary : rgb ( ' --color-primary' ) ,
197
- } ) ,
195
+ colors : {
196
+ primary : ' rgb(var( --color-primary) / <alpha-value>)' ,
197
+ } ,
198
198
} ,
199
199
corePlugins : {
200
200
backgroundOpacity : false ,
@@ -269,9 +269,9 @@ it('can use hsl helper when defining custom properties for colors (opacity plugi
269
269
} ,
270
270
] ,
271
271
theme : {
272
- colors : ( { hsl } ) => ( {
273
- primary : hsl ( ' --color-primary' ) ,
274
- } ) ,
272
+ colors : {
273
+ primary : ' hsl(var( --color-primary) / <alpha-value>)' ,
274
+ } ,
275
275
} ,
276
276
}
277
277
@@ -344,9 +344,9 @@ it('can use hsl helper when defining custom properties for colors (opacity plugi
344
344
} ,
345
345
] ,
346
346
theme : {
347
- colors : ( { hsl } ) => ( {
348
- primary : hsl ( ' --color-primary' ) ,
349
- } ) ,
347
+ colors : {
348
+ primary : ' hsl(var( --color-primary) / <alpha-value>)' ,
349
+ } ,
350
350
} ,
351
351
corePlugins : {
352
352
backgroundOpacity : false ,
@@ -400,34 +400,6 @@ it('can use hsl helper when defining custom properties for colors (opacity plugi
400
400
} )
401
401
} )
402
402
403
- it ( 'the rgb helper throws when not passing custom properties' , ( ) => {
404
- let config = {
405
- theme : {
406
- colors : ( { rgb } ) => ( {
407
- primary : rgb ( 'anything else' ) ,
408
- } ) ,
409
- } ,
410
- }
411
-
412
- return expect ( run ( '@tailwind utilities' , config ) ) . rejects . toThrow (
413
- 'The rgb() helper requires a custom property name to be passed as the first argument.'
414
- )
415
- } )
416
-
417
- it ( 'the hsl helper throws when not passing custom properties' , ( ) => {
418
- let config = {
419
- theme : {
420
- colors : ( { hsl } ) => ( {
421
- primary : hsl ( 'anything else' ) ,
422
- } ) ,
423
- } ,
424
- }
425
-
426
- return expect ( run ( '@tailwind utilities' , config ) ) . rejects . toThrow (
427
- 'The hsl() helper requires a custom property name to be passed as the first argument.'
428
- )
429
- } )
430
-
431
403
test ( 'Theme function in JS can apply alpha values to colors (1)' , ( ) => {
432
404
let input = css `
433
405
@tailwind utilities;
@@ -611,11 +583,11 @@ test('Theme function in JS can apply alpha values to colors (7)', () => {
611
583
content : [ { raw : html `text-foo` } ] ,
612
584
corePlugins : { textOpacity : false } ,
613
585
theme : {
614
- colors : ( { rgb } ) => ( {
586
+ colors : {
615
587
blue : {
616
- 500 : rgb ( ' --foo' ) ,
588
+ 500 : ' rgb(var( --foo) / <alpha-value>)' ,
617
589
} ,
618
- } ) ,
590
+ } ,
619
591
extend : {
620
592
textColor : ( { theme } ) => ( {
621
593
foo : theme ( 'colors.blue.500 / var(--my-alpha)' ) ,
@@ -659,3 +631,100 @@ test('Theme function prefers existing values in config', () => {
659
631
expect ( result . warnings ( ) . length ) . toBe ( 0 )
660
632
} )
661
633
} )
634
+
635
+ it ( 'should be possible to use an <alpha-value> as part of the color definition' , ( ) => {
636
+ let config = {
637
+ content : [
638
+ {
639
+ raw : html ` <div class= "bg- primary"> </ div> ` ,
640
+ } ,
641
+ ] ,
642
+ corePlugins : [ 'backgroundColor' , 'backgroundOpacity' ] ,
643
+ theme : {
644
+ colors : {
645
+ primary : 'rgb(var(--color-primary) / <alpha-value>)' ,
646
+ } ,
647
+ } ,
648
+ }
649
+
650
+ return run ( '@tailwind utilities' , config ) . then ( ( result ) => {
651
+ expect ( result . css ) . toMatchCss ( css `
652
+ .bg-primary {
653
+ --tw-bg-opacity : 1 ;
654
+ background-color : rgb (var (--color-primary ) / var (--tw-bg-opacity ));
655
+ }
656
+ ` )
657
+ } )
658
+ } )
659
+
660
+ it ( 'should be possible to use an <alpha-value> as part of the color definition with an opacity modifiers' , ( ) => {
661
+ let config = {
662
+ content : [
663
+ {
664
+ raw : html ` <div class= "bg-primary/50" > </ div> ` ,
665
+ } ,
666
+ ] ,
667
+ corePlugins : [ 'backgroundColor' , 'backgroundOpacity' ] ,
668
+ theme : {
669
+ colors : {
670
+ primary : 'rgb(var(--color-primary) / <alpha-value>)' ,
671
+ } ,
672
+ } ,
673
+ }
674
+
675
+ return run ( '@tailwind utilities' , config ) . then ( ( result ) => {
676
+ expect ( result . css ) . toMatchCss ( css `
677
+ .bg-primary\/50 {
678
+ background-color : rgb (var (--color-primary ) / 0.5 );
679
+ }
680
+ ` )
681
+ } )
682
+ } )
683
+
684
+ it ( 'should be possible to use an <alpha-value> as part of the color definition with an opacity modifiers' , ( ) => {
685
+ let config = {
686
+ content : [
687
+ {
688
+ raw : html ` <div class= "bg-primary" > </ div> ` ,
689
+ } ,
690
+ ] ,
691
+ corePlugins : [ 'backgroundColor' ] ,
692
+ theme : {
693
+ colors : {
694
+ primary : 'rgb(var(--color-primary) / <alpha-value>)' ,
695
+ } ,
696
+ } ,
697
+ }
698
+
699
+ return run ( '@tailwind utilities' , config ) . then ( ( result ) => {
700
+ expect ( result . css ) . toMatchCss ( css `
701
+ .bg-primary {
702
+ background-color : rgb (var (--color-primary ) / 1 );
703
+ }
704
+ ` )
705
+ } )
706
+ } )
707
+
708
+ it ( 'should be possible to use <alpha-value> inside arbitrary values' , ( ) => {
709
+ let config = {
710
+ content : [
711
+ {
712
+ raw : html ` <div class= "bg-[rgb(var(--color-primary)/<alpha-value>)]/50" > </ div> ` ,
713
+ } ,
714
+ ] ,
715
+ corePlugins : [ 'backgroundColor' , 'backgroundOpacity' ] ,
716
+ theme : {
717
+ colors : {
718
+ primary : 'rgb(var(--color-primary) / <alpha-value>)' ,
719
+ } ,
720
+ } ,
721
+ }
722
+
723
+ return run ( '@tailwind utilities' , config ) . then ( ( result ) => {
724
+ expect ( result . css ) . toMatchCss ( css `
725
+ .bg-\[rgb\(var\(--color-primary\)\/\<alpha-value\>\)\]\/50 {
726
+ background-color : rgb (var (--color-primary ) / 0.5 );
727
+ }
728
+ ` )
729
+ } )
730
+ } )
0 commit comments