Skip to content

Commit 19cc425

Browse files
authored
Merge pull request #718 from tailwindcss/default-key-in-color-objects
Support default key in color objects
2 parents 1ffa750 + fc75cf9 commit 19cc425

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

__tests__/plugins/backgroundColor.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ test('colors can be a nested object', () => {
99
theme: {
1010
backgroundColor: {
1111
purple: 'purple',
12+
white: {
13+
25: 'rgba(255,255,255,.25)',
14+
50: 'rgba(255,255,255,.5)',
15+
75: 'rgba(255,255,255,.75)',
16+
default: '#fff',
17+
},
1218
red: {
1319
1: 'rgb(33,0,0)',
1420
2: 'rgb(67,0,0)',
@@ -48,6 +54,10 @@ test('colors can be a nested object', () => {
4854
{
4955
utilities: {
5056
'.bg-purple': { 'background-color': 'purple' },
57+
'.bg-white-25': { 'background-color': 'rgba(255,255,255,.25)' },
58+
'.bg-white-50': { 'background-color': 'rgba(255,255,255,.5)' },
59+
'.bg-white-75': { 'background-color': 'rgba(255,255,255,.75)' },
60+
'.bg-white': { 'background-color': '#fff' },
5161
'.bg-red-1': { 'background-color': 'rgb(33,0,0)' },
5262
'.bg-red-2': { 'background-color': 'rgb(67,0,0)' },
5363
'.bg-red-3': { 'background-color': 'rgb(100,0,0)' },

__tests__/plugins/borderColor.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ test('colors can be a nested object', () => {
99
theme: {
1010
borderColor: {
1111
purple: 'purple',
12+
white: {
13+
25: 'rgba(255,255,255,.25)',
14+
50: 'rgba(255,255,255,.5)',
15+
75: 'rgba(255,255,255,.75)',
16+
default: '#fff',
17+
},
1218
red: {
1319
1: 'rgb(33,0,0)',
1420
2: 'rgb(67,0,0)',
@@ -48,6 +54,10 @@ test('colors can be a nested object', () => {
4854
{
4955
utilities: {
5056
'.border-purple': { 'border-color': 'purple' },
57+
'.border-white-25': { 'border-color': 'rgba(255,255,255,.25)' },
58+
'.border-white-50': { 'border-color': 'rgba(255,255,255,.5)' },
59+
'.border-white-75': { 'border-color': 'rgba(255,255,255,.75)' },
60+
'.border-white': { 'border-color': '#fff' },
5161
'.border-red-1': { 'border-color': 'rgb(33,0,0)' },
5262
'.border-red-2': { 'border-color': 'rgb(67,0,0)' },
5363
'.border-red-3': { 'border-color': 'rgb(100,0,0)' },

__tests__/plugins/textColor.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ test('colors can be a nested object', () => {
99
theme: {
1010
textColor: {
1111
purple: 'purple',
12+
white: {
13+
25: 'rgba(255,255,255,.25)',
14+
50: 'rgba(255,255,255,.5)',
15+
75: 'rgba(255,255,255,.75)',
16+
default: '#fff',
17+
},
1218
red: {
1319
1: 'rgb(33,0,0)',
1420
2: 'rgb(67,0,0)',
@@ -48,6 +54,10 @@ test('colors can be a nested object', () => {
4854
{
4955
utilities: {
5056
'.text-purple': { color: 'purple' },
57+
'.text-white-25': { color: 'rgba(255,255,255,.25)' },
58+
'.text-white-50': { color: 'rgba(255,255,255,.5)' },
59+
'.text-white-75': { color: 'rgba(255,255,255,.75)' },
60+
'.text-white': { color: '#fff' },
5161
'.text-red-1': { color: 'rgb(33,0,0)' },
5262
'.text-red-2': { color: 'rgb(67,0,0)' },
5363
'.text-red-3': { color: 'rgb(100,0,0)' },

src/util/flattenColorPalette.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import _ from 'lodash'
33
export default function flattenColorPalette(colors) {
44
const result = _(colors)
55
.flatMap((color, name) => {
6-
return _.isObject(color)
7-
? _.map(color, (value, key) => [`${name}-${key}`, value])
8-
: [[name, color]]
6+
if (!_.isObject(color)) {
7+
return [[name, color]]
8+
}
9+
10+
return _.map(color, (value, key) => {
11+
const suffix = key === 'default' ? '' : `-${key}`
12+
return [`${name}${suffix}`, value]
13+
})
914
})
1015
.fromPairs()
1116
.value()

0 commit comments

Comments
 (0)