forked from tailwindlabs/tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
withAlphaVariable.test.js
97 lines (94 loc) · 2.23 KB
/
withAlphaVariable.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
86
87
88
89
90
91
92
93
94
95
96
97
import withAlphaVariable from '../src/util/withAlphaVariable'
test('it adds the right custom property', () => {
expect(
withAlphaVariable({ color: '#ff0000', property: 'color', variable: '--text-opacity' })
).toEqual({
'--text-opacity': '1',
color: ['#ff0000', 'rgba(255, 0, 0, var(--text-opacity))'],
})
})
test('it ignores colors that cannot be parsed', () => {
expect(
withAlphaVariable({
color: 'currentColor',
property: 'background-color',
variable: '--bg-opacity',
})
).toEqual({
'background-color': 'currentColor',
})
})
test('it ignores colors that already have an alpha channel', () => {
expect(
withAlphaVariable({
color: '#ff0000ff',
property: 'background-color',
variable: '--bg-opacity',
})
).toEqual({
'background-color': '#ff0000ff',
})
expect(
withAlphaVariable({
color: '#ff000080',
property: 'background-color',
variable: '--bg-opacity',
})
).toEqual({
'background-color': '#ff000080',
})
expect(
withAlphaVariable({
color: '#f00a',
property: 'background-color',
variable: '--bg-opacity',
})
).toEqual({
'background-color': '#f00a',
})
expect(
withAlphaVariable({
color: '#f00f',
property: 'background-color',
variable: '--bg-opacity',
})
).toEqual({
'background-color': '#f00f',
})
expect(
withAlphaVariable({
color: 'rgba(255, 255, 255, 1)',
property: 'background-color',
variable: '--bg-opacity',
})
).toEqual({
'background-color': 'rgba(255, 255, 255, 1)',
})
expect(
withAlphaVariable({
color: 'rgba(255, 255, 255, 0.5)',
property: 'background-color',
variable: '--bg-opacity',
})
).toEqual({
'background-color': 'rgba(255, 255, 255, 0.5)',
})
expect(
withAlphaVariable({
color: 'hsla(240, 100%, 50%, 1)',
property: 'background-color',
variable: '--bg-opacity',
})
).toEqual({
'background-color': 'hsla(240, 100%, 50%, 1)',
})
expect(
withAlphaVariable({
color: 'hsla(240, 100%, 50%, 0.5)',
property: 'background-color',
variable: '--bg-opacity',
})
).toEqual({
'background-color': 'hsla(240, 100%, 50%, 0.5)',
})
})