@pyreon/unistyle 0.11.5 → 0.11.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -34
- package/lib/index.d.ts +13 -8
- package/lib/index.js +9 -4
- package/package.json +24 -24
- package/src/__tests__/alignContent.test.ts +57 -57
- package/src/__tests__/borderRadius.test.ts +40 -40
- package/src/__tests__/camelToKebab.test.ts +23 -23
- package/src/__tests__/context.test.ts +28 -28
- package/src/__tests__/createMediaQueries.test.ts +21 -21
- package/src/__tests__/edge.test.ts +76 -76
- package/src/__tests__/enrichTheme.test.ts +13 -13
- package/src/__tests__/index.test.ts +31 -31
- package/src/__tests__/makeItResponsive.test.ts +32 -32
- package/src/__tests__/processDescriptor.test.ts +107 -107
- package/src/__tests__/responsive.test.ts +66 -66
- package/src/__tests__/styles.test.ts +52 -52
- package/src/__tests__/units.test.ts +63 -63
- package/src/context.tsx +11 -6
- package/src/enrichTheme.ts +3 -3
- package/src/index.ts +11 -11
- package/src/responsive/createMediaQueries.ts +4 -4
- package/src/responsive/index.ts +14 -14
- package/src/responsive/makeItResponsive.ts +9 -9
- package/src/responsive/normalizeTheme.ts +2 -2
- package/src/responsive/transformTheme.ts +2 -2
- package/src/styles/alignContent.ts +14 -14
- package/src/styles/extendCss.ts +4 -4
- package/src/styles/index.ts +6 -6
- package/src/styles/shorthands/borderRadius.ts +6 -6
- package/src/styles/shorthands/edge.ts +29 -29
- package/src/styles/shorthands/index.ts +4 -4
- package/src/styles/styles/index.ts +6 -6
- package/src/styles/styles/processDescriptor.ts +31 -31
- package/src/styles/styles/propertyMap.ts +326 -326
- package/src/styles/styles/utils.ts +4 -4
- package/src/types.ts +155 -155
- package/src/units/index.ts +6 -6
- package/src/units/stripUnit.ts +1 -1
- package/src/units/value.ts +20 -20
- package/src/units/values.ts +18 -18
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { describe, expect, it } from
|
|
2
|
-
import edge from
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import edge from '../styles/shorthands/edge'
|
|
3
3
|
|
|
4
4
|
const empty = {
|
|
5
5
|
full: undefined,
|
|
@@ -13,152 +13,152 @@ const empty = {
|
|
|
13
13
|
|
|
14
14
|
const e = edge()
|
|
15
15
|
|
|
16
|
-
describe(
|
|
17
|
-
it(
|
|
18
|
-
expect(e(
|
|
16
|
+
describe('edge', () => {
|
|
17
|
+
it('returns null when no values provided', () => {
|
|
18
|
+
expect(e('margin', empty)).toBeNull()
|
|
19
19
|
})
|
|
20
20
|
|
|
21
|
-
describe(
|
|
22
|
-
it(
|
|
23
|
-
expect(e(
|
|
21
|
+
describe('full shorthand (all same)', () => {
|
|
22
|
+
it('margin with single value', () => {
|
|
23
|
+
expect(e('margin', { ...empty, full: 16 })).toBe('margin: 1rem;')
|
|
24
24
|
})
|
|
25
25
|
|
|
26
|
-
it(
|
|
27
|
-
expect(e(
|
|
26
|
+
it('padding with single value', () => {
|
|
27
|
+
expect(e('padding', { ...empty, full: 32 })).toBe('padding: 2rem;')
|
|
28
28
|
})
|
|
29
29
|
|
|
30
|
-
it(
|
|
31
|
-
expect(e(
|
|
30
|
+
it('inset with single value', () => {
|
|
31
|
+
expect(e('inset', { ...empty, full: 16 })).toBe('inset: 1rem;')
|
|
32
32
|
})
|
|
33
33
|
})
|
|
34
34
|
|
|
35
|
-
describe(
|
|
36
|
-
it(
|
|
37
|
-
const result = e(
|
|
38
|
-
expect(result).toBe(
|
|
35
|
+
describe('two-value shorthand', () => {
|
|
36
|
+
it('top===bottom and right===left', () => {
|
|
37
|
+
const result = e('margin', { ...empty, y: 16, x: 32 })
|
|
38
|
+
expect(result).toBe('margin: 1rem 2rem;')
|
|
39
39
|
})
|
|
40
40
|
})
|
|
41
41
|
|
|
42
|
-
describe(
|
|
43
|
-
it(
|
|
44
|
-
const result = e(
|
|
42
|
+
describe('three-value shorthand', () => {
|
|
43
|
+
it('top, right===left, bottom', () => {
|
|
44
|
+
const result = e('padding', {
|
|
45
45
|
...empty,
|
|
46
46
|
top: 16,
|
|
47
47
|
right: 32,
|
|
48
48
|
bottom: 48,
|
|
49
49
|
left: 32,
|
|
50
50
|
})
|
|
51
|
-
expect(result).toBe(
|
|
51
|
+
expect(result).toBe('padding: 1rem 2rem 3rem;')
|
|
52
52
|
})
|
|
53
53
|
})
|
|
54
54
|
|
|
55
|
-
describe(
|
|
56
|
-
it(
|
|
57
|
-
const result = e(
|
|
55
|
+
describe('four-value shorthand', () => {
|
|
56
|
+
it('all different sides', () => {
|
|
57
|
+
const result = e('margin', {
|
|
58
58
|
...empty,
|
|
59
59
|
top: 16,
|
|
60
60
|
right: 32,
|
|
61
61
|
bottom: 48,
|
|
62
62
|
left: 64,
|
|
63
63
|
})
|
|
64
|
-
expect(result).toBe(
|
|
64
|
+
expect(result).toBe('margin: 1rem 2rem 3rem 4rem;')
|
|
65
65
|
})
|
|
66
66
|
})
|
|
67
67
|
|
|
68
|
-
describe(
|
|
69
|
-
it(
|
|
70
|
-
const result = e(
|
|
71
|
-
expect(result).toBe(
|
|
68
|
+
describe('x and y values', () => {
|
|
69
|
+
it('x sets left and right', () => {
|
|
70
|
+
const result = e('margin', { ...empty, x: 16 })
|
|
71
|
+
expect(result).toBe('margin-left: 1rem;margin-right: 1rem;')
|
|
72
72
|
})
|
|
73
73
|
|
|
74
|
-
it(
|
|
75
|
-
const result = e(
|
|
76
|
-
expect(result).toBe(
|
|
74
|
+
it('y sets top and bottom', () => {
|
|
75
|
+
const result = e('margin', { ...empty, y: 16 })
|
|
76
|
+
expect(result).toBe('margin-top: 1rem;margin-bottom: 1rem;')
|
|
77
77
|
})
|
|
78
78
|
})
|
|
79
79
|
|
|
80
|
-
describe(
|
|
81
|
-
it(
|
|
82
|
-
const result = e(
|
|
80
|
+
describe('individual sides override x/y/full', () => {
|
|
81
|
+
it('top overrides y', () => {
|
|
82
|
+
const result = e('margin', { ...empty, y: 16, top: 32, x: 16 })
|
|
83
83
|
// t=32, r=16, b=16, l=16 → r===l so 3-value shorthand
|
|
84
|
-
expect(result).toBe(
|
|
84
|
+
expect(result).toBe('margin: 2rem 1rem 1rem;')
|
|
85
85
|
})
|
|
86
86
|
|
|
87
|
-
it(
|
|
88
|
-
const result = e(
|
|
89
|
-
expect(result).toBe(
|
|
87
|
+
it('left overrides x', () => {
|
|
88
|
+
const result = e('padding', { ...empty, full: 16, left: 32 })
|
|
89
|
+
expect(result).toBe('padding: 1rem 1rem 1rem 2rem;')
|
|
90
90
|
})
|
|
91
91
|
})
|
|
92
92
|
|
|
93
|
-
describe(
|
|
94
|
-
it(
|
|
95
|
-
expect(e(
|
|
93
|
+
describe('border-width uses px unit', () => {
|
|
94
|
+
it('border-width with full value', () => {
|
|
95
|
+
expect(e('border-width', { ...empty, full: 1 })).toBe('border-width: 1px;')
|
|
96
96
|
})
|
|
97
97
|
|
|
98
|
-
it(
|
|
99
|
-
const result = e(
|
|
100
|
-
expect(result).toBe(
|
|
98
|
+
it('border-width individual sides', () => {
|
|
99
|
+
const result = e('border-width', { ...empty, top: 1, bottom: 2 })
|
|
100
|
+
expect(result).toBe('border-top-width: 1px;border-bottom-width: 2px;')
|
|
101
101
|
})
|
|
102
102
|
})
|
|
103
103
|
|
|
104
|
-
describe(
|
|
105
|
-
it(
|
|
106
|
-
expect(e(
|
|
104
|
+
describe('border-style does not use units', () => {
|
|
105
|
+
it('border-style with full value', () => {
|
|
106
|
+
expect(e('border-style', { ...empty, full: 'solid' })).toBe('border-style: solid;')
|
|
107
107
|
})
|
|
108
108
|
|
|
109
|
-
it(
|
|
110
|
-
const result = e(
|
|
111
|
-
expect(result).toBe(
|
|
109
|
+
it('border-style individual sides', () => {
|
|
110
|
+
const result = e('border-style', { ...empty, top: 'solid', bottom: 'dashed' })
|
|
111
|
+
expect(result).toBe('border-top-style: solid;border-bottom-style: dashed;')
|
|
112
112
|
})
|
|
113
113
|
})
|
|
114
114
|
|
|
115
|
-
describe(
|
|
116
|
-
it(
|
|
117
|
-
expect(e(
|
|
115
|
+
describe('border-color does not use units', () => {
|
|
116
|
+
it('border-color with full value', () => {
|
|
117
|
+
expect(e('border-color', { ...empty, full: 'red' })).toBe('border-color: red;')
|
|
118
118
|
})
|
|
119
119
|
|
|
120
|
-
it(
|
|
121
|
-
const result = e(
|
|
122
|
-
expect(result).toBe(
|
|
120
|
+
it('border-color individual sides', () => {
|
|
121
|
+
const result = e('border-color', { ...empty, top: 'red', left: 'blue' })
|
|
122
|
+
expect(result).toBe('border-top-color: red;border-left-color: blue;')
|
|
123
123
|
})
|
|
124
124
|
})
|
|
125
125
|
|
|
126
|
-
describe(
|
|
127
|
-
it(
|
|
128
|
-
expect(e(
|
|
126
|
+
describe('individual format when not all sides have values', () => {
|
|
127
|
+
it('only top is set', () => {
|
|
128
|
+
expect(e('margin', { ...empty, top: 16 })).toBe('margin-top: 1rem;')
|
|
129
129
|
})
|
|
130
130
|
|
|
131
|
-
it(
|
|
132
|
-
const result = e(
|
|
133
|
-
expect(result).toBe(
|
|
131
|
+
it('only left and right are set', () => {
|
|
132
|
+
const result = e('padding', { ...empty, left: 16, right: 32 })
|
|
133
|
+
expect(result).toBe('padding-left: 1rem;padding-right: 2rem;')
|
|
134
134
|
})
|
|
135
135
|
|
|
136
|
-
it(
|
|
137
|
-
const result = e(
|
|
138
|
-
expect(result).toBe(
|
|
136
|
+
it('inset individual sides', () => {
|
|
137
|
+
const result = e('inset', { ...empty, top: 0, left: 16 })
|
|
138
|
+
expect(result).toBe('top: 0;left: 1rem;')
|
|
139
139
|
})
|
|
140
140
|
})
|
|
141
141
|
|
|
142
|
-
describe(
|
|
143
|
-
it(
|
|
144
|
-
expect(e(
|
|
142
|
+
describe('zero values are valid', () => {
|
|
143
|
+
it('zero full value', () => {
|
|
144
|
+
expect(e('margin', { ...empty, full: 0 })).toBe('margin: 0;')
|
|
145
145
|
})
|
|
146
146
|
|
|
147
|
-
it(
|
|
148
|
-
expect(e(
|
|
147
|
+
it('zero individual side', () => {
|
|
148
|
+
expect(e('padding', { ...empty, top: 0 })).toBe('padding-top: 0;')
|
|
149
149
|
})
|
|
150
150
|
})
|
|
151
151
|
|
|
152
|
-
describe(
|
|
153
|
-
it(
|
|
152
|
+
describe('custom rootSize', () => {
|
|
153
|
+
it('uses custom rootSize for conversion', () => {
|
|
154
154
|
const eCustom = edge(10)
|
|
155
|
-
expect(eCustom(
|
|
155
|
+
expect(eCustom('margin', { ...empty, full: 20 })).toBe('margin: 2rem;')
|
|
156
156
|
})
|
|
157
157
|
})
|
|
158
158
|
|
|
159
|
-
describe(
|
|
160
|
-
it(
|
|
161
|
-
expect(e(
|
|
159
|
+
describe('string values', () => {
|
|
160
|
+
it('passes through string values like auto', () => {
|
|
161
|
+
expect(e('margin', { ...empty, full: 'auto' })).toBe('margin: auto;')
|
|
162
162
|
})
|
|
163
163
|
})
|
|
164
164
|
})
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { describe, expect, it } from
|
|
2
|
-
import { enrichTheme } from
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { enrichTheme } from '../enrichTheme'
|
|
3
3
|
|
|
4
|
-
describe(
|
|
5
|
-
it(
|
|
4
|
+
describe('enrichTheme', () => {
|
|
5
|
+
it('adds __PYREON__ with sortedBreakpoints and media', () => {
|
|
6
6
|
const theme = { rootSize: 16, breakpoints: { xs: 0, sm: 576, md: 768 } }
|
|
7
7
|
const result = enrichTheme(theme)
|
|
8
8
|
|
|
9
9
|
expect(result.__PYREON__).toBeDefined()
|
|
10
|
-
expect(result.__PYREON__.sortedBreakpoints).toEqual([
|
|
10
|
+
expect(result.__PYREON__.sortedBreakpoints).toEqual(['xs', 'sm', 'md'])
|
|
11
11
|
expect(result.__PYREON__.media).toBeDefined()
|
|
12
|
-
expect(typeof result.__PYREON__.media?.sm).toBe(
|
|
12
|
+
expect(typeof result.__PYREON__.media?.sm).toBe('function')
|
|
13
13
|
})
|
|
14
14
|
|
|
15
|
-
it(
|
|
16
|
-
const theme = { rootSize: 16, colors: { primary:
|
|
15
|
+
it('preserves custom theme properties', () => {
|
|
16
|
+
const theme = { rootSize: 16, colors: { primary: 'blue' } }
|
|
17
17
|
const result = enrichTheme(theme)
|
|
18
18
|
|
|
19
|
-
expect(result.colors).toEqual({ primary:
|
|
19
|
+
expect(result.colors).toEqual({ primary: 'blue' })
|
|
20
20
|
expect(result.rootSize).toBe(16)
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
-
it(
|
|
23
|
+
it('handles theme without breakpoints', () => {
|
|
24
24
|
const theme = { rootSize: 16 }
|
|
25
25
|
const result = enrichTheme(theme)
|
|
26
26
|
|
|
@@ -29,7 +29,7 @@ describe("enrichTheme", () => {
|
|
|
29
29
|
expect(result.__PYREON__.media).toBeUndefined()
|
|
30
30
|
})
|
|
31
31
|
|
|
32
|
-
it(
|
|
32
|
+
it('handles empty breakpoints', () => {
|
|
33
33
|
const theme = { rootSize: 16, breakpoints: {} }
|
|
34
34
|
const result = enrichTheme(theme)
|
|
35
35
|
|
|
@@ -37,7 +37,7 @@ describe("enrichTheme", () => {
|
|
|
37
37
|
expect(result.__PYREON__.media).toBeUndefined()
|
|
38
38
|
})
|
|
39
39
|
|
|
40
|
-
it(
|
|
40
|
+
it('defaults rootSize to 16', () => {
|
|
41
41
|
const theme = { breakpoints: { sm: 576 } }
|
|
42
42
|
const result = enrichTheme(theme)
|
|
43
43
|
|
|
@@ -45,7 +45,7 @@ describe("enrichTheme", () => {
|
|
|
45
45
|
expect(result.__PYREON__.media).toBeDefined()
|
|
46
46
|
})
|
|
47
47
|
|
|
48
|
-
it(
|
|
48
|
+
it('is a pure function — does not mutate input', () => {
|
|
49
49
|
const theme = { rootSize: 16, breakpoints: { xs: 0, md: 768 } }
|
|
50
50
|
const copy = { ...theme }
|
|
51
51
|
enrichTheme(theme)
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import { describe, expect, it } from
|
|
2
|
-
import * as unistyle from
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import * as unistyle from '../index'
|
|
3
3
|
|
|
4
|
-
describe(
|
|
5
|
-
it(
|
|
4
|
+
describe('index exports', () => {
|
|
5
|
+
it('exports breakpoints', () => {
|
|
6
6
|
expect(unistyle.breakpoints).toBeDefined()
|
|
7
|
-
expect(typeof unistyle.breakpoints).toBe(
|
|
7
|
+
expect(typeof unistyle.breakpoints).toBe('object')
|
|
8
8
|
})
|
|
9
9
|
|
|
10
|
-
it(
|
|
10
|
+
it('exports sortBreakpoints', () => {
|
|
11
11
|
expect(unistyle.sortBreakpoints).toBeDefined()
|
|
12
|
-
expect(typeof unistyle.sortBreakpoints).toBe(
|
|
12
|
+
expect(typeof unistyle.sortBreakpoints).toBe('function')
|
|
13
13
|
})
|
|
14
14
|
|
|
15
|
-
it(
|
|
15
|
+
it('exports createMediaQueries', () => {
|
|
16
16
|
expect(unistyle.createMediaQueries).toBeDefined()
|
|
17
|
-
expect(typeof unistyle.createMediaQueries).toBe(
|
|
17
|
+
expect(typeof unistyle.createMediaQueries).toBe('function')
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
-
it(
|
|
20
|
+
it('exports makeItResponsive', () => {
|
|
21
21
|
expect(unistyle.makeItResponsive).toBeDefined()
|
|
22
|
-
expect(typeof unistyle.makeItResponsive).toBe(
|
|
22
|
+
expect(typeof unistyle.makeItResponsive).toBe('function')
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
it(
|
|
25
|
+
it('exports normalizeTheme', () => {
|
|
26
26
|
expect(unistyle.normalizeTheme).toBeDefined()
|
|
27
|
-
expect(typeof unistyle.normalizeTheme).toBe(
|
|
27
|
+
expect(typeof unistyle.normalizeTheme).toBe('function')
|
|
28
28
|
})
|
|
29
29
|
|
|
30
|
-
it(
|
|
30
|
+
it('exports transformTheme', () => {
|
|
31
31
|
expect(unistyle.transformTheme).toBeDefined()
|
|
32
|
-
expect(typeof unistyle.transformTheme).toBe(
|
|
32
|
+
expect(typeof unistyle.transformTheme).toBe('function')
|
|
33
33
|
})
|
|
34
34
|
|
|
35
|
-
it(
|
|
35
|
+
it('exports styles', () => {
|
|
36
36
|
expect(unistyle.styles).toBeDefined()
|
|
37
|
-
expect(typeof unistyle.styles).toBe(
|
|
37
|
+
expect(typeof unistyle.styles).toBe('function')
|
|
38
38
|
})
|
|
39
39
|
|
|
40
|
-
it(
|
|
40
|
+
it('exports alignContent', () => {
|
|
41
41
|
expect(unistyle.alignContent).toBeDefined()
|
|
42
|
-
expect(typeof unistyle.alignContent).toBe(
|
|
42
|
+
expect(typeof unistyle.alignContent).toBe('function')
|
|
43
43
|
})
|
|
44
44
|
|
|
45
|
-
it(
|
|
45
|
+
it('exports extendCss', () => {
|
|
46
46
|
expect(unistyle.extendCss).toBeDefined()
|
|
47
|
-
expect(typeof unistyle.extendCss).toBe(
|
|
47
|
+
expect(typeof unistyle.extendCss).toBe('function')
|
|
48
48
|
})
|
|
49
49
|
|
|
50
|
-
it(
|
|
50
|
+
it('exports stripUnit', () => {
|
|
51
51
|
expect(unistyle.stripUnit).toBeDefined()
|
|
52
|
-
expect(typeof unistyle.stripUnit).toBe(
|
|
52
|
+
expect(typeof unistyle.stripUnit).toBe('function')
|
|
53
53
|
})
|
|
54
54
|
|
|
55
|
-
it(
|
|
55
|
+
it('exports value', () => {
|
|
56
56
|
expect(unistyle.value).toBeDefined()
|
|
57
|
-
expect(typeof unistyle.value).toBe(
|
|
57
|
+
expect(typeof unistyle.value).toBe('function')
|
|
58
58
|
})
|
|
59
59
|
|
|
60
|
-
it(
|
|
60
|
+
it('exports values', () => {
|
|
61
61
|
expect(unistyle.values).toBeDefined()
|
|
62
|
-
expect(typeof unistyle.values).toBe(
|
|
62
|
+
expect(typeof unistyle.values).toBe('function')
|
|
63
63
|
})
|
|
64
64
|
|
|
65
|
-
it(
|
|
65
|
+
it('exports Provider', () => {
|
|
66
66
|
expect(unistyle.Provider).toBeDefined()
|
|
67
|
-
expect(typeof unistyle.Provider).toBe(
|
|
67
|
+
expect(typeof unistyle.Provider).toBe('function')
|
|
68
68
|
})
|
|
69
69
|
|
|
70
|
-
it(
|
|
70
|
+
it('exports context', () => {
|
|
71
71
|
expect(unistyle.context).toBeDefined()
|
|
72
72
|
})
|
|
73
73
|
|
|
74
|
-
it(
|
|
74
|
+
it('exports align content constants', () => {
|
|
75
75
|
expect(unistyle.ALIGN_CONTENT_DIRECTION).toBeDefined()
|
|
76
76
|
expect(unistyle.ALIGN_CONTENT_MAP_X).toBeDefined()
|
|
77
77
|
expect(unistyle.ALIGN_CONTENT_MAP_Y).toBeDefined()
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
2
|
|
|
3
|
-
vi.mock(
|
|
3
|
+
vi.mock('@pyreon/ui-core', () => ({
|
|
4
4
|
isEmpty: (val: unknown) =>
|
|
5
|
-
val == null || (typeof val ===
|
|
5
|
+
val == null || (typeof val === 'object' && Object.keys(val as object).length === 0),
|
|
6
6
|
set: (obj: any, path: (string | number)[], value: unknown) => {
|
|
7
7
|
let current = obj
|
|
8
8
|
for (let i = 0; i < path.length - 1; i++) {
|
|
9
9
|
const key = path[i] as string | number
|
|
10
|
-
if (current[key] == null || typeof current[key] !==
|
|
10
|
+
if (current[key] == null || typeof current[key] !== 'object') {
|
|
11
11
|
current[key] = {}
|
|
12
12
|
}
|
|
13
13
|
current = current[key]
|
|
@@ -17,10 +17,10 @@ vi.mock("@pyreon/ui-core", () => ({
|
|
|
17
17
|
},
|
|
18
18
|
}))
|
|
19
19
|
|
|
20
|
-
import makeItResponsive from
|
|
20
|
+
import makeItResponsive from '../responsive/makeItResponsive'
|
|
21
21
|
|
|
22
22
|
const mockCss = (strings: TemplateStringsArray, ...vals: any[]) => {
|
|
23
|
-
let r =
|
|
23
|
+
let r = ''
|
|
24
24
|
for (let i = 0; i < strings.length; i++) {
|
|
25
25
|
r += strings[i]
|
|
26
26
|
if (i < vals.length) r += String(vals[i])
|
|
@@ -31,76 +31,76 @@ const mockCss = (strings: TemplateStringsArray, ...vals: any[]) => {
|
|
|
31
31
|
const mockStyles = ({ theme }: { theme: Record<string, unknown> }) => {
|
|
32
32
|
return Object.entries(theme)
|
|
33
33
|
.map(([k, v]) => `${k}: ${v};`)
|
|
34
|
-
.join(
|
|
34
|
+
.join(' ')
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
describe(
|
|
38
|
-
it(
|
|
37
|
+
describe('makeItResponsive', () => {
|
|
38
|
+
it('returns empty string when customTheme is empty/undefined', () => {
|
|
39
39
|
const responsive = makeItResponsive({
|
|
40
|
-
key:
|
|
40
|
+
key: 'styles',
|
|
41
41
|
css: mockCss,
|
|
42
42
|
styles: mockStyles,
|
|
43
43
|
})
|
|
44
44
|
|
|
45
45
|
const result = responsive({ theme: {} })
|
|
46
|
-
expect(result).toBe(
|
|
46
|
+
expect(result).toBe('')
|
|
47
47
|
})
|
|
48
48
|
|
|
49
|
-
it(
|
|
49
|
+
it('returns empty string when customTheme is empty object', () => {
|
|
50
50
|
const responsive = makeItResponsive({
|
|
51
51
|
theme: {},
|
|
52
|
-
key:
|
|
52
|
+
key: 'styles',
|
|
53
53
|
css: mockCss,
|
|
54
54
|
styles: mockStyles,
|
|
55
55
|
})
|
|
56
56
|
|
|
57
57
|
const result = responsive({ theme: {} })
|
|
58
|
-
expect(result).toBe(
|
|
58
|
+
expect(result).toBe('')
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
-
it(
|
|
61
|
+
it('without breakpoints: wraps styles output in css template', () => {
|
|
62
62
|
const responsive = makeItResponsive({
|
|
63
|
-
theme: { color:
|
|
63
|
+
theme: { color: 'red' },
|
|
64
64
|
css: mockCss,
|
|
65
65
|
styles: mockStyles,
|
|
66
66
|
})
|
|
67
67
|
|
|
68
68
|
const result = responsive({ theme: {} })
|
|
69
|
-
expect(result).toContain(
|
|
69
|
+
expect(result).toContain('color: red;')
|
|
70
70
|
})
|
|
71
71
|
|
|
72
|
-
it(
|
|
72
|
+
it('uses props[key] when theme is not provided', () => {
|
|
73
73
|
const responsive = makeItResponsive({
|
|
74
|
-
key:
|
|
74
|
+
key: 'myStyles',
|
|
75
75
|
css: mockCss,
|
|
76
76
|
styles: mockStyles,
|
|
77
77
|
})
|
|
78
78
|
|
|
79
79
|
const result = responsive({
|
|
80
80
|
theme: {},
|
|
81
|
-
myStyles: { fontSize:
|
|
81
|
+
myStyles: { fontSize: '16px' },
|
|
82
82
|
})
|
|
83
83
|
|
|
84
|
-
expect(result).toContain(
|
|
84
|
+
expect(result).toContain('fontSize: 16px;')
|
|
85
85
|
})
|
|
86
86
|
|
|
87
|
-
it(
|
|
88
|
-
const sortedBreakpoints = [
|
|
87
|
+
it('with breakpoints and __PYREON__: returns array of media-wrapped styles per breakpoint', () => {
|
|
88
|
+
const sortedBreakpoints = ['xs', 'sm']
|
|
89
89
|
const media: Record<string, (strings: TemplateStringsArray, ...vals: any[]) => string> = {
|
|
90
90
|
xs: mockCss,
|
|
91
91
|
sm: (strings: TemplateStringsArray, ...vals: any[]) => {
|
|
92
|
-
let r =
|
|
92
|
+
let r = '@media (min-width: 36em) {'
|
|
93
93
|
for (let i = 0; i < strings.length; i++) {
|
|
94
94
|
r += strings[i]
|
|
95
95
|
if (i < vals.length) r += String(vals[i])
|
|
96
96
|
}
|
|
97
|
-
r +=
|
|
97
|
+
r += '}'
|
|
98
98
|
return r
|
|
99
99
|
},
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
const responsive = makeItResponsive({
|
|
103
|
-
theme: { color: { xs:
|
|
103
|
+
theme: { color: { xs: 'red', sm: 'blue' } },
|
|
104
104
|
css: mockCss,
|
|
105
105
|
styles: mockStyles,
|
|
106
106
|
normalize: true,
|
|
@@ -117,14 +117,14 @@ describe("makeItResponsive", () => {
|
|
|
117
117
|
expect(result).toHaveLength(2)
|
|
118
118
|
})
|
|
119
119
|
|
|
120
|
-
it(
|
|
121
|
-
const sortedBreakpoints = [
|
|
120
|
+
it('caching: second call with same internalTheme object returns same result', () => {
|
|
121
|
+
const sortedBreakpoints = ['xs', 'sm']
|
|
122
122
|
const media: Record<string, (strings: TemplateStringsArray, ...vals: any[]) => string> = {
|
|
123
123
|
xs: mockCss,
|
|
124
124
|
sm: mockCss,
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
const themeObj = { color: { xs:
|
|
127
|
+
const themeObj = { color: { xs: 'red', sm: 'blue' } }
|
|
128
128
|
|
|
129
129
|
const responsive = makeItResponsive({
|
|
130
130
|
theme: themeObj,
|
|
@@ -143,8 +143,8 @@ describe("makeItResponsive", () => {
|
|
|
143
143
|
expect(result1).toEqual(result2)
|
|
144
144
|
})
|
|
145
145
|
|
|
146
|
-
it(
|
|
147
|
-
const sortedBreakpoints = [
|
|
146
|
+
it('normalize=false skips normalizeTheme step', () => {
|
|
147
|
+
const sortedBreakpoints = ['xs', 'sm']
|
|
148
148
|
const media: Record<string, (strings: TemplateStringsArray, ...vals: any[]) => string> = {
|
|
149
149
|
xs: mockCss,
|
|
150
150
|
sm: mockCss,
|
|
@@ -153,7 +153,7 @@ describe("makeItResponsive", () => {
|
|
|
153
153
|
// When normalize=false, object values are not expanded across breakpoints.
|
|
154
154
|
// Provide a pre-normalized theme (object keyed by breakpoint names).
|
|
155
155
|
const responsive = makeItResponsive({
|
|
156
|
-
theme: { color: { xs:
|
|
156
|
+
theme: { color: { xs: 'red', sm: 'blue' } },
|
|
157
157
|
css: mockCss,
|
|
158
158
|
styles: mockStyles,
|
|
159
159
|
normalize: false,
|