Skip to content

Commit a7e19ca

Browse files
committed
Pass opacityValue to gradient colors for transparency support, do not pass opacityVariable since unused
1 parent 28930f4 commit a7e19ca

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

__tests__/plugins/gradientColorStops.test.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,49 @@ test('opacity variables are given to colors defined as closures', () => {
66
tailwind({
77
theme: {
88
colors: {
9-
primary: ({ opacityVariable }) => `rgba(31,31,31,var(${opacityVariable},1))`,
9+
primary: ({ opacityVariable, opacityValue }) => {
10+
if (opacityValue !== undefined) {
11+
return `rgba(31,31,31,${opacityValue})`
12+
}
13+
14+
if (opacityVariable !== undefined) {
15+
return `rgba(31,31,31,var(${opacityVariable},1))`
16+
}
17+
18+
return `rgb(31,31,31)`
19+
},
20+
},
21+
opacity: {
22+
'50': '0.5',
1023
},
1124
},
1225
variants: {
26+
textColor: [],
27+
textOpacity: [],
1328
gradientColorStops: [],
1429
},
15-
corePlugins: ['gradientColorStops'],
30+
corePlugins: ['textColor', 'textOpacity', 'gradientColorStops'],
1631
}),
1732
])
1833
.process('@tailwind utilities', { from: undefined })
1934
.then(result => {
2035
const expected = `
36+
.text-primary {
37+
color: rgba(31,31,31,var(--text-opacity,1))
38+
}
39+
.text-opacity-50 {
40+
--text-opacity: 0.5
41+
}
2142
.from-primary {
22-
--gradient-from-color: rgba(31,31,31,var(--gradient-from-opacity,1));
23-
--gradient-color-stops: var(--gradient-from-color), var(--gradient-to-color, rgba(255, 255, 255, 0))
43+
--gradient-from-color: rgb(31,31,31);
44+
--gradient-color-stops: var(--gradient-from-color), var(--gradient-to-color, rgba(31, 31, 31, 0))
2445
}
25-
2646
.via-primary {
27-
--gradient-via-color: rgba(31,31,31,var(--gradient-via-opacity,1));
28-
--gradient-color-stops: var(--gradient-from-color), var(--gradient-via-color), var(--gradient-to-color, rgba(255, 255, 255, 0))
47+
--gradient-via-color: rgb(31,31,31);
48+
--gradient-color-stops: var(--gradient-from-color), var(--gradient-via-color), var(--gradient-to-color, rgba(31, 31, 31, 0))
2949
}
30-
3150
.to-primary {
32-
--gradient-to-color: rgba(31,31,31,var(--gradient-to-opacity,1))
51+
--gradient-to-color: rgb(31,31,31)
3352
}
3453
`
3554

src/plugins/gradientColorStops.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ export default function() {
1212

1313
const utilities = _(colors)
1414
.map((value, modifier) => {
15-
const getColorValue = (color, type) => {
15+
const getColorValue = color => {
1616
if (_.isFunction(color)) {
17-
return value({
18-
opacityVariable: `--gradient-${type}-opacity`,
19-
})
17+
return value({})
2018
}
2119

2220
return color
2321
}
2422

2523
const transparentTo = (() => {
24+
if (_.isFunction(value)) {
25+
return value({ opacityValue: 0 })
26+
}
27+
2628
try {
2729
const [r, g, b] = toRgba(value)
2830
return `rgba(${r}, ${g}, ${b}, 0)`

0 commit comments

Comments
 (0)