Skip to content

Commit 35b7bb1

Browse files
committed
Support closures for colors in all circumstances (#2536)
1 parent a6729cc commit 35b7bb1

17 files changed

+431
-23
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import invokePlugin from '../util/invokePlugin'
2+
import plugin from '../../src/plugins/backgroundColor'
3+
4+
test('defining color as a function', () => {
5+
const config = {
6+
target: 'relaxed',
7+
theme: {
8+
backgroundColor: {
9+
black: ({ opacityVariable: _ }) => 'black',
10+
},
11+
},
12+
variants: {
13+
backgroundColor: [],
14+
},
15+
}
16+
17+
const { utilities } = invokePlugin(plugin(), config)
18+
19+
expect(utilities).toEqual([
20+
[
21+
{
22+
'.bg-black': {
23+
'background-color': 'black',
24+
},
25+
},
26+
[],
27+
],
28+
])
29+
})
30+
31+
test('defining color as a function in ie11 mode', () => {
32+
const config = {
33+
target: 'ie11',
34+
theme: {
35+
backgroundColor: {
36+
black: ({ opacityVariable: _ }) => 'black',
37+
},
38+
},
39+
variants: {
40+
backgroundColor: [],
41+
},
42+
}
43+
44+
const { utilities } = invokePlugin(plugin(), config)
45+
46+
expect(utilities).toEqual([
47+
[
48+
{
49+
'.bg-black': {
50+
'background-color': 'black',
51+
},
52+
},
53+
[],
54+
],
55+
])
56+
})

__tests__/plugins/borderColor.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import invokePlugin from '../util/invokePlugin'
2+
import plugin from '../../src/plugins/borderColor'
3+
4+
test('defining color as a function', () => {
5+
const config = {
6+
target: 'relaxed',
7+
theme: {
8+
borderColor: {
9+
black: ({ opacityVariable: _ }) => 'black',
10+
},
11+
},
12+
variants: {
13+
borderColor: [],
14+
},
15+
}
16+
17+
const { utilities } = invokePlugin(plugin(), config)
18+
19+
expect(utilities).toEqual([
20+
[
21+
{
22+
'.border-black': {
23+
'border-color': 'black',
24+
},
25+
},
26+
[],
27+
],
28+
])
29+
})
30+
31+
test('defining color as a function in ie11 mode', () => {
32+
const config = {
33+
target: 'ie11',
34+
theme: {
35+
borderColor: {
36+
black: ({ opacityVariable: _ }) => 'black',
37+
},
38+
},
39+
variants: {
40+
borderColor: [],
41+
},
42+
}
43+
44+
const { utilities } = invokePlugin(plugin(), config)
45+
46+
expect(utilities).toEqual([
47+
[
48+
{
49+
'.border-black': {
50+
'border-color': 'black',
51+
},
52+
},
53+
[],
54+
],
55+
])
56+
})

__tests__/plugins/divideColor.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import invokePlugin from '../util/invokePlugin'
2+
import plugin from '../../src/plugins/divideColor'
3+
4+
test('defining color as a function', () => {
5+
const config = {
6+
target: 'relaxed',
7+
theme: {
8+
divideColor: {
9+
black: ({ opacityVariable: _ }) => 'black',
10+
},
11+
},
12+
variants: {
13+
divideColor: [],
14+
},
15+
}
16+
17+
const { utilities } = invokePlugin(plugin(), config)
18+
19+
expect(utilities).toEqual([
20+
[
21+
{
22+
'.divide-black > :not(template) ~ :not(template)': {
23+
'border-color': 'black',
24+
},
25+
},
26+
[],
27+
],
28+
])
29+
})
30+
31+
test('defining color as a function in ie11 mode', () => {
32+
const config = {
33+
target: 'ie11',
34+
theme: {
35+
divideColor: {
36+
black: ({ opacityVariable: _ }) => 'black',
37+
},
38+
},
39+
variants: {
40+
divideColor: [],
41+
},
42+
}
43+
44+
const { utilities } = invokePlugin(plugin(), config)
45+
46+
expect(utilities).toEqual([
47+
[
48+
{
49+
'.divide-black > :not(template) ~ :not(template)': {
50+
'border-color': 'black',
51+
},
52+
},
53+
[],
54+
],
55+
])
56+
})

__tests__/plugins/fill.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import invokePlugin from '../util/invokePlugin'
2+
import plugin from '../../src/plugins/fill'
3+
4+
test('defining color as a function', () => {
5+
const config = {
6+
target: 'relaxed',
7+
theme: {
8+
fill: {
9+
black: ({ opacityVariable: _ }) => 'black',
10+
},
11+
},
12+
variants: {
13+
fill: [],
14+
},
15+
}
16+
17+
const { utilities } = invokePlugin(plugin(), config)
18+
19+
expect(utilities).toEqual([
20+
[
21+
{
22+
'.fill-black': {
23+
fill: 'black',
24+
},
25+
},
26+
[],
27+
],
28+
])
29+
})
30+
31+
test('defining color as a function in ie11 mode', () => {
32+
const config = {
33+
target: 'ie11',
34+
theme: {
35+
fill: {
36+
black: ({ opacityVariable: _ }) => 'black',
37+
},
38+
},
39+
variants: {
40+
fill: [],
41+
},
42+
}
43+
44+
const { utilities } = invokePlugin(plugin(), config)
45+
46+
expect(utilities).toEqual([
47+
[
48+
{
49+
'.fill-black': {
50+
fill: 'black',
51+
},
52+
},
53+
[],
54+
],
55+
])
56+
})
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import invokePlugin from '../util/invokePlugin'
2+
import plugin from '../../src/plugins/placeholderColor'
3+
4+
test('defining color as a function', () => {
5+
const config = {
6+
target: 'relaxed',
7+
theme: {
8+
placeholderColor: {
9+
black: ({ opacityVariable: _ }) => 'black',
10+
},
11+
},
12+
variants: {
13+
placeholderColor: [],
14+
},
15+
}
16+
17+
const { utilities } = invokePlugin(plugin(), config)
18+
19+
expect(utilities).toEqual([
20+
[
21+
{
22+
'.placeholder-black::placeholder': {
23+
color: 'black',
24+
},
25+
},
26+
[],
27+
],
28+
])
29+
})
30+
31+
test('defining color as a function in ie11 mode', () => {
32+
const config = {
33+
target: 'ie11',
34+
theme: {
35+
placeholderColor: {
36+
black: ({ opacityVariable: _ }) => 'black',
37+
},
38+
},
39+
variants: {
40+
placeholderColor: [],
41+
},
42+
}
43+
44+
const { utilities } = invokePlugin(plugin(), config)
45+
46+
expect(utilities).toEqual([
47+
[
48+
{
49+
'.placeholder-black::placeholder': {
50+
color: 'black',
51+
},
52+
},
53+
[],
54+
],
55+
])
56+
})

__tests__/plugins/stroke.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import invokePlugin from '../util/invokePlugin'
2+
import plugin from '../../src/plugins/stroke'
3+
4+
test('defining color as a function', () => {
5+
const config = {
6+
target: 'relaxed',
7+
theme: {
8+
stroke: {
9+
black: ({ opacityVariable: _ }) => 'black',
10+
},
11+
},
12+
variants: {
13+
stroke: [],
14+
},
15+
}
16+
17+
const { utilities } = invokePlugin(plugin(), config)
18+
19+
expect(utilities).toEqual([
20+
[
21+
{
22+
'.stroke-black': {
23+
stroke: 'black',
24+
},
25+
},
26+
[],
27+
],
28+
])
29+
})
30+
31+
test('defining color as a function in ie11 mode', () => {
32+
const config = {
33+
target: 'ie11',
34+
theme: {
35+
stroke: {
36+
black: ({ opacityVariable: _ }) => 'black',
37+
},
38+
},
39+
variants: {
40+
stroke: [],
41+
},
42+
}
43+
44+
const { utilities } = invokePlugin(plugin(), config)
45+
46+
expect(utilities).toEqual([
47+
[
48+
{
49+
'.stroke-black': {
50+
stroke: 'black',
51+
},
52+
},
53+
[],
54+
],
55+
])
56+
})

__tests__/plugins/textColor.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import invokePlugin from '../util/invokePlugin'
2+
import plugin from '../../src/plugins/textColor'
3+
4+
test('defining color as a function', () => {
5+
const config = {
6+
target: 'relaxed',
7+
theme: {
8+
textColor: {
9+
black: ({ opacityVariable: _ }) => 'black',
10+
},
11+
},
12+
variants: {
13+
textColor: [],
14+
},
15+
}
16+
17+
const { utilities } = invokePlugin(plugin(), config)
18+
19+
expect(utilities).toEqual([
20+
[
21+
{
22+
'.text-black': {
23+
color: 'black',
24+
},
25+
},
26+
[],
27+
],
28+
])
29+
})
30+
31+
test('defining color as a function in ie11 mode', () => {
32+
const config = {
33+
target: 'ie11',
34+
theme: {
35+
textColor: {
36+
black: ({ opacityVariable: _ }) => 'black',
37+
},
38+
},
39+
variants: {
40+
textColor: [],
41+
},
42+
}
43+
44+
const { utilities } = invokePlugin(plugin(), config)
45+
46+
expect(utilities).toEqual([
47+
[
48+
{
49+
'.text-black': {
50+
color: 'black',
51+
},
52+
},
53+
[],
54+
],
55+
])
56+
})

0 commit comments

Comments
 (0)