@pyreon/elements 0.13.0 → 0.14.0
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/lib/index.d.ts.map +1 -1
- package/lib/index.js +24 -1
- package/lib/index.js.map +1 -1
- package/package.json +10 -10
- package/src/Element/component.tsx +58 -16
- package/src/__tests__/Element.test.ts +95 -46
- package/src/__tests__/equalBeforeAfter.test.ts +4 -4
- package/src/__tests__/integration.test.tsx +36 -5
- package/src/__tests__/perf-stress.browser.test.tsx +119 -0
- package/src/__tests__/responsiveProps.test.ts +59 -28
|
@@ -7,6 +7,37 @@ import Wrapper from '../helpers/Wrapper/component'
|
|
|
7
7
|
|
|
8
8
|
const asVNode = (v: unknown) => v as VNode
|
|
9
9
|
|
|
10
|
+
// See Element.test.ts for context — Element's simple-element fast path moves
|
|
11
|
+
// layout props from `result.props.{tag, direction, …}` to
|
|
12
|
+
// `result.props.{as, $element.direction, …}`. This helper reads from
|
|
13
|
+
// whichever shape the result is in.
|
|
14
|
+
const getLayoutProps = (result: VNode): Record<string, unknown> => {
|
|
15
|
+
const p = result.props as Record<string, unknown>
|
|
16
|
+
if (p.$element && typeof p.$element === 'object') {
|
|
17
|
+
const el = p.$element as Record<string, unknown>
|
|
18
|
+
return {
|
|
19
|
+
tag: p.as,
|
|
20
|
+
direction: el.direction,
|
|
21
|
+
alignX: el.alignX,
|
|
22
|
+
alignY: el.alignY,
|
|
23
|
+
block: el.block,
|
|
24
|
+
equalCols: el.equalCols,
|
|
25
|
+
extendCss: el.extraStyles,
|
|
26
|
+
isInline: undefined,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
tag: p.tag,
|
|
31
|
+
direction: p.direction,
|
|
32
|
+
alignX: p.alignX,
|
|
33
|
+
alignY: p.alignY,
|
|
34
|
+
block: p.block,
|
|
35
|
+
equalCols: p.equalCols,
|
|
36
|
+
extendCss: p.extendCss,
|
|
37
|
+
isInline: p.isInline,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
10
41
|
const getContentSlots = (result: VNode): VNode[] => {
|
|
11
42
|
const children = result.props.children
|
|
12
43
|
if (!Array.isArray(children)) return []
|
|
@@ -20,17 +51,17 @@ describe('Element responsive props', () => {
|
|
|
20
51
|
describe('single values', () => {
|
|
21
52
|
it('renders with alignX as string', () => {
|
|
22
53
|
const result = asVNode(Element({ alignX: 'center', children: 'content' }))
|
|
23
|
-
expect(result.type).toBe(
|
|
54
|
+
expect(typeof result.type).toBe("function")
|
|
24
55
|
})
|
|
25
56
|
|
|
26
57
|
it('renders with alignY as string', () => {
|
|
27
58
|
const result = asVNode(Element({ alignY: 'top', children: 'content' }))
|
|
28
|
-
expect(result.type).toBe(
|
|
59
|
+
expect(typeof result.type).toBe("function")
|
|
29
60
|
})
|
|
30
61
|
|
|
31
62
|
it('renders with direction as string', () => {
|
|
32
63
|
const result = asVNode(Element({ direction: 'rows', children: 'content' }))
|
|
33
|
-
expect(result.type).toBe(
|
|
64
|
+
expect(typeof result.type).toBe("function")
|
|
34
65
|
})
|
|
35
66
|
|
|
36
67
|
it('renders with gap as number', () => {
|
|
@@ -42,13 +73,13 @@ describe('Element responsive props', () => {
|
|
|
42
73
|
children: 'content',
|
|
43
74
|
}),
|
|
44
75
|
)
|
|
45
|
-
expect(result.type).toBe(
|
|
76
|
+
expect(typeof result.type).toBe("function")
|
|
46
77
|
})
|
|
47
78
|
|
|
48
79
|
it('renders with block as boolean', () => {
|
|
49
80
|
const result = asVNode(Element({ block: true, children: 'content' }))
|
|
50
|
-
expect(result.type).toBe(
|
|
51
|
-
expect(result.
|
|
81
|
+
expect(typeof result.type).toBe("function")
|
|
82
|
+
expect(getLayoutProps(result).block).toBe(true)
|
|
52
83
|
})
|
|
53
84
|
|
|
54
85
|
it('renders with equalCols as boolean', () => {
|
|
@@ -60,7 +91,7 @@ describe('Element responsive props', () => {
|
|
|
60
91
|
children: 'content',
|
|
61
92
|
}),
|
|
62
93
|
)
|
|
63
|
-
expect(result.type).toBe(
|
|
94
|
+
expect(typeof result.type).toBe("function")
|
|
64
95
|
})
|
|
65
96
|
})
|
|
66
97
|
|
|
@@ -69,19 +100,19 @@ describe('Element responsive props', () => {
|
|
|
69
100
|
const result = asVNode(
|
|
70
101
|
Element({ alignX: ['left', 'center', 'right'] as any, children: 'content' }),
|
|
71
102
|
)
|
|
72
|
-
expect(result.type).toBe(
|
|
103
|
+
expect(typeof result.type).toBe("function")
|
|
73
104
|
})
|
|
74
105
|
|
|
75
106
|
it('renders with alignY as array', () => {
|
|
76
107
|
const result = asVNode(
|
|
77
108
|
Element({ alignY: ['top', 'center', 'bottom'] as any, children: 'content' }),
|
|
78
109
|
)
|
|
79
|
-
expect(result.type).toBe(
|
|
110
|
+
expect(typeof result.type).toBe("function")
|
|
80
111
|
})
|
|
81
112
|
|
|
82
113
|
it('renders with direction as array', () => {
|
|
83
114
|
const result = asVNode(Element({ direction: ['rows', 'inline'] as any, children: 'content' }))
|
|
84
|
-
expect(result.type).toBe(
|
|
115
|
+
expect(typeof result.type).toBe("function")
|
|
85
116
|
})
|
|
86
117
|
|
|
87
118
|
it('renders with gap as array', () => {
|
|
@@ -92,12 +123,12 @@ describe('Element responsive props', () => {
|
|
|
92
123
|
children: 'content',
|
|
93
124
|
}),
|
|
94
125
|
)
|
|
95
|
-
expect(result.type).toBe(
|
|
126
|
+
expect(typeof result.type).toBe("function")
|
|
96
127
|
})
|
|
97
128
|
|
|
98
129
|
it('renders with block as array', () => {
|
|
99
130
|
const result = asVNode(Element({ block: [false, true] as any, children: 'content' }))
|
|
100
|
-
expect(result.type).toBe(
|
|
131
|
+
expect(typeof result.type).toBe("function")
|
|
101
132
|
})
|
|
102
133
|
|
|
103
134
|
it('renders with equalCols as array', () => {
|
|
@@ -109,7 +140,7 @@ describe('Element responsive props', () => {
|
|
|
109
140
|
children: 'content',
|
|
110
141
|
}),
|
|
111
142
|
)
|
|
112
|
-
expect(result.type).toBe(
|
|
143
|
+
expect(typeof result.type).toBe("function")
|
|
113
144
|
})
|
|
114
145
|
})
|
|
115
146
|
|
|
@@ -121,14 +152,14 @@ describe('Element responsive props', () => {
|
|
|
121
152
|
children: 'content',
|
|
122
153
|
}),
|
|
123
154
|
)
|
|
124
|
-
expect(result.type).toBe(
|
|
155
|
+
expect(typeof result.type).toBe("function")
|
|
125
156
|
})
|
|
126
157
|
|
|
127
158
|
it('renders with alignY as breakpoint object', () => {
|
|
128
159
|
const result = asVNode(
|
|
129
160
|
Element({ alignY: { xs: 'top', lg: 'center' } as any, children: 'content' }),
|
|
130
161
|
)
|
|
131
|
-
expect(result.type).toBe(
|
|
162
|
+
expect(typeof result.type).toBe("function")
|
|
132
163
|
})
|
|
133
164
|
|
|
134
165
|
it('renders with direction as breakpoint object', () => {
|
|
@@ -138,7 +169,7 @@ describe('Element responsive props', () => {
|
|
|
138
169
|
children: 'content',
|
|
139
170
|
}),
|
|
140
171
|
)
|
|
141
|
-
expect(result.type).toBe(
|
|
172
|
+
expect(typeof result.type).toBe("function")
|
|
142
173
|
})
|
|
143
174
|
|
|
144
175
|
it('renders with gap as breakpoint object', () => {
|
|
@@ -149,14 +180,14 @@ describe('Element responsive props', () => {
|
|
|
149
180
|
children: 'content',
|
|
150
181
|
}),
|
|
151
182
|
)
|
|
152
|
-
expect(result.type).toBe(
|
|
183
|
+
expect(typeof result.type).toBe("function")
|
|
153
184
|
})
|
|
154
185
|
|
|
155
186
|
it('renders with block as breakpoint object', () => {
|
|
156
187
|
const result = asVNode(
|
|
157
188
|
Element({ block: { xs: false, md: true } as any, children: 'content' }),
|
|
158
189
|
)
|
|
159
|
-
expect(result.type).toBe(
|
|
190
|
+
expect(typeof result.type).toBe("function")
|
|
160
191
|
})
|
|
161
192
|
})
|
|
162
193
|
|
|
@@ -174,7 +205,7 @@ describe('Element responsive props', () => {
|
|
|
174
205
|
children: h('span', { 'data-testid': 'main' }, 'Main'),
|
|
175
206
|
}),
|
|
176
207
|
)
|
|
177
|
-
expect(result.type).toBe(
|
|
208
|
+
expect(typeof result.type).toBe("function")
|
|
178
209
|
const slots = getContentSlots(result)
|
|
179
210
|
expect(slots).toHaveLength(3)
|
|
180
211
|
})
|
|
@@ -190,7 +221,7 @@ describe('Element responsive props', () => {
|
|
|
190
221
|
children: h('span', null, 'Main'),
|
|
191
222
|
}),
|
|
192
223
|
)
|
|
193
|
-
expect(result.type).toBe(
|
|
224
|
+
expect(typeof result.type).toBe("function")
|
|
194
225
|
const slots = getContentSlots(result)
|
|
195
226
|
expect(slots).toHaveLength(3)
|
|
196
227
|
})
|
|
@@ -207,15 +238,15 @@ describe('Element responsive props', () => {
|
|
|
207
238
|
children: 'content',
|
|
208
239
|
}),
|
|
209
240
|
)
|
|
210
|
-
expect(result.type).toBe(
|
|
241
|
+
expect(typeof result.type).toBe("function")
|
|
211
242
|
})
|
|
212
243
|
})
|
|
213
244
|
|
|
214
245
|
describe('responsive css prop', () => {
|
|
215
246
|
it('renders with css as string', () => {
|
|
216
247
|
const result = asVNode(Element({ css: 'background: red;', children: 'content' }))
|
|
217
|
-
expect(result.type).toBe(
|
|
218
|
-
expect(result.
|
|
248
|
+
expect(typeof result.type).toBe("function")
|
|
249
|
+
expect(getLayoutProps(result).extendCss).toBe('background: red;')
|
|
219
250
|
})
|
|
220
251
|
|
|
221
252
|
it('renders with contentCss', () => {
|
|
@@ -226,7 +257,7 @@ describe('Element responsive props', () => {
|
|
|
226
257
|
children: 'content',
|
|
227
258
|
}),
|
|
228
259
|
)
|
|
229
|
-
expect(result.type).toBe(
|
|
260
|
+
expect(typeof result.type).toBe("function")
|
|
230
261
|
const slots = getContentSlots(result)
|
|
231
262
|
const contentSlot = slots.find((v) => v.props.contentType === 'content')
|
|
232
263
|
expect(contentSlot?.props.extendCss).toBe('color: blue;')
|
|
@@ -242,7 +273,7 @@ describe('Element responsive props', () => {
|
|
|
242
273
|
children: 'content',
|
|
243
274
|
}),
|
|
244
275
|
)
|
|
245
|
-
expect(result.type).toBe(
|
|
276
|
+
expect(typeof result.type).toBe("function")
|
|
246
277
|
const slots = getContentSlots(result)
|
|
247
278
|
const beforeSlot = slots.find((v) => v.props.contentType === 'before')
|
|
248
279
|
const afterSlot = slots.find((v) => v.props.contentType === 'after')
|
|
@@ -273,14 +304,14 @@ describe('Element responsive props', () => {
|
|
|
273
304
|
for (const value of alignXValues) {
|
|
274
305
|
it(`renders with alignX="${value}"`, () => {
|
|
275
306
|
const result = asVNode(Element({ alignX: value, children: 'content' }))
|
|
276
|
-
expect(result.type).toBe(
|
|
307
|
+
expect(typeof result.type).toBe("function")
|
|
277
308
|
})
|
|
278
309
|
}
|
|
279
310
|
|
|
280
311
|
for (const value of alignYValues) {
|
|
281
312
|
it(`renders with alignY="${value}"`, () => {
|
|
282
313
|
const result = asVNode(Element({ alignY: value, children: 'content' }))
|
|
283
|
-
expect(result.type).toBe(
|
|
314
|
+
expect(typeof result.type).toBe("function")
|
|
284
315
|
})
|
|
285
316
|
}
|
|
286
317
|
})
|
|
@@ -291,7 +322,7 @@ describe('Element responsive props', () => {
|
|
|
291
322
|
for (const value of directionValues) {
|
|
292
323
|
it(`renders with direction="${value}"`, () => {
|
|
293
324
|
const result = asVNode(Element({ direction: value, children: 'content' }))
|
|
294
|
-
expect(result.type).toBe(
|
|
325
|
+
expect(typeof result.type).toBe("function")
|
|
295
326
|
})
|
|
296
327
|
}
|
|
297
328
|
})
|