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

Commit 9838321

Browse files
committed
Add bg-none utility (fix #11)
1 parent b841759 commit 9838321

File tree

4 files changed

+122
-13
lines changed

4 files changed

+122
-13
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
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.2.0] - 2019-07-05
9+
10+
### Added
11+
- Added a `bg-none` utility to remove gradients on larger screens (e.g. `bg-gradient-b-black sm:bg-none`)
12+
813
## [2.1.0] - 2019-05-24
914

1015
### Added
@@ -69,7 +74,8 @@ and this project mostly adheres to [Semantic Versioning](https://semver.org/spec
6974

7075
Initial release
7176

72-
[Unreleased]: https://github.com/benface/tailwindcss-gradients/compare/v2.1.0...HEAD
77+
[Unreleased]: https://github.com/benface/tailwindcss-gradients/compare/v2.2.0...HEAD
78+
[2.2.0]: https://github.com/benface/tailwindcss-gradients/compare/v2.1.0...v2.2.0
7379
[2.1.0]: https://github.com/benface/tailwindcss-gradients/compare/v2.0.1...v2.1.0
7480
[2.0.1]: https://github.com/benface/tailwindcss-gradients/compare/v2.0.0...v2.0.1
7581
[2.0.0]: https://github.com/benface/tailwindcss-gradients/compare/v2.0.0-beta.2...v2.0.0

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,12 @@ npm install tailwindcss-gradients
104104
},
105105
}),
106106
},
107-
variants: {
108-
linearGradients: ['responsive'], // defaults to ['responsive']
109-
radialGradients: ['responsive'], // defaults to ['responsive']
110-
repeatingLinearGradients: ['responsive'], // defaults to ['responsive']
111-
repeatingRadialGradients: ['responsive'], // defaults to ['responsive']
107+
variants: { // all the following default to ['responsive']
108+
backgroundImage: ['responsive'], // this is for the "bg-none" utility
109+
linearGradients: ['responsive'],
110+
radialGradients: ['responsive'],
111+
repeatingLinearGradients: ['responsive'],
112+
repeatingRadialGradients: ['responsive'],
112113
},
113114
plugins: [
114115
require('tailwindcss-gradients')(),
@@ -119,6 +120,10 @@ npm install tailwindcss-gradients
119120
This plugin generates the following utilities:
120121

121122
```css
123+
.bg-none {
124+
background-image: none;
125+
}
126+
122127
/* configurable with the "linearGradients" theme object */
123128
.bg-gradient-[direction-key]-[color-key] {
124129
background-image: linear-gradient([direction-value], [color-value-1], [color-value-2], [...]);

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const normalizeColors = function(colors, transparentFirst = true) {
2323

2424
module.exports = function() {
2525
return ({ theme, variants, e, addUtilities }) => {
26+
const defaultBackgroundImageVariants = ['responsive'];
2627
const defaultLinearGradientDirections = {
2728
't': 'to top',
2829
'tr': 'to top right',
@@ -67,6 +68,7 @@ module.exports = function() {
6768
const defaultRepeatingRadialGradientLengths = {};
6869
const defaultRepeatingRadialGradientVariants = ['responsive'];
6970

71+
const backgroundImageVariants = variants('backgroundImage', defaultBackgroundImageVariants);
7072
const linearGradientDirections = theme('linearGradients.directions', defaultLinearGradientDirections);
7173
const linearGradientColors = theme('linearGradients.colors', defaultLinearGradientColors);
7274
const linearGradientVariants = variants('linearGradients', defaultLinearGradientVariants);
@@ -116,6 +118,12 @@ module.exports = function() {
116118
return `${!_.isNil(length) ? 'repeating-' : ''}radial-gradient(${firstArgumentValues.length > 0 ? `${firstArgumentValues.join(' ')}, ` : ''}${colors.join(', ')}${length ? ` ${length}` : ''})`;
117119
};
118120

121+
const backgroundImageUtilities = {
122+
'.bg-none': {
123+
backgroundImage: 'none',
124+
},
125+
};
126+
119127
const linearGradientUtilities = (function() {
120128
let utilities = {};
121129
_.forEach(linearGradientColors, (colors, colorKey) => {
@@ -192,6 +200,7 @@ module.exports = function() {
192200
return utilities;
193201
})();
194202

203+
addUtilities(backgroundImageUtilities, backgroundImageVariants);
195204
addUtilities(linearGradientUtilities, linearGradientVariants);
196205
addUtilities(radialGradientUtilities, radialGradientVariants);
197206
addUtilities(repeatingLinearGradientUtilities, repeatingLinearGradientVariants);

test.js

Lines changed: 96 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,22 @@ expect.extend({
3232
toMatchCss: cssMatcher,
3333
});
3434

35-
test('there is no output by default', () => {
35+
test('only one utility is generated by default', () => {
3636
return generatePluginCss().then(css => {
37-
expect(css).toMatchCss(``);
37+
expect(css).toMatchCss(`
38+
.bg-none {
39+
background-image: none;
40+
}
41+
@media (min-width: 640px) {
42+
.sm\\:bg-none {
43+
background-image: none;
44+
}
45+
}
46+
`);
3847
});
3948
});
4049

41-
test('there is no output without directions or positions', () => {
50+
test('no gradient is generated without directions or positions', () => {
4251
return generatePluginCss({
4352
theme: {
4453
linearGradients: {
@@ -59,11 +68,20 @@ test('there is no output without directions or positions', () => {
5968
},
6069
},
6170
}).then(css => {
62-
expect(css).toMatchCss(``);
71+
expect(css).toMatchCss(`
72+
.bg-none {
73+
background-image: none;
74+
}
75+
@media (min-width: 640px) {
76+
.sm\\:bg-none {
77+
background-image: none;
78+
}
79+
}
80+
`);
6381
});
6482
});
6583

66-
test('there is no output without colors', () => {
84+
test('no gradient is generated without colors', () => {
6785
return generatePluginCss({
6886
theme: {
6987
linearGradients: {
@@ -87,7 +105,16 @@ test('there is no output without colors', () => {
87105
},
88106
},
89107
}).then(css => {
90-
expect(css).toMatchCss(``);
108+
expect(css).toMatchCss(`
109+
.bg-none {
110+
background-image: none;
111+
}
112+
@media (min-width: 640px) {
113+
.sm\\:bg-none {
114+
background-image: none;
115+
}
116+
}
117+
`);
91118
});
92119
});
93120

@@ -101,10 +128,14 @@ test('linear gradients have default directions', () => {
101128
},
102129
},
103130
variants: {
131+
backgroundImage: [],
104132
linearGradients: [],
105133
},
106134
}).then(css => {
107135
expect(css).toMatchCss(`
136+
.bg-none {
137+
background-image: none;
138+
}
108139
.bg-gradient-t-red {
109140
background-image: linear-gradient(to top, rgba(255, 0, 0, 0), #f00);
110141
}
@@ -143,11 +174,15 @@ test('radial gradients have default shapes, sizes, and positions', () => {
143174
},
144175
},
145176
variants: {
177+
backgroundImage: [],
146178
linearGradients: [],
147179
radialGradients: [],
148180
},
149181
}).then(css => {
150182
expect(css).toMatchCss(`
183+
.bg-none {
184+
background-image: none;
185+
}
151186
.bg-radial-red {
152187
background-image: radial-gradient(closest-side, #f00, rgba(255, 0, 0, 0));
153188
}
@@ -202,11 +237,15 @@ test('directions and positions can be customized', () => {
202237
},
203238
},
204239
variants: {
240+
backgroundImage: [],
205241
linearGradients: [],
206242
radialGradients: [],
207243
},
208244
}).then(css => {
209245
expect(css).toMatchCss(`
246+
.bg-none {
247+
background-image: none;
248+
}
210249
.bg-gradient-to-top-red {
211250
background-image: linear-gradient(to top, rgba(255, 0, 0, 0), #f00);
212251
}
@@ -246,11 +285,15 @@ test('gradients can have multiple colors', () => {
246285
},
247286
},
248287
variants: {
288+
backgroundImage: [],
249289
linearGradients: [],
250290
radialGradients: [],
251291
},
252292
}).then(css => {
253293
expect(css).toMatchCss(`
294+
.bg-none {
295+
background-image: none;
296+
}
254297
.bg-gradient-to-bottom-red-green {
255298
background-image: linear-gradient(#f00, #0f0);
256299
}
@@ -292,11 +335,15 @@ test('multiple directions/positions and multiple colors can be used together', (
292335
},
293336
},
294337
variants: {
338+
backgroundImage: [],
295339
linearGradients: [],
296340
radialGradients: [],
297341
},
298342
}).then(css => {
299343
expect(css).toMatchCss(`
344+
.bg-none {
345+
background-image: none;
346+
}
300347
.bg-gradient-to-top-red {
301348
background-image: linear-gradient(to top, rgba(255, 0, 0, 0), #f00);
302349
}
@@ -340,11 +387,15 @@ test('colors can be referenced from the theme with a closure', () => {
340387
}),
341388
},
342389
variants: {
390+
backgroundImage: [],
343391
linearGradients: [],
344392
radialGradients: [],
345393
},
346394
}).then(css => {
347395
expect(css).toMatchCss(`
396+
.bg-none {
397+
background-image: none;
398+
}
348399
.bg-gradient-b-red {
349400
background-image: linear-gradient(rgba(255, 0, 0, 0), #f00);
350401
}
@@ -378,11 +429,15 @@ test('color keywords are accepted', () => {
378429
}),
379430
},
380431
variants: {
432+
backgroundImage: [],
381433
linearGradients: [],
382434
radialGradients: [],
383435
},
384436
}).then(css => {
385437
expect(css).toMatchCss(`
438+
.bg-none {
439+
background-image: none;
440+
}
386441
.bg-gradient-t-white {
387442
background-image: linear-gradient(to top, rgba(255, 255, 255, 0), white);
388443
}
@@ -435,11 +490,15 @@ test('some keywords such as inherit are skipped', () => {
435490
}),
436491
},
437492
variants: {
493+
backgroundImage: [],
438494
linearGradients: [],
439495
radialGradients: [],
440496
},
441497
}).then(css => {
442498
expect(css).toMatchCss(`
499+
.bg-none {
500+
background-image: none;
501+
}
443502
.bg-gradient-t-red {
444503
background-image: linear-gradient(to top, rgba(255, 0, 0, 0), #f00);
445504
}
@@ -474,10 +533,14 @@ test('radial gradient shapes and sizes can be customized', () => {
474533
}),
475534
},
476535
variants: {
536+
backgroundImage: [],
477537
radialGradients: [],
478538
},
479539
}).then(css => {
480540
expect(css).toMatchCss(`
541+
.bg-none {
542+
background-image: none;
543+
}
481544
.bg-radial-red {
482545
background-image: radial-gradient(circle closest-side, #f00, rgba(255, 0, 0, 0));
483546
}
@@ -548,11 +611,16 @@ test('there is no output for repeating gradients without lengths', () => {
548611
}),
549612
},
550613
variants: {
614+
backgroundImage: [],
551615
repeatingLinearGradients: [],
552616
repeatingRadialGradients: [],
553617
},
554618
}).then(css => {
555-
expect(css).toMatchCss(``);
619+
expect(css).toMatchCss(`
620+
.bg-none {
621+
background-image: none;
622+
}
623+
`);
556624
});
557625
});
558626

@@ -587,11 +655,15 @@ test('lengths can be customized', () => {
587655
}),
588656
},
589657
variants: {
658+
backgroundImage: [],
590659
repeatingLinearGradients: [],
591660
repeatingRadialGradients: [],
592661
},
593662
}).then(css => {
594663
expect(css).toMatchCss(`
664+
.bg-none {
665+
background-image: none;
666+
}
595667
.bg-gradient-t-red-sm {
596668
background-image: repeating-linear-gradient(to top, rgba(255, 0, 0, 0), #f00 25px);
597669
}
@@ -671,13 +743,17 @@ test('color stops can be customized', () => {
671743
}),
672744
},
673745
variants: {
746+
backgroundImage: [],
674747
linearGradients: [],
675748
radialGradients: [],
676749
repeatingLinearGradients: [],
677750
repeatingRadialGradients: [],
678751
},
679752
}).then(css => {
680753
expect(css).toMatchCss(`
754+
.bg-none {
755+
background-image: none;
756+
}
681757
.bg-gradient-r-custom {
682758
background-image: linear-gradient(to right, #000, #000 45%, #fff 55%, #fff);
683759
}
@@ -730,6 +806,9 @@ test('responsive variants are generated by default', () => {
730806
},
731807
}).then(css => {
732808
expect(css).toMatchCss(`
809+
.bg-none {
810+
background-image: none;
811+
}
733812
.bg-gradient-t-red {
734813
background-image: linear-gradient(to top, rgba(255, 0, 0, 0), #f00);
735814
}
@@ -743,6 +822,9 @@ test('responsive variants are generated by default', () => {
743822
background-image: repeating-radial-gradient(#f00, rgba(255, 0, 0, 0) 10px);
744823
}
745824
@media (min-width: 640px) {
825+
.sm\\:bg-none {
826+
background-image: none;
827+
}
746828
.sm\\:bg-gradient-t-red {
747829
background-image: linear-gradient(to top, rgba(255, 0, 0, 0), #f00);
748830
}
@@ -795,13 +877,20 @@ test('variants can be customized', () => {
795877
}),
796878
},
797879
variants: {
880+
backgroundImage: ['focus'],
798881
linearGradients: ['hover', 'active'],
799882
radialGradients: ['group-hover'],
800883
repeatingLinearGradients: ['active'],
801884
repeatingRadialGradients: ['hover'],
802885
},
803886
}).then(css => {
804887
expect(css).toMatchCss(`
888+
.bg-none {
889+
background-image: none;
890+
}
891+
.focus\\:bg-none:focus {
892+
background-image: none;
893+
}
805894
.bg-gradient-t-red {
806895
background-image: linear-gradient(to top, rgba(255, 0, 0, 0), #f00);
807896
}

0 commit comments

Comments
 (0)