Skip to content

Commit 54aa5be

Browse files
authored
Return rgb values if the opacity core plugins are disabled (#3984)
1 parent fbc0f2f commit 54aa5be

8 files changed

+139
-30
lines changed

jit/corePlugins/backgroundColor.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const flattenColorPalette = require('../../lib/util/flattenColorPalette').defaul
22
const withAlphaVariable = require('../../lib/util/withAlphaVariable').default
33
const { asColor, nameClass } = require('../pluginUtils')
44

5-
module.exports = function ({ matchUtilities, theme }) {
5+
module.exports = function ({ corePlugins, matchUtilities, theme }) {
66
let colorPalette = flattenColorPalette(theme('backgroundColor'))
77

88
matchUtilities({
@@ -13,13 +13,17 @@ module.exports = function ({ matchUtilities, theme }) {
1313
return []
1414
}
1515

16-
return {
17-
[nameClass('bg', modifier)]: withAlphaVariable({
18-
color: value,
19-
property: 'background-color',
20-
variable: '--tw-bg-opacity',
21-
}),
16+
if (corePlugins('backgroundOpacity')) {
17+
return {
18+
[nameClass('bg', modifier)]: withAlphaVariable({
19+
color: value,
20+
property: 'background-color',
21+
variable: '--tw-bg-opacity',
22+
}),
23+
}
2224
}
25+
26+
return { [nameClass('bg', modifier)]: { 'background-color': value } }
2327
},
2428
})
2529
}

jit/corePlugins/borderColor.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const flattenColorPalette = require('../../lib/util/flattenColorPalette').defaul
22
const withAlphaVariable = require('../../lib/util/withAlphaVariable').default
33
const { asColor, nameClass } = require('../pluginUtils')
44

5-
module.exports = function ({ matchUtilities, theme }) {
5+
module.exports = function ({ corePlugins, matchUtilities, theme }) {
66
let colorPalette = flattenColorPalette(theme('borderColor'))
77

88
matchUtilities({
@@ -17,12 +17,18 @@ module.exports = function ({ matchUtilities, theme }) {
1717
return []
1818
}
1919

20+
if (corePlugins('borderOpacity')) {
21+
return {
22+
[nameClass('border', modifier)]: withAlphaVariable({
23+
color: value,
24+
property: 'border-color',
25+
variable: '--tw-border-opacity',
26+
}),
27+
}
28+
}
29+
2030
return {
21-
[nameClass('border', modifier)]: withAlphaVariable({
22-
color: value,
23-
property: 'border-color',
24-
variable: '--tw-border-opacity',
25-
}),
31+
[nameClass('border', modifier)]: { 'border-color': value },
2632
}
2733
},
2834
})

jit/corePlugins/divideColor.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const flattenColorPalette = require('../../lib/util/flattenColorPalette').defaul
22
const withAlphaVariable = require('../../lib/util/withAlphaVariable').default
33
const { asColor, nameClass } = require('../pluginUtils')
44

5-
module.exports = function ({ matchUtilities, theme }) {
5+
module.exports = function ({ corePlugins, matchUtilities, theme }) {
66
let colorPalette = flattenColorPalette(theme('divideColor'))
77

88
// TODO: Make sure there is no issue with DEFAULT here
@@ -14,12 +14,20 @@ module.exports = function ({ matchUtilities, theme }) {
1414
return []
1515
}
1616

17+
if (corePlugins('divideOpacity')) {
18+
return {
19+
[`${nameClass('divide', modifier)} > :not([hidden]) ~ :not([hidden])`]: withAlphaVariable({
20+
color: colorPalette[modifier],
21+
property: 'border-color',
22+
variable: '--tw-divide-opacity',
23+
}),
24+
}
25+
}
26+
1727
return {
18-
[`${nameClass('divide', modifier)} > :not([hidden]) ~ :not([hidden])`]: withAlphaVariable({
19-
color: colorPalette[modifier],
20-
property: 'border-color',
21-
variable: '--tw-divide-opacity',
22-
}),
28+
[`${nameClass('divide', modifier)} > :not([hidden]) ~ :not([hidden])`]: {
29+
'border-color': value,
30+
},
2331
}
2432
},
2533
})

jit/corePlugins/placeholderColor.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const flattenColorPalette = require('../../lib/util/flattenColorPalette').defaul
22
const withAlphaVariable = require('../../lib/util/withAlphaVariable').default
33
const { asColor, nameClass } = require('../pluginUtils')
44

5-
module.exports = function ({ matchUtilities, theme }) {
5+
module.exports = function ({ corePlugins, matchUtilities, theme }) {
66
let colorPalette = flattenColorPalette(theme('placeholderColor'))
77

88
matchUtilities({
@@ -13,12 +13,18 @@ module.exports = function ({ matchUtilities, theme }) {
1313
return []
1414
}
1515

16+
if (corePlugins('placeholderOpacity')) {
17+
return {
18+
[`${nameClass('placeholder', modifier)}::placeholder`]: withAlphaVariable({
19+
color: value,
20+
property: 'color',
21+
variable: '--tw-placeholder-opacity',
22+
}),
23+
}
24+
}
25+
1626
return {
17-
[`${nameClass('placeholder', modifier)}::placeholder`]: withAlphaVariable({
18-
color: value,
19-
property: 'color',
20-
variable: '--tw-placeholder-opacity',
21-
}),
27+
[`${nameClass('placeholder', modifier)}::placeholder`]: { color: value },
2228
}
2329
},
2430
})

jit/corePlugins/textColor.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ module.exports = function ({ matchUtilities, theme }) {
1313
return []
1414
}
1515

16+
if (corePlugins('textOpacity')) {
17+
return {
18+
[nameClass('text', modifier)]: withAlphaVariable({
19+
color: value,
20+
property: 'color',
21+
variable: '--tw-text-opacity',
22+
}),
23+
}
24+
}
25+
1626
return {
17-
[nameClass('text', modifier)]: withAlphaVariable({
18-
color: value,
19-
property: 'color',
20-
variable: '--tw-text-opacity',
21-
}),
27+
[nameClass('text', modifier)]: { color: value },
2228
}
2329
},
2430
})

