Skip to content
This repository was archived by the owner on Dec 15, 2024. It is now read-only.

Commit fc5ae9e

Browse files
committed
Use rgba() instead of transparent (fix #5)
1 parent 600be74 commit fc5ae9e

File tree

5 files changed

+65
-25
lines changed

5 files changed

+65
-25
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.0.0-beta.2] - 2019-04-04
9+
10+
### Fixed
11+
- Single-color gradients now generate a transparent `rgba()` version of the color instead of using the `transparent` keyword, which is interpreted as `rgba(0, 0, 0, 0)` (transparent black) by Safari and the CSS spec
12+
813
## [2.0.0-beta.1] - 2019-04-04
914

1015
### Added

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const _ = require('lodash');
2+
const Color = require('color');
23

34
module.exports = function() {
45
return ({ config, e, addUtilities }) => {
@@ -19,7 +20,9 @@ module.exports = function() {
1920
let utilities = {};
2021
_.forEach(config('theme.gradients.colors', defaultColors), (colors, colorKey) => {
2122
if (!_.isArray(colors) || colors.length === 1) {
22-
colors = ['transparent', _.isArray(colors) ? colors[0] : colors];
23+
let color = _.isArray(colors) ? colors[0] : colors;
24+
let parsedColor = Color(color);
25+
colors = [parsedColor.alpha(0).rgb().string(), color];
2326
}
2427
_.forEach(config('theme.gradients.directions', defaultDirections), (direction, directionKey) => {
2528
utilities[`.${e(`bg-gradient-${directionKey}-${colorKey}`)}`] = {

package-lock.json

Lines changed: 35 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"release": "f(){ release-it $1 && github-release-from-changelog ;};f"
1616
},
1717
"dependencies": {
18+
"color": "^3.1.0",
1819
"lodash": "^4.17.11"
1920
},
2021
"devDependencies": {

test.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,28 +95,28 @@ test('there are default directions', () => {
9595
}).then(css => {
9696
expect(css).toMatchCss(`
9797
.bg-gradient-t-red {
98-
background-image: linear-gradient(to top, transparent, #f00);
98+
background-image: linear-gradient(to top, rgba(255, 0, 0, 0), #f00);
9999
}
100100
.bg-gradient-tr-red {
101-
background-image: linear-gradient(to top right, transparent, #f00);
101+
background-image: linear-gradient(to top right, rgba(255, 0, 0, 0), #f00);
102102
}
103103
.bg-gradient-r-red {
104-
background-image: linear-gradient(to right, transparent, #f00);
104+
background-image: linear-gradient(to right, rgba(255, 0, 0, 0), #f00);
105105
}
106106
.bg-gradient-br-red {
107-
background-image: linear-gradient(to bottom right, transparent, #f00);
107+
background-image: linear-gradient(to bottom right, rgba(255, 0, 0, 0), #f00);
108108
}
109109
.bg-gradient-b-red {
110-
background-image: linear-gradient(to bottom, transparent, #f00);
110+
background-image: linear-gradient(to bottom, rgba(255, 0, 0, 0), #f00);
111111
}
112112
.bg-gradient-bl-red {
113-
background-image: linear-gradient(to bottom left, transparent, #f00);
113+
background-image: linear-gradient(to bottom left, rgba(255, 0, 0, 0), #f00);
114114
}
115115
.bg-gradient-l-red {
116-
background-image: linear-gradient(to left, transparent, #f00);
116+
background-image: linear-gradient(to left, rgba(255, 0, 0, 0), #f00);
117117
}
118118
.bg-gradient-tl-red {
119-
background-image: linear-gradient(to top left, transparent, #f00);
119+
background-image: linear-gradient(to top left, rgba(255, 0, 0, 0), #f00);
120120
}
121121
`);
122122
});
@@ -142,13 +142,13 @@ test('directions can be customized', () => {
142142
}).then(css => {
143143
expect(css).toMatchCss(`
144144
.bg-gradient-to-top-red {
145-
background-image: linear-gradient(to top, transparent, #f00);
145+
background-image: linear-gradient(to top, rgba(255, 0, 0, 0), #f00);
146146
}
147147
.bg-gradient-to-top-green {
148-
background-image: linear-gradient(to top, transparent, #0f0);
148+
background-image: linear-gradient(to top, rgba(0, 255, 0, 0), #0f0);
149149
}
150150
.bg-gradient-to-top-blue {
151-
background-image: linear-gradient(to top, transparent, #00f);
151+
background-image: linear-gradient(to top, rgba(0, 0, 255, 0), #00f);
152152
}
153153
`);
154154
});
@@ -202,16 +202,16 @@ test('multiple directions and multiple gradients can be used together', () => {
202202
}).then(css => {
203203
expect(css).toMatchCss(`
204204
.bg-gradient-to-top-red {
205-
background-image: linear-gradient(to top, transparent, #f00);
205+
background-image: linear-gradient(to top, rgba(255, 0, 0, 0), #f00);
206206
}
207207
.bg-gradient-to-bottom-red {
208-
background-image: linear-gradient(to bottom, transparent, #f00);
208+
background-image: linear-gradient(to bottom, rgba(255, 0, 0, 0), #f00);
209209
}
210210
.bg-gradient-to-top-green {
211-
background-image: linear-gradient(to top, transparent, #0f0);
211+
background-image: linear-gradient(to top, rgba(0, 255, 0, 0), #0f0);
212212
}
213213
.bg-gradient-to-bottom-green {
214-
background-image: linear-gradient(to bottom, transparent, #0f0);
214+
background-image: linear-gradient(to bottom, rgba(0, 255, 0, 0), #0f0);
215215
}
216216
`);
217217
});
@@ -232,11 +232,11 @@ test('responsive utilities are generated by default', () => {
232232
}).then(css => {
233233
expect(css).toMatchCss(`
234234
.bg-gradient-t-red {
235-
background-image: linear-gradient(to top, transparent, #f00);
235+
background-image: linear-gradient(to top, rgba(255, 0, 0, 0), #f00);
236236
}
237237
@media (min-width: 640px) {
238238
.sm\\:bg-gradient-t-red {
239-
background-image: linear-gradient(to top, transparent, #f00);
239+
background-image: linear-gradient(to top, rgba(255, 0, 0, 0), #f00);
240240
}
241241
}
242242
`);
@@ -261,13 +261,13 @@ test('variants can be customized', () => {
261261
}).then(css => {
262262
expect(css).toMatchCss(`
263263
.bg-gradient-t-red {
264-
background-image: linear-gradient(to top, transparent, #f00);
264+
background-image: linear-gradient(to top, rgba(255, 0, 0, 0), #f00);
265265
}
266266
.hover\\:bg-gradient-t-red:hover {
267-
background-image: linear-gradient(to top, transparent, #f00);
267+
background-image: linear-gradient(to top, rgba(255, 0, 0, 0), #f00);
268268
}
269269
.active\\:bg-gradient-t-red:active {
270-
background-image: linear-gradient(to top, transparent, #f00);
270+
background-image: linear-gradient(to top, rgba(255, 0, 0, 0), #f00);
271271
}
272272
`);
273273
});

0 commit comments

Comments
 (0)