Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Commit a3d92c0

Browse files
authored
Merge pull request #9 from tailwindlabs/new-plugin-return-signature
Update plugins to new return signature
2 parents f7129d5 + 1030119 commit a3d92c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1278
-1603
lines changed

src/corePlugins/animation.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
const nameClass = require('tailwindcss/lib/util/nameClass').default
22
const transformThemeValue = require('tailwindcss/lib/util/transformThemeValue').default
33
const parseAnimationValue = require('tailwindcss/lib/util/parseAnimationValue').default
4+
const { newFormat } = require('../pluginUtils')
45

5-
module.exports = function ({ jit: { theme, addUtilities } }) {
6+
module.exports = function ({ matchUtilities, jit: { theme } }) {
67
let keyframes = Object.fromEntries(
78
Object.entries(theme.keyframes).map(([key, value]) => {
89
return [
910
key,
1011
[
11-
`@keyframes ${key}`,
12-
Object.entries(value).map(([key, value]) => {
13-
return [key, value]
14-
}),
12+
{
13+
[`@keyframes ${key}`]: value,
14+
},
15+
{ respectVariants: false },
1516
],
16-
{ respectVariants: false },
1717
]
1818
})
1919
)
2020

2121
let transformValue = transformThemeValue('animation')
22-
addUtilities({
22+
matchUtilities({
2323
animate: [
2424
(modifier, { theme }) => {
2525
let value = transformValue(theme.animation[modifier])
@@ -30,7 +30,10 @@ module.exports = function ({ jit: { theme, addUtilities } }) {
3030

3131
let { name: animationName } = parseAnimationValue(value)
3232

33-
return [keyframes[animationName], [nameClass('animate', modifier), { animation: value }]]
33+
return [
34+
keyframes[animationName],
35+
{ [nameClass('animate', modifier)]: { animation: value } },
36+
]
3437
},
3538
],
3639
})

src/corePlugins/backgroundColor.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,24 @@ const withAlphaVariable = require('tailwindcss/lib/util/withAlphaVariable').defa
55
const toColorValue = require('tailwindcss/lib/util/toColorValue').default
66
const { asColor } = require('../pluginUtils')
77

8-
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
8+
module.exports = function ({ matchUtilities, jit: { theme } }) {
99
let colorPalette = flattenColorPalette(theme.backgroundColor)
1010

11-
addUtilities({
12-
bg: [
13-
(modifier, { theme }) => {
14-
let value = asColor(modifier, colorPalette)
11+
matchUtilities({
12+
bg: (modifier, { theme }) => {
13+
let value = asColor(modifier, colorPalette)
1514

16-
if (value === undefined) {
17-
return []
18-
}
15+
if (value === undefined) {
16+
return []
17+
}
1918

20-
return [
21-
[
22-
nameClass('bg', modifier),
23-
withAlphaVariable({
24-
color: value,
25-
property: 'background-color',
26-
variable: '--tw-bg-opacity',
27-
}),
28-
],
29-
]
30-
},
31-
],
19+
return {
20+
[nameClass('bg', modifier)]: withAlphaVariable({
21+
color: value,
22+
property: 'background-color',
23+
variable: '--tw-bg-opacity',
24+
}),
25+
}
26+
},
3227
})
3328
}

src/corePlugins/backgroundImage.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
const nameClass = require('tailwindcss/lib/util/nameClass').default
22

3-
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
4-
addUtilities({
5-
bg: [
6-
(modifier, { theme }) => {
7-
let value = theme.backgroundImage[modifier]
3+
module.exports = function ({ matchUtilities, jit: { theme } }) {
4+
matchUtilities({
5+
bg: (modifier, { theme }) => {
6+
let value = theme.backgroundImage[modifier]
87

9-
if (value === undefined) {
10-
return []
11-
}
8+
if (value === undefined) {
9+
return []
10+
}
1211

13-
return [[nameClass('bg', modifier), { 'background-image': value }]]
14-
},
15-
],
12+
return { [nameClass('bg', modifier)]: { 'background-image': value } }
13+
},
1614
})
1715
}

src/corePlugins/backgroundOpacity.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
const nameClass = require('tailwindcss/lib/util/nameClass').default
2-
const transformThemeValue = require('tailwindcss/lib/util/transformThemeValue').default
32
const { asValue } = require('../pluginUtils')
43

5-
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
6-
let transformValue = transformThemeValue('backgroundOpacity')
4+
module.exports = function ({ matchUtilities, jit: { theme, addVariant, e } }) {
5+
matchUtilities({
6+
'bg-opacity': (modifier, { theme }) => {
7+
let value = asValue(modifier, theme.backgroundOpacity)
78

8-
addUtilities({
9-
'bg-opacity': [
10-
(modifier, { theme }) => {
11-
let value = asValue(modifier, theme.backgroundOpacity)
9+
if (value === undefined) {
10+
return []
11+
}
1212

13-
if (value === undefined) {
14-
return []
15-
}
16-
17-
return [[nameClass('bg-opacity', modifier), { '--tw-bg-opacity': value }]]
18-
},
19-
],
13+
return { [nameClass('bg-opacity', modifier)]: { '--tw-bg-opacity': value } }
14+
},
2015
})
2116
}

src/corePlugins/backgroundPosition.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
const nameClass = require('tailwindcss/lib/util/nameClass').default
2-
const transformThemeValue = require('tailwindcss/lib/util/transformThemeValue').default
32

4-
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
5-
addUtilities({
6-
bg: [
7-
(modifier, { theme }) => {
8-
let value = theme.backgroundPosition[modifier]
3+
module.exports = function ({ matchUtilities, jit: { theme } }) {
4+
matchUtilities({
5+
bg: (modifier, { theme }) => {
6+
let value = theme.backgroundPosition[modifier]
97

10-
if (value === undefined) {
11-
return []
12-
}
8+
if (value === undefined) {
9+
return []
10+
}
1311

14-
return [[nameClass('bg', modifier), { 'background-position': value }]]
15-
},
16-
],
12+
return { [nameClass('bg', modifier)]: { 'background-position': value } }
13+
},
1714
})
1815
}

src/corePlugins/backgroundSize.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
const nameClass = require('tailwindcss/lib/util/nameClass').default
2-
const transformThemeValue = require('tailwindcss/lib/util/transformThemeValue').default
32

4-
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
5-
addUtilities({
6-
bg: [
7-
(modifier, { theme }) => {
8-
if (
9-
modifier === undefined ||
10-
modifier === '' ||
11-
theme.backgroundSize[modifier] === undefined
12-
) {
13-
return []
14-
}
3+
module.exports = function ({ matchUtilities, jit: { theme } }) {
4+
matchUtilities({
5+
bg: (modifier, { theme }) => {
6+
let value = theme.backgroundSize[modifier]
157

16-
return [[nameClass('bg', modifier), { 'background-size': theme.backgroundSize[modifier] }]]
17-
},
18-
],
8+
if (value === undefined) {
9+
return []
10+
}
11+
12+
return { [nameClass('bg', modifier)]: { 'background-size': value } }
13+
},
1914
})
2015
}

src/corePlugins/borderColor.js

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
11
const nameClass = require('tailwindcss/lib/util/nameClass').default
2-
const transformThemeValue = require('tailwindcss/lib/util/transformThemeValue').default
32
const flattenColorPalette = require('tailwindcss/lib/util/flattenColorPalette').default
43
const withAlphaVariable = require('tailwindcss/lib/util/withAlphaVariable').default
54
const toColorValue = require('tailwindcss/lib/util/toColorValue').default
65
const { asColor } = require('../pluginUtils')
76

8-
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
7+
module.exports = function ({ matchUtilities, jit: { theme } }) {
98
let colorPalette = flattenColorPalette(theme.borderColor)
109

11-
addUtilities({
12-
border: [
13-
(modifier, { theme }) => {
14-
if (modifier === 'DEFAULT') {
15-
return []
16-
}
10+
matchUtilities({
11+
border: (modifier, { theme }) => {
12+
if (modifier === 'DEFAULT') {
13+
return []
14+
}
1715

18-
let value = asColor(modifier, colorPalette)
16+
let value = asColor(modifier, colorPalette)
1917

20-
if (value === undefined) {
21-
return []
22-
}
18+
if (value === undefined) {
19+
return []
20+
}
2321

24-
return [
25-
[
26-
nameClass('border', modifier),
27-
withAlphaVariable({
28-
color: colorPalette[modifier],
29-
property: 'border-color',
30-
variable: '--tw-border-opacity',
31-
}),
32-
],
33-
]
34-
},
35-
],
22+
return {
23+
[nameClass('border', modifier)]: withAlphaVariable({
24+
color: colorPalette[modifier],
25+
property: 'border-color',
26+
variable: '--tw-border-opacity',
27+
}),
28+
}
29+
},
3630
})
3731
}

src/corePlugins/borderOpacity.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
const nameClass = require('tailwindcss/lib/util/nameClass').default
22
const { asValue } = require('../pluginUtils')
33

4-
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
5-
addUtilities({
6-
'border-opacity': [
7-
(modifier, { theme }) => {
8-
let value = asValue(modifier, theme.borderOpacity)
4+
module.exports = function ({ matchUtilities, jit: { theme } }) {
5+
matchUtilities({
6+
'border-opacity': (modifier, { theme }) => {
7+
let value = asValue(modifier, theme.borderOpacity)
98

10-
if (value === undefined) {
11-
return []
12-
}
9+
if (value === undefined) {
10+
return []
11+
}
1312

14-
return [[nameClass('border-opacity', modifier), { '--tw-border-opacity': value }]]
15-
},
16-
],
13+
return { [nameClass('border-opacity', modifier)]: { '--tw-border-opacity': value } }
14+
},
1715
})
1816
}

0 commit comments

Comments
 (0)