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

Commit bc8b5a4

Browse files
committed
More arbitrary value support
1 parent 5d05679 commit bc8b5a4

20 files changed

+67
-71
lines changed

src/corePlugins/animation.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = function ({ jit: { theme, addUtilities } }) {
1313
return [key, value]
1414
}),
1515
],
16+
{ respectVariants: false },
1617
]
1718
})
1819
)

src/corePlugins/backgroundImage.js

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

43
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
5-
let transformValue = transformThemeValue('backgroundImage')
64
addUtilities({
75
bg: [
86
(modifier, { theme }) => {
9-
let value = transformValue(theme.backgroundImage[modifier])
7+
let value = theme.backgroundImage[modifier]
108

119
if (value === undefined) {
1210
return []

src/corePlugins/backgroundOpacity.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
const nameClass = require('tailwindcss/lib/util/nameClass').default
22
const transformThemeValue = require('tailwindcss/lib/util/transformThemeValue').default
3+
const { asValue } = require('../pluginUtils')
34

45
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
56
let transformValue = transformThemeValue('backgroundOpacity')
67

78
addUtilities({
89
'bg-opacity': [
910
(modifier, { theme }) => {
10-
let value = transformValue(theme.backgroundOpacity[modifier])
11+
let value = asValue(modifier, theme.backgroundOpacity)
1112

1213
if (value === undefined) {
1314
return []
1415
}
1516

16-
return [
17-
[
18-
nameClass('bg-opacity', modifier),
19-
{ '--tw-bg-opacity': theme.backgroundOpacity[modifier] },
20-
],
21-
]
17+
return [[nameClass('bg-opacity', modifier), { '--tw-bg-opacity': value }]]
2218
},
2319
],
2420
})

src/corePlugins/borderOpacity.js

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

44
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
55
addUtilities({
66
'border-opacity': [
77
(modifier, { theme }) => {
8-
let transformValue = transformThemeValue('borderOpacity')
9-
let value = transformValue(theme.borderOpacity[modifier])
8+
let value = asValue(modifier, theme.borderOpacity)
109

1110
if (value === undefined) {
1211
return []

src/corePlugins/cursor.js

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

45
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
56
addUtilities({
67
cursor: [
78
(modifier, { theme }) => {
8-
if (modifier === undefined || modifier === '' || theme.cursor[modifier] === undefined) {
9+
let value = asValue(modifier, theme.cursor)
10+
11+
if (value === undefined) {
912
return []
1013
}
1114

12-
return [[nameClass('cursor', modifier), { cursor: theme.cursor[modifier] }]]
15+
return [[nameClass('cursor', modifier), { cursor: value }]]
1316
},
1417
],
1518
})

src/corePlugins/divideOpacity.js

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

45
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
56
addUtilities({
67
'divide-opacity': [
78
(modifier, { theme }) => {
8-
let transformValue = transformThemeValue('divideOpacity')
9-
let value = transformValue(theme.divideOpacity[modifier])
9+
let value = asValue(modifier, theme.divideOpacity)
1010

1111
if (value === undefined) {
1212
return []
@@ -15,7 +15,7 @@ module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
1515
return [
1616
[
1717
`${nameClass('divide-opacity', modifier)} > :not([hidden]) ~ :not([hidden])`,
18-
{ '--tw-divide-opacity': theme.divideOpacity[modifier] },
18+
{ '--tw-divide-opacity': value },
1919
],
2020
]
2121
},

src/corePlugins/flexGrow.js

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

44
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
55
addUtilities({
66
'flex-grow': [
77
(modifier, { theme }) => {
8-
let transformValue = transformThemeValue('flexGrow')
9-
let value = transformValue(theme.flexGrow[modifier])
8+
let value = asValue(modifier, theme.flexGrow)
109

1110
if (value === undefined) {
1211
return []

src/corePlugins/flexShrink.js

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

44
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
55
addUtilities({
66
'flex-shrink': [
77
(modifier, { theme }) => {
8-
let transformValue = transformThemeValue('flexShrink')
9-
let value = transformValue(theme.flexShrink[modifier])
8+
let value = asValue(modifier, theme.flexShrink)
109

1110
if (value === undefined) {
1211
return []

src/corePlugins/margin.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
const { asLength } = require('../pluginUtils')
2+
13
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
24
addUtilities({
35
m: [
46
(modifier, { theme, candidate }) => {
5-
let value = theme.margin[modifier]
6-
if (modifier === '' || value === undefined) {
7+
let value = asLength(modifier, theme['margin'])
8+
9+
if (value === undefined) {
710
return []
811
}
912

@@ -14,9 +17,9 @@ module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
1417
addUtilities({
1518
mx: [
1619
(modifier, { theme, candidate }) => {
17-
let value = theme.margin[modifier]
20+
let value = asLength(modifier, theme['margin'])
1821

19-
if (modifier === '' || value === undefined) {
22+
if (value === undefined) {
2023
return []
2124
}
2225

@@ -25,9 +28,9 @@ module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
2528
],
2629
my: [
2730
(modifier, { theme, candidate }) => {
28-
let value = theme.margin[modifier]
31+
let value = asLength(modifier, theme['margin'])
2932

30-
if (modifier === '' || value === undefined) {
33+
if (value === undefined) {
3134
return []
3235
}
3336

@@ -53,9 +56,9 @@ module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
5356
],
5457
mr: [
5558
(modifier, { theme, candidate }) => {
56-
let value = theme.margin[modifier]
59+
let value = asLength(modifier, theme['margin'])
5760

58-
if (modifier === '' || value === undefined) {
61+
if (value === undefined) {
5962
return []
6063
}
6164

@@ -64,9 +67,9 @@ module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
6467
],
6568
mb: [
6669
(modifier, { theme, candidate }) => {
67-
let value = theme.margin[modifier]
70+
let value = asLength(modifier, theme['margin'])
6871

69-
if (modifier === '' || value === undefined) {
72+
if (value === undefined) {
7073
return []
7174
}
7275

@@ -75,9 +78,9 @@ module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
7578
],
7679
ml: [
7780
(modifier, { theme, candidate }) => {
78-
let value = theme.margin[modifier]
81+
let value = asLength(modifier, theme['margin'])
7982

80-
if (modifier === '' || value === undefined) {
83+
if (value === undefined) {
8184
return []
8285
}
8386

src/corePlugins/opacity.js

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

44
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
55
addUtilities({
66
opacity: (modifier, { theme }) => {
7-
if (modifier === '' || theme.opacity[modifier] === undefined) {
7+
let value = asValue(modifier, theme.opacity)
8+
9+
if (value === undefined) {
810
return []
911
}
1012

11-
return [[nameClass('opacity', modifier), { opacity: theme.opacity[modifier] }]]
13+
return [[nameClass('opacity', modifier), { opacity: value }]]
1214
},
1315
})
1416
}

src/corePlugins/order.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
const nameClass = require('tailwindcss/lib/util/nameClass').default
2-
const transformThemeValue = require('tailwindcss/lib/util/transformThemeValue').default
2+
const { asValue } = require('../pluginUtils')
33

44
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
55
addUtilities({
66
order: [
77
(modifier, { theme }) => {
8-
if (modifier === '' || theme.order[modifier] === undefined) {
8+
let value = asValue(modifier, theme.order)
9+
10+
if (value === undefined) {
911
return []
1012
}
1113

12-
return [[nameClass('order', modifier), { order: theme.order[modifier] }]]
14+
return [[nameClass('order', modifier), { order: value }]]
1315
},
1416
],
1517
})

src/corePlugins/placeholderOpacity.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const nameClass = require('tailwindcss/lib/util/nameClass').default
22
const transformThemeValue = require('tailwindcss/lib/util/transformThemeValue').default
3+
const { asValue } = require('../pluginUtils')
34

45
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
56
addUtilities({
67
'placeholder-opacity': [
78
(modifier, { theme }) => {
8-
let transformValue = transformThemeValue('placeholderOpacity')
9-
let value = transformValue(theme.placeholderOpacity[modifier])
9+
let value = asValue(modifier, theme.placeholderOpacity)
1010

1111
if (value === undefined) {
1212
return []

src/corePlugins/ringColor.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
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

src/corePlugins/ringOffsetColor.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
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

src/corePlugins/ringOffsetWidth.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
const nameClass = require('tailwindcss/lib/util/nameClass').default
2-
const transformThemeValue = require('tailwindcss/lib/util/transformThemeValue').default
2+
const { asLength } = require('../pluginUtils')
33

44
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
55
addUtilities({
66
'ring-offset': [
77
(modifier, { theme }) => {
8-
let transformValue = transformThemeValue('ringOffsetWidth')
9-
let value = transformValue(theme.ringOffsetWidth[modifier])
8+
let value = asLength(modifier, theme['ringOffsetWidth'])
109

1110
if (value === undefined) {
1211
return []

src/corePlugins/ringOpacity.js

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

44
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
55
addUtilities({
66
'ring-opacity': [
77
(modifier, { theme }) => {
8-
let transformValue = transformThemeValue('ringOpacity')
9-
let value = transformValue(theme.ringOpacity[modifier])
8+
let value = asValue(modifier, theme['ringOpacity'])
109

1110
if (value === undefined) {
1211
return []

src/corePlugins/ringWidth.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const nameClass = require('tailwindcss/lib/util/nameClass').default
22
const transformThemeValue = require('tailwindcss/lib/util/transformThemeValue').default
33
const toRgba = require('tailwindcss/lib/util/withAlphaVariable').toRgba
4+
const { asLength } = require('../pluginUtils')
45

56
function safeCall(callback, defaultValue) {
67
try {
@@ -33,12 +34,9 @@ module.exports = function ({ jit: { theme, addUtilities } }) {
3334
addUtilities({
3435
ring: [
3536
(modifier, { theme }) => {
36-
modifier = modifier === '' ? 'DEFAULT' : modifier
37+
let value = asLength(modifier, theme['ringWidth'])
3738

38-
let transformValue = transformThemeValue('ringWidth')
39-
let value = transformValue(theme.ringWidth[modifier])
40-
41-
if (modifier === '' || value === undefined) {
39+
if (value === undefined) {
4240
return []
4341
}
4442

src/corePlugins/strokeWidth.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
const nameClass = require('tailwindcss/lib/util/nameClass').default
22
const transformThemeValue = require('tailwindcss/lib/util/transformThemeValue').default
3+
const { asLength } = require('../pluginUtils')
34

45
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
56
addUtilities({
67
stroke: [
78
(modifier, { theme }) => {
8-
if (modifier === '' || theme.strokeWidth[modifier] === undefined) {
9+
let value = asLength(modifier, theme['strokeWidth'])
10+
11+
if (value === undefined) {
912
return []
1013
}
1114

12-
return [[nameClass('stroke', modifier), { 'stroke-width': theme.strokeWidth[modifier] }]]
15+
return [[nameClass('stroke', modifier), { 'stroke-width': value }]]
1316
},
1417
],
1518
})

src/corePlugins/textOpacity.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
const nameClass = require('tailwindcss/lib/util/nameClass').default
2-
const transformThemeValue = require('tailwindcss/lib/util/transformThemeValue').default
2+
const { asValue } = require('../pluginUtils')
33

44
module.exports = function ({ jit: { theme, addUtilities, addVariant, e } }) {
55
addUtilities({
66
'text-opacity': [
77
(modifier, { theme }) => {
8-
let transformValue = transformThemeValue('textOpacity')
9-
let value = transformValue(theme.textOpacity[modifier])
8+
let value = asValue(modifier, theme.textOpacity)
109

11-
if (theme.textOpacity[modifier] === undefined) {
10+
if (value === undefined) {
1211
return []
1312
}
1413

15-
return [
16-
[
17-
nameClass('text-opacity', modifier),
18-
{ '--tw-text-opacity': theme.textOpacity[modifier] },
19-
],
20-
]
14+
return [[nameClass('text-opacity', modifier), { '--tw-text-opacity': value }]]
2115
},
2216
],
2317
})

0 commit comments

Comments
 (0)