Skip to content

Commit 8d87445

Browse files
committed
Improve API, support auto-transparent to, rename gradientColor plugin
1 parent 7fb5d4a commit 8d87445

9 files changed

+41850
-47308
lines changed

__tests__/fixtures/tailwind-output-flagged.css

Lines changed: 11248 additions & 12728 deletions
Large diffs are not rendered by default.

__tests__/fixtures/tailwind-output-important.css

Lines changed: 10178 additions & 11508 deletions
Large diffs are not rendered by default.

__tests__/fixtures/tailwind-output-no-color-opacity.css

Lines changed: 10178 additions & 11508 deletions
Large diffs are not rendered by default.

__tests__/fixtures/tailwind-output.css

Lines changed: 10178 additions & 11508 deletions
Large diffs are not rendered by default.

src/corePlugins.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import backgroundAttachment from './plugins/backgroundAttachment'
99
import backgroundClip from './plugins/backgroundClip'
1010
import backgroundColor from './plugins/backgroundColor'
1111
import backgroundImage from './plugins/backgroundImage'
12-
import gradientColor from './plugins/gradientColor'
12+
import gradientColorStops from './plugins/gradientColorStops'
1313
import backgroundPosition from './plugins/backgroundPosition'
1414
import backgroundRepeat from './plugins/backgroundRepeat'
1515
import backgroundSize from './plugins/backgroundSize'
@@ -119,7 +119,7 @@ export default function({ corePlugins: corePluginConfig }) {
119119
backgroundClip,
120120
backgroundColor,
121121
backgroundImage,
122-
gradientColor,
122+
gradientColorStops,
123123
backgroundOpacity,
124124
backgroundPosition,
125125
backgroundRepeat,

src/plugins/gradientColor.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/plugins/gradientColorStops.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import _ from 'lodash'
2+
import flattenColorPalette from '../util/flattenColorPalette'
3+
import { toRgba } from '../util/withAlphaVariable'
4+
5+
export default function() {
6+
return function({ addUtilities, e, theme, variants, target }) {
7+
if (target('gradientColorStops') === 'ie11') {
8+
return
9+
}
10+
11+
const colors = flattenColorPalette(theme('gradientColorStops'))
12+
13+
const utilities = _(colors)
14+
.map((value, modifier) => {
15+
const transparentTo = (() => {
16+
try {
17+
const [r, g, b] = toRgba(value)
18+
return `rgba(${r}, ${g}, ${b}, 0)`
19+
} catch {
20+
return `rgba(255, 255, 255, 0)`
21+
}
22+
})()
23+
24+
return [
25+
[
26+
`.${e(`from-${modifier}`)}`,
27+
{
28+
'--gradient-from-color': value,
29+
'--gradient-color-stops': `var(--gradient-from-color), var(--gradient-to-color, ${transparentTo})`,
30+
},
31+
],
32+
[
33+
`.${e(`mid-${modifier}`)}`,
34+
{
35+
'--gradient-mid-color': value,
36+
'--gradient-color-stops': `var(--gradient-from-color), var(--gradient-mid-color), var(--gradient-to-color, ${transparentTo})`,
37+
},
38+
],
39+
[
40+
`.${e(`to-${modifier}`)}`,
41+
{
42+
'--gradient-to-color': value,
43+
},
44+
],
45+
]
46+
})
47+
.unzip()
48+
.flatten()
49+
.fromPairs()
50+
.value()
51+
52+
addUtilities(utilities, variants('gradientColorStops'))
53+
}
54+
}

src/util/withAlphaVariable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function hasAlpha(color) {
1010
)
1111
}
1212

13-
function toRgba(color) {
13+
export function toRgba(color) {
1414
const [r, g, b, a] = createColor(color)
1515
.rgb()
1616
.array()

stubs/defaultConfig.stub.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,16 @@ module.exports = {
152152
},
153153
backgroundColor: theme => theme('colors'),
154154
backgroundImage: {
155-
'gradient-up': 'linear-gradient(0deg, var(--gradient-color-stops))',
156-
'gradient-right': 'linear-gradient(90deg, var(--gradient-color-stops))',
157-
'gradient-down': 'linear-gradient(180deg, var(--gradient-color-stops))',
158-
'gradient-left': 'linear-gradient(270deg, var(--gradient-color-stops))',
159-
},
160-
gradientColor: theme => theme('colors'),
155+
'gradient-t': 'linear-gradient(to top, var(--gradient-color-stops))',
156+
'gradient-tr': 'linear-gradient(to top right, var(--gradient-color-stops))',
157+
'gradient-r': 'linear-gradient(to right, var(--gradient-color-stops))',
158+
'gradient-br': 'linear-gradient(to bottom right, var(--gradient-color-stops))',
159+
'gradient-b': 'linear-gradient(to bottom, var(--gradient-color-stops))',
160+
'gradient-bl': 'linear-gradient(to bottom left, var(--gradient-color-stops))',
161+
'gradient-l': 'linear-gradient(to left, var(--gradient-color-stops))',
162+
'gradient-tl': 'linear-gradient(to top left, var(--gradient-color-stops))',
163+
},
164+
gradientColorStops: theme => theme('colors'),
161165
backgroundOpacity: theme => theme('opacity'),
162166
backgroundPosition: {
163167
bottom: 'bottom',
@@ -668,7 +672,7 @@ module.exports = {
668672
backgroundClip: ['responsive'],
669673
backgroundColor: ['responsive', 'hover', 'focus'],
670674
backgroundImage: ['responsive'],
671-
gradientColor: ['responsive', 'hover', 'focus'],
675+
gradientColorStops: ['responsive', 'hover', 'focus'],
672676
backgroundOpacity: ['responsive', 'hover', 'focus'],
673677
backgroundPosition: ['responsive'],
674678
backgroundRepeat: ['responsive'],

0 commit comments

Comments
 (0)