@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 borderRadius from
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import borderRadius from '../styles/shorthands/borderRadius'
|
|
3
3
|
|
|
4
4
|
const empty = {
|
|
5
5
|
full: undefined,
|
|
@@ -15,27 +15,27 @@ const empty = {
|
|
|
15
15
|
|
|
16
16
|
const br = borderRadius()
|
|
17
17
|
|
|
18
|
-
describe(
|
|
19
|
-
it(
|
|
18
|
+
describe('borderRadius', () => {
|
|
19
|
+
it('returns null when no values provided', () => {
|
|
20
20
|
expect(br(empty)).toBeNull()
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
-
describe(
|
|
24
|
-
it(
|
|
25
|
-
expect(br({ ...empty, full: 16 })).toBe(
|
|
23
|
+
describe('full shorthand', () => {
|
|
24
|
+
it('all same value produces single-value shorthand', () => {
|
|
25
|
+
expect(br({ ...empty, full: 16 })).toBe('border-radius: 1rem;')
|
|
26
26
|
})
|
|
27
27
|
|
|
28
|
-
it(
|
|
29
|
-
expect(br({ ...empty, full: 0 })).toBe(
|
|
28
|
+
it('zero is a valid value', () => {
|
|
29
|
+
expect(br({ ...empty, full: 0 })).toBe('border-radius: 0;')
|
|
30
30
|
})
|
|
31
31
|
|
|
32
|
-
it(
|
|
33
|
-
expect(br({ ...empty, full:
|
|
32
|
+
it('string values pass through', () => {
|
|
33
|
+
expect(br({ ...empty, full: '50%' })).toBe('border-radius: 50%;')
|
|
34
34
|
})
|
|
35
35
|
})
|
|
36
36
|
|
|
37
|
-
describe(
|
|
38
|
-
it(
|
|
37
|
+
describe('two-value shorthand', () => {
|
|
38
|
+
it('tl===br and tr===bl produces two-value shorthand', () => {
|
|
39
39
|
const result = br({
|
|
40
40
|
...empty,
|
|
41
41
|
topLeft: 16,
|
|
@@ -43,12 +43,12 @@ describe("borderRadius", () => {
|
|
|
43
43
|
bottomRight: 16,
|
|
44
44
|
bottomLeft: 32,
|
|
45
45
|
})
|
|
46
|
-
expect(result).toBe(
|
|
46
|
+
expect(result).toBe('border-radius: 1rem 2rem;')
|
|
47
47
|
})
|
|
48
48
|
})
|
|
49
49
|
|
|
50
|
-
describe(
|
|
51
|
-
it(
|
|
50
|
+
describe('three-value shorthand', () => {
|
|
51
|
+
it('tl, tr===bl, br produces three-value shorthand', () => {
|
|
52
52
|
const result = br({
|
|
53
53
|
...empty,
|
|
54
54
|
topLeft: 16,
|
|
@@ -56,12 +56,12 @@ describe("borderRadius", () => {
|
|
|
56
56
|
bottomRight: 48,
|
|
57
57
|
bottomLeft: 32,
|
|
58
58
|
})
|
|
59
|
-
expect(result).toBe(
|
|
59
|
+
expect(result).toBe('border-radius: 1rem 2rem 3rem;')
|
|
60
60
|
})
|
|
61
61
|
})
|
|
62
62
|
|
|
63
|
-
describe(
|
|
64
|
-
it(
|
|
63
|
+
describe('four-value shorthand', () => {
|
|
64
|
+
it('all different produces four-value shorthand', () => {
|
|
65
65
|
const result = br({
|
|
66
66
|
...empty,
|
|
67
67
|
topLeft: 16,
|
|
@@ -69,57 +69,57 @@ describe("borderRadius", () => {
|
|
|
69
69
|
bottomRight: 48,
|
|
70
70
|
bottomLeft: 64,
|
|
71
71
|
})
|
|
72
|
-
expect(result).toBe(
|
|
72
|
+
expect(result).toBe('border-radius: 1rem 2rem 3rem 4rem;')
|
|
73
73
|
})
|
|
74
74
|
})
|
|
75
75
|
|
|
76
|
-
describe(
|
|
77
|
-
it(
|
|
76
|
+
describe('per-side values', () => {
|
|
77
|
+
it('top sets topLeft and topRight', () => {
|
|
78
78
|
const result = br({ ...empty, top: 16, bottom: 32 })
|
|
79
|
-
expect(result).toBe(
|
|
79
|
+
expect(result).toBe('border-radius: 1rem 1rem 2rem 2rem;')
|
|
80
80
|
})
|
|
81
81
|
|
|
82
|
-
it(
|
|
82
|
+
it('left sets topLeft and bottomLeft', () => {
|
|
83
83
|
const result = br({ ...empty, left: 16, right: 32 })
|
|
84
|
-
expect(result).toBe(
|
|
84
|
+
expect(result).toBe('border-radius: 1rem 2rem 2rem 1rem;')
|
|
85
85
|
})
|
|
86
86
|
})
|
|
87
87
|
|
|
88
|
-
describe(
|
|
89
|
-
it(
|
|
88
|
+
describe('individual corners override sides', () => {
|
|
89
|
+
it('topLeft overrides top and left', () => {
|
|
90
90
|
const result = br({ ...empty, top: 16, topLeft: 32, bottom: 16 })
|
|
91
91
|
// tl=32, tr=16, br=16, bl=16 → tr===bl so 3-value shorthand
|
|
92
|
-
expect(result).toBe(
|
|
92
|
+
expect(result).toBe('border-radius: 2rem 1rem 1rem;')
|
|
93
93
|
})
|
|
94
94
|
|
|
95
|
-
it(
|
|
95
|
+
it('bottomRight overrides bottom and right', () => {
|
|
96
96
|
const result = br({ ...empty, full: 16, bottomRight: 32 })
|
|
97
97
|
// tl=16, tr=16, br=32, bl=16 → tr===bl so 3-value shorthand
|
|
98
|
-
expect(result).toBe(
|
|
98
|
+
expect(result).toBe('border-radius: 1rem 1rem 2rem;')
|
|
99
99
|
})
|
|
100
100
|
})
|
|
101
101
|
|
|
102
|
-
describe(
|
|
103
|
-
it(
|
|
102
|
+
describe('individual properties when not all corners have values', () => {
|
|
103
|
+
it('only topLeft is set', () => {
|
|
104
104
|
const result = br({ ...empty, topLeft: 16 })
|
|
105
|
-
expect(result).toBe(
|
|
105
|
+
expect(result).toBe('border-top-left-radius: 1rem;')
|
|
106
106
|
})
|
|
107
107
|
|
|
108
|
-
it(
|
|
108
|
+
it('topLeft and bottomRight are set', () => {
|
|
109
109
|
const result = br({ ...empty, topLeft: 16, bottomRight: 32 })
|
|
110
|
-
expect(result).toBe(
|
|
110
|
+
expect(result).toBe('border-top-left-radius: 1rem;border-bottom-right-radius: 2rem;')
|
|
111
111
|
})
|
|
112
112
|
|
|
113
|
-
it(
|
|
113
|
+
it('top only sets topLeft and topRight individual properties', () => {
|
|
114
114
|
const result = br({ ...empty, top: 16 })
|
|
115
|
-
expect(result).toBe(
|
|
115
|
+
expect(result).toBe('border-top-left-radius: 1rem;border-top-right-radius: 1rem;')
|
|
116
116
|
})
|
|
117
117
|
})
|
|
118
118
|
|
|
119
|
-
describe(
|
|
120
|
-
it(
|
|
119
|
+
describe('custom rootSize', () => {
|
|
120
|
+
it('uses custom rootSize for conversion', () => {
|
|
121
121
|
const brCustom = borderRadius(10)
|
|
122
|
-
expect(brCustom({ ...empty, full: 20 })).toBe(
|
|
122
|
+
expect(brCustom({ ...empty, full: 20 })).toBe('border-radius: 2rem;')
|
|
123
123
|
})
|
|
124
124
|
})
|
|
125
125
|
})
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { describe, expect, it } from
|
|
2
|
-
import camelToKebab from
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import camelToKebab from '../styles/styles/camelToKebab'
|
|
3
3
|
|
|
4
|
-
describe(
|
|
5
|
-
it(
|
|
6
|
-
expect(camelToKebab(
|
|
4
|
+
describe('camelToKebab', () => {
|
|
5
|
+
it('converts camelCase to kebab-case', () => {
|
|
6
|
+
expect(camelToKebab('backgroundColor')).toBe('background-color')
|
|
7
7
|
})
|
|
8
8
|
|
|
9
|
-
it(
|
|
10
|
-
expect(camelToKebab(
|
|
9
|
+
it('converts multiple uppercase letters', () => {
|
|
10
|
+
expect(camelToKebab('borderTopLeftRadius')).toBe('border-top-left-radius')
|
|
11
11
|
})
|
|
12
12
|
|
|
13
|
-
it(
|
|
14
|
-
expect(camelToKebab(
|
|
13
|
+
it('returns lowercase strings unchanged', () => {
|
|
14
|
+
expect(camelToKebab('color')).toBe('color')
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
it(
|
|
18
|
-
expect(camelToKebab(
|
|
17
|
+
it('returns empty string for empty input', () => {
|
|
18
|
+
expect(camelToKebab('')).toBe('')
|
|
19
19
|
})
|
|
20
20
|
|
|
21
|
-
it(
|
|
22
|
-
expect(camelToKebab(
|
|
21
|
+
it('handles single uppercase letter', () => {
|
|
22
|
+
expect(camelToKebab('A')).toBe('-a')
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
it(
|
|
26
|
-
expect(camelToKebab(
|
|
25
|
+
it('handles leading lowercase', () => {
|
|
26
|
+
expect(camelToKebab('fontSize')).toBe('font-size')
|
|
27
27
|
})
|
|
28
28
|
|
|
29
|
-
it(
|
|
30
|
-
expect(camelToKebab(
|
|
29
|
+
it('handles consecutive uppercase letters individually', () => {
|
|
30
|
+
expect(camelToKebab('msOverflowStyle')).toBe('ms-overflow-style')
|
|
31
31
|
})
|
|
32
32
|
|
|
33
|
-
it(
|
|
34
|
-
expect(camelToKebab(
|
|
33
|
+
it('handles boxSizing', () => {
|
|
34
|
+
expect(camelToKebab('boxSizing')).toBe('box-sizing')
|
|
35
35
|
})
|
|
36
36
|
|
|
37
|
-
it(
|
|
38
|
-
expect(camelToKebab(
|
|
37
|
+
it('handles flexDirection', () => {
|
|
38
|
+
expect(camelToKebab('flexDirection')).toBe('flex-direction')
|
|
39
39
|
})
|
|
40
40
|
|
|
41
|
-
it(
|
|
42
|
-
expect(camelToKebab(
|
|
41
|
+
it('handles justifyContent', () => {
|
|
42
|
+
expect(camelToKebab('justifyContent')).toBe('justify-content')
|
|
43
43
|
})
|
|
44
44
|
})
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
2
|
|
|
3
|
-
vi.mock(
|
|
4
|
-
const mockContext = { id: Symbol(
|
|
3
|
+
vi.mock('@pyreon/ui-core', () => {
|
|
4
|
+
const mockContext = { id: Symbol('test-context') }
|
|
5
5
|
return {
|
|
6
6
|
Provider: vi.fn((props: any) => props.children ?? null),
|
|
7
7
|
config: {
|
|
8
8
|
css: (strings: TemplateStringsArray, ...vals: any[]) => {
|
|
9
|
-
let r =
|
|
9
|
+
let r = ''
|
|
10
10
|
for (let i = 0; i < strings.length; i++) {
|
|
11
11
|
r += strings[i]
|
|
12
12
|
if (i < vals.length) r += String(vals[i])
|
|
@@ -16,12 +16,12 @@ vi.mock("@pyreon/ui-core", () => {
|
|
|
16
16
|
},
|
|
17
17
|
context: mockContext,
|
|
18
18
|
isEmpty: (val: unknown) =>
|
|
19
|
-
val == null || (typeof val ===
|
|
19
|
+
val == null || (typeof val === 'object' && Object.keys(val as object).length === 0),
|
|
20
20
|
}
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
-
import { Provider as CoreProvider } from
|
|
24
|
-
import Provider, { context } from
|
|
23
|
+
import { Provider as CoreProvider } from '@pyreon/ui-core'
|
|
24
|
+
import Provider, { context } from '../context'
|
|
25
25
|
|
|
26
26
|
const mockCoreProvider = CoreProvider as ReturnType<typeof vi.fn>
|
|
27
27
|
|
|
@@ -32,13 +32,13 @@ const firstCallArg = () => {
|
|
|
32
32
|
return (calls[0] as any[])[0] as any
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
describe(
|
|
36
|
-
it(
|
|
35
|
+
describe('Provider', () => {
|
|
36
|
+
it('exports context from @pyreon/ui-core', () => {
|
|
37
37
|
expect(context).toBeDefined()
|
|
38
|
-
expect(context).toHaveProperty(
|
|
38
|
+
expect(context).toHaveProperty('id')
|
|
39
39
|
})
|
|
40
40
|
|
|
41
|
-
it(
|
|
41
|
+
it('calls CoreProvider with enriched theme', () => {
|
|
42
42
|
mockCoreProvider.mockClear()
|
|
43
43
|
|
|
44
44
|
Provider({
|
|
@@ -48,10 +48,10 @@ describe("Provider", () => {
|
|
|
48
48
|
|
|
49
49
|
expect(mockCoreProvider).toHaveBeenCalledTimes(1)
|
|
50
50
|
const calledWith = firstCallArg()
|
|
51
|
-
expect(calledWith.theme).toHaveProperty(
|
|
51
|
+
expect(calledWith.theme).toHaveProperty('__PYREON__')
|
|
52
52
|
})
|
|
53
53
|
|
|
54
|
-
it(
|
|
54
|
+
it('when theme has no breakpoints: __PYREON__ has undefined sortedBreakpoints and media', () => {
|
|
55
55
|
mockCoreProvider.mockClear()
|
|
56
56
|
|
|
57
57
|
Provider({
|
|
@@ -64,7 +64,7 @@ describe("Provider", () => {
|
|
|
64
64
|
expect(enrichedTheme.__PYREON__.media).toBeUndefined()
|
|
65
65
|
})
|
|
66
66
|
|
|
67
|
-
it(
|
|
67
|
+
it('when theme has empty breakpoints: __PYREON__ has undefined sortedBreakpoints and media', () => {
|
|
68
68
|
mockCoreProvider.mockClear()
|
|
69
69
|
|
|
70
70
|
Provider({
|
|
@@ -77,7 +77,7 @@ describe("Provider", () => {
|
|
|
77
77
|
expect(enrichedTheme.__PYREON__.media).toBeUndefined()
|
|
78
78
|
})
|
|
79
79
|
|
|
80
|
-
it(
|
|
80
|
+
it('when theme has breakpoints: __PYREON__ has sortedBreakpoints and media objects', () => {
|
|
81
81
|
mockCoreProvider.mockClear()
|
|
82
82
|
|
|
83
83
|
Provider({
|
|
@@ -89,15 +89,15 @@ describe("Provider", () => {
|
|
|
89
89
|
})
|
|
90
90
|
|
|
91
91
|
const enrichedTheme = firstCallArg().theme
|
|
92
|
-
expect(enrichedTheme.__PYREON__.sortedBreakpoints).toEqual([
|
|
92
|
+
expect(enrichedTheme.__PYREON__.sortedBreakpoints).toEqual(['xs', 'sm', 'md'])
|
|
93
93
|
expect(enrichedTheme.__PYREON__.media).toBeDefined()
|
|
94
|
-
expect(Object.keys(enrichedTheme.__PYREON__.media)).toEqual([
|
|
94
|
+
expect(Object.keys(enrichedTheme.__PYREON__.media)).toEqual(['xs', 'sm', 'md'])
|
|
95
95
|
})
|
|
96
96
|
|
|
97
|
-
it(
|
|
97
|
+
it('passes children through to CoreProvider', () => {
|
|
98
98
|
mockCoreProvider.mockClear()
|
|
99
99
|
|
|
100
|
-
const mockChild = { type:
|
|
100
|
+
const mockChild = { type: 'div' } as any
|
|
101
101
|
Provider({
|
|
102
102
|
theme: { rootSize: 16 },
|
|
103
103
|
children: mockChild,
|
|
@@ -107,20 +107,20 @@ describe("Provider", () => {
|
|
|
107
107
|
expect(calledWith.children).toBe(mockChild)
|
|
108
108
|
})
|
|
109
109
|
|
|
110
|
-
it(
|
|
110
|
+
it('preserves other theme properties in enriched theme', () => {
|
|
111
111
|
mockCoreProvider.mockClear()
|
|
112
112
|
|
|
113
113
|
Provider({
|
|
114
|
-
theme: { rootSize: 16, customProp:
|
|
114
|
+
theme: { rootSize: 16, customProp: 'hello' } as any,
|
|
115
115
|
children: null,
|
|
116
116
|
})
|
|
117
117
|
|
|
118
118
|
const enrichedTheme = firstCallArg().theme
|
|
119
119
|
expect(enrichedTheme.rootSize).toBe(16)
|
|
120
|
-
expect(enrichedTheme.customProp).toBe(
|
|
120
|
+
expect(enrichedTheme.customProp).toBe('hello')
|
|
121
121
|
})
|
|
122
122
|
|
|
123
|
-
it(
|
|
123
|
+
it('media functions are callable tagged template functions', () => {
|
|
124
124
|
mockCoreProvider.mockClear()
|
|
125
125
|
|
|
126
126
|
Provider({
|
|
@@ -132,16 +132,16 @@ describe("Provider", () => {
|
|
|
132
132
|
})
|
|
133
133
|
|
|
134
134
|
const media = firstCallArg().theme.__PYREON__.media
|
|
135
|
-
expect(typeof media.xs).toBe(
|
|
136
|
-
expect(typeof media.sm).toBe(
|
|
135
|
+
expect(typeof media.xs).toBe('function')
|
|
136
|
+
expect(typeof media.sm).toBe('function')
|
|
137
137
|
|
|
138
138
|
// xs (value 0) should pass through
|
|
139
139
|
const xsResult = media.xs`color: red;`
|
|
140
|
-
expect(xsResult).toContain(
|
|
141
|
-
expect(xsResult).not.toContain(
|
|
140
|
+
expect(xsResult).toContain('color: red;')
|
|
141
|
+
expect(xsResult).not.toContain('@media')
|
|
142
142
|
|
|
143
143
|
// sm (value 576) should wrap in media query
|
|
144
144
|
const smResult = media.sm`color: blue;`
|
|
145
|
-
expect(smResult).toContain(
|
|
145
|
+
expect(smResult).toContain('@media only screen and (min-width: 36em)')
|
|
146
146
|
})
|
|
147
147
|
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { describe, expect, it } from
|
|
2
|
-
import createMediaQueries from
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import createMediaQueries from '../responsive/createMediaQueries'
|
|
3
3
|
|
|
4
4
|
const mockCss = (strings: TemplateStringsArray, ...vals: any[]) => {
|
|
5
|
-
let r =
|
|
5
|
+
let r = ''
|
|
6
6
|
for (let i = 0; i < strings.length; i++) {
|
|
7
7
|
r += strings[i]
|
|
8
8
|
if (i < vals.length) r += String(vals[i])
|
|
@@ -10,18 +10,18 @@ const mockCss = (strings: TemplateStringsArray, ...vals: any[]) => {
|
|
|
10
10
|
return r
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
describe(
|
|
14
|
-
it(
|
|
13
|
+
describe('createMediaQueries', () => {
|
|
14
|
+
it('returns an object with keys matching breakpoint names', () => {
|
|
15
15
|
const result = createMediaQueries({
|
|
16
16
|
breakpoints: { xs: 0, sm: 576, md: 768 },
|
|
17
17
|
rootSize: 16,
|
|
18
18
|
css: mockCss,
|
|
19
19
|
})
|
|
20
20
|
|
|
21
|
-
expect(Object.keys(result)).toEqual([
|
|
21
|
+
expect(Object.keys(result)).toEqual(['xs', 'sm', 'md'])
|
|
22
22
|
})
|
|
23
23
|
|
|
24
|
-
it(
|
|
24
|
+
it('multiple breakpoints produce correct number of keys', () => {
|
|
25
25
|
const result = createMediaQueries({
|
|
26
26
|
breakpoints: { xs: 0, sm: 576, md: 768, lg: 992, xl: 1200 },
|
|
27
27
|
rootSize: 16,
|
|
@@ -31,7 +31,7 @@ describe("createMediaQueries", () => {
|
|
|
31
31
|
expect(Object.keys(result)).toHaveLength(5)
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
it(
|
|
34
|
+
it('for breakpoint with value 0: passes through to css directly (no @media wrapper)', () => {
|
|
35
35
|
const result = createMediaQueries({
|
|
36
36
|
breakpoints: { xs: 0 },
|
|
37
37
|
rootSize: 16,
|
|
@@ -39,11 +39,11 @@ describe("createMediaQueries", () => {
|
|
|
39
39
|
})
|
|
40
40
|
|
|
41
41
|
const output = result.xs`color: red;`
|
|
42
|
-
expect(output).toBe(
|
|
43
|
-
expect(output).not.toContain(
|
|
42
|
+
expect(output).toBe('color: red;')
|
|
43
|
+
expect(output).not.toContain('@media')
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
-
it(
|
|
46
|
+
it('for breakpoint with non-zero value: wraps in @media with em calculation', () => {
|
|
47
47
|
const result = createMediaQueries({
|
|
48
48
|
breakpoints: { sm: 576 },
|
|
49
49
|
rootSize: 16,
|
|
@@ -52,11 +52,11 @@ describe("createMediaQueries", () => {
|
|
|
52
52
|
|
|
53
53
|
const output = result.sm`color: blue;`
|
|
54
54
|
// 576 / 16 = 36
|
|
55
|
-
expect(output).toContain(
|
|
56
|
-
expect(output).toContain(
|
|
55
|
+
expect(output).toContain('@media only screen and (min-width: 36em)')
|
|
56
|
+
expect(output).toContain('color: blue;')
|
|
57
57
|
})
|
|
58
58
|
|
|
59
|
-
it(
|
|
59
|
+
it('calculates em size as breakpointValue / rootSize', () => {
|
|
60
60
|
const result = createMediaQueries({
|
|
61
61
|
breakpoints: { md: 768 },
|
|
62
62
|
rootSize: 16,
|
|
@@ -65,10 +65,10 @@ describe("createMediaQueries", () => {
|
|
|
65
65
|
|
|
66
66
|
const output = result.md`font-size: 1rem;`
|
|
67
67
|
// 768 / 16 = 48
|
|
68
|
-
expect(output).toContain(
|
|
68
|
+
expect(output).toContain('48em')
|
|
69
69
|
})
|
|
70
70
|
|
|
71
|
-
it(
|
|
71
|
+
it('respects custom rootSize', () => {
|
|
72
72
|
const result = createMediaQueries({
|
|
73
73
|
breakpoints: { lg: 992 },
|
|
74
74
|
rootSize: 10,
|
|
@@ -77,10 +77,10 @@ describe("createMediaQueries", () => {
|
|
|
77
77
|
|
|
78
78
|
const output = result.lg`display: flex;`
|
|
79
79
|
// 992 / 10 = 99.2
|
|
80
|
-
expect(output).toContain(
|
|
80
|
+
expect(output).toContain('99.2em')
|
|
81
81
|
})
|
|
82
82
|
|
|
83
|
-
it(
|
|
83
|
+
it('handles mixed zero and non-zero breakpoints', () => {
|
|
84
84
|
const result = createMediaQueries({
|
|
85
85
|
breakpoints: { xs: 0, sm: 576, md: 768 },
|
|
86
86
|
rootSize: 16,
|
|
@@ -91,8 +91,8 @@ describe("createMediaQueries", () => {
|
|
|
91
91
|
const smOutput = result.sm`color: blue;`
|
|
92
92
|
const mdOutput = result.md`color: green;`
|
|
93
93
|
|
|
94
|
-
expect(xsOutput).not.toContain(
|
|
95
|
-
expect(smOutput).toContain(
|
|
96
|
-
expect(mdOutput).toContain(
|
|
94
|
+
expect(xsOutput).not.toContain('@media')
|
|
95
|
+
expect(smOutput).toContain('@media only screen and (min-width: 36em)')
|
|
96
|
+
expect(mdOutput).toContain('@media only screen and (min-width: 48em)')
|
|
97
97
|
})
|
|
98
98
|
})
|