jit/tests/opacity.test.css

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
* {
2+
--tw-shadow: 0 0 #0000;
3+
--tw-ring-inset: var(--tw-empty, /*!*/ /*!*/);
4+
--tw-ring-offset-width: 0px;
5+
--tw-ring-offset-color: #fff;
6+
--tw-ring-color: rgba(59, 130, 246, 0.5);
7+
--tw-ring-offset-shadow: 0 0 #0000;
8+
--tw-ring-shadow: 0 0 #0000;
9+
}
10+
.divide-black > :not([hidden]) ~ :not([hidden]) {
11+
border-color: #000;
12+
}
13+
.border-black {
14+
border-color: #000;
15+
}
16+
.bg-black {
17+
background-color: #000;
18+
}
19+
.text-black {
20+
color: #000;
21+
}
22+
.placeholder-black::placeholder {
23+
color: #000;
24+
}

jit/tests/opacity.test.html

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" href="/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Title</title>
8+
<link rel="stylesheet" href="./tailwind.css" />
9+
</head>
10+
<body>
11+
<div class="divide-black"></div>
12+
<div class="border-black"></div>
13+
<div class="bg-black"></div>
14+
<div class="text-black"></div>
15+
<div class="placeholder-black"></div>
16+
</body>
17+
</html>

jit/tests/opacity.test.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const postcss = require('postcss')
2+
const tailwind = require('../index.js')
3+
const fs = require('fs')
4+
const path = require('path')
5+
6+
function run(input, config = {}) {
7+
return postcss(tailwind(config)).process(input, { from: path.resolve(__filename) })
8+
}
9+
10+
test('opacity', () => {
11+
let config = {
12+
darkMode: 'class',
13+
purge: [path.resolve(__dirname, './opacity.test.html')],
14+
corePlugins: {
15+
backgroundOpacity: false,
16+
borderOpacity: false,
17+
divideOpacity: false,
18+
placeholderOpacity: false,
19+
preflight: false,
20+
textOpacity: false,
21+
},
22+
theme: {},
23+
plugins: [],
24+
}
25+
26+
let css = `
27+
@tailwind base;
28+
@tailwind components;
29+
@tailwind utilities;
30+
`
31+
32+
return run(css, config).then((result) => {
33+
let expectedPath = path.resolve(__dirname, './opacity.test.css')
34+
let expected = fs.readFileSync(expectedPath, 'utf8')
35+
36+
expect(result.css).toMatchCss(expected)
37+
})
38+
})

0 commit comments

Comments
 (0)