forked from tailwindlabs/tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flattenColorPalette.test.js
85 lines (83 loc) · 2.18 KB
/
flattenColorPalette.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import flattenColorPalette from '../src/util/flattenColorPalette'
test('it flattens nested color objects', () => {
expect(
flattenColorPalette({
purple: 'purple',
white: {
25: 'rgba(255,255,255,.25)',
50: 'rgba(255,255,255,.5)',
75: 'rgba(255,255,255,.75)',
DEFAULT: '#fff',
},
red: {
1: 'rgb(33,0,0)',
2: 'rgb(67,0,0)',
3: 'rgb(100,0,0)',
},
green: {
1: 'rgb(0,33,0)',
2: 'rgb(0,67,0)',
3: 'rgb(0,100,0)',
},
blue: {
1: 'rgb(0,0,33)',
2: 'rgb(0,0,67)',
3: 'rgb(0,0,100)',
},
})
).toEqual({
purple: 'purple',
'white-25': 'rgba(255,255,255,.25)',
'white-50': 'rgba(255,255,255,.5)',
'white-75': 'rgba(255,255,255,.75)',
white: '#fff',
'red-1': 'rgb(33,0,0)',
'red-2': 'rgb(67,0,0)',
'red-3': 'rgb(100,0,0)',
'green-1': 'rgb(0,33,0)',
'green-2': 'rgb(0,67,0)',
'green-3': 'rgb(0,100,0)',
'blue-1': 'rgb(0,0,33)',
'blue-2': 'rgb(0,0,67)',
'blue-3': 'rgb(0,0,100)',
})
})
test('it recursively flattens nested color objects', () => {
expect(
flattenColorPalette({
brand: {
primary: {
DEFAULT: 'rgb(100,0,0)',
50: 'rgba(100,0,0,.5)',
},
},
theme: {
default: {
background: {
DEFAULT: 'rgb(0,0,0)',
50: 'rgba(0,0,0,.5)',
},
},
'not-default': {
background: {
DEFAULT: 'rgb(255,255,255)',
50: 'rgba(255,255,255,.5)',
'keep-going': {
DEFAULT: 'rgb(128,128,128)',
50: 'rgba(128,128,128,.5)',
},
},
},
},
})
).toEqual({
'brand-primary': 'rgb(100,0,0)',
'brand-primary-50': 'rgba(100,0,0,.5)',
'theme-default-background': 'rgb(0,0,0)',
'theme-default-background-50': 'rgba(0,0,0,.5)',
'theme-not-default-background': 'rgb(255,255,255)',
'theme-not-default-background-50': 'rgba(255,255,255,.5)',
'theme-not-default-background-keep-going': 'rgb(128,128,128)',
'theme-not-default-background-keep-going-50': 'rgba(128,128,128,.5)',
})
})