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

Commit c8f991f

Browse files
committed
Allow gradient colors to use nested object notation
1 parent d0d164b commit c8f991f

File tree

5 files changed

+719
-705
lines changed

5 files changed

+719
-705
lines changed

CHANGELOG.md

+7-1
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.3.1] - 2019-09-01
9+
10+
### Fixed
11+
- Fixed an issue when using nested object notation for gradient colors
12+
813
## [2.3.0] - 2019-07-08
914

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

8085
Initial release
8186

82-
[Unreleased]: https://github.com/benface/tailwindcss-gradients/compare/v2.3.0...HEAD
87+
[Unreleased]: https://github.com/benface/tailwindcss-gradients/compare/v2.3.1...HEAD
88+
[2.3.0]: https://github.com/benface/tailwindcss-gradients/compare/v2.3.0...v2.3.1
8389
[2.3.0]: https://github.com/benface/tailwindcss-gradients/compare/v2.2.0...v2.3.0
8490
[2.2.0]: https://github.com/benface/tailwindcss-gradients/compare/v2.1.0...v2.2.0
8591
[2.1.0]: https://github.com/benface/tailwindcss-gradients/compare/v2.0.1...v2.1.0

index.js

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
const _ = require('lodash');
22
const Color = require('color');
33

4+
const flattenColorPalette = function(colors) {
5+
return _(colors)
6+
.flatMap((color, name) => {
7+
if (!_.isPlainObject(color)) {
8+
return [[name, color]];
9+
}
10+
return _.map(color, (value, key) => {
11+
const suffix = key === 'default' ? '' : `-${key}`;
12+
return [`${name}${suffix}`, value];
13+
});
14+
})
15+
.fromPairs()
16+
.value();
17+
};
18+
419
const normalizeColors = function(colors, transparentFirst = true) {
520
colors = _.castArray(colors);
621
const unsupportedColorKeywords = ['inherit', 'initial', 'unset', 'revert'];
@@ -173,7 +188,7 @@ module.exports = function() {
173188

174189
const linearGradientUtilities = (function() {
175190
const utilities = {};
176-
_.forEach(linearGradientColors, (colors, colorKey) => {
191+
_.forEach(flattenColorPalette(linearGradientColors), (colors, colorKey) => {
177192
colors = normalizeColors(colors, true);
178193
if (!colors) {
179194
return; // continue
@@ -189,7 +204,7 @@ module.exports = function() {
189204

190205
const radialGradientUtilities = (function() {
191206
const utilities = {};
192-
_.forEach(radialGradientColors, (colors, colorKey) => {
207+
_.forEach(flattenColorPalette(radialGradientColors), (colors, colorKey) => {
193208
colors = normalizeColors(colors, false);
194209
if (!colors) {
195210
return; // continue
@@ -209,7 +224,7 @@ module.exports = function() {
209224

210225
const conicGradientUtilities = (function() {
211226
const utilities = {};
212-
_.forEach(conicGradientColors, (colors, colorKey) => {
227+
_.forEach(flattenColorPalette(conicGradientColors), (colors, colorKey) => {
213228
colors = normalizeColors(colors, false);
214229
if (!colors) {
215230
return; // continue
@@ -228,7 +243,7 @@ module.exports = function() {
228243
const repeatingLinearGradientUtilities = (function() {
229244
const utilities = {};
230245
_.forEach(repeatingLinearGradientLengths, (length, lengthKey) => {
231-
_.forEach(repeatingLinearGradientColors, (colors, colorKey) => {
246+
_.forEach(flattenColorPalette(repeatingLinearGradientColors), (colors, colorKey) => {
232247
colors = normalizeColors(colors, true);
233248
if (!colors) {
234249
return; // continue
@@ -246,7 +261,7 @@ module.exports = function() {
246261
const repeatingRadialGradientUtilities = (function() {
247262
const utilities = {};
248263
_.forEach(repeatingRadialGradientLengths, (length, lengthKey) => {
249-
_.forEach(repeatingRadialGradientColors, (colors, colorKey) => {
264+
_.forEach(flattenColorPalette(repeatingRadialGradientColors), (colors, colorKey) => {
250265
colors = normalizeColors(colors, false);
251266
if (!colors) {
252267
return; // continue
@@ -268,7 +283,7 @@ module.exports = function() {
268283
const repeatingConicGradientUtilities = (function() {
269284
const utilities = {};
270285
_.forEach(repeatingConicGradientLengths, (length, lengthKey) => {
271-
_.forEach(repeatingConicGradientColors, (colors, colorKey) => {
286+
_.forEach(flattenColorPalette(repeatingConicGradientColors), (colors, colorKey) => {
272287
colors = normalizeColors(colors, false);
273288
if (!colors) {
274289
return; // continue

0 commit comments

Comments
 (0)