@pyreon/elements 0.11.5 → 0.11.6
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 +38 -35
- package/lib/index.d.ts +15 -15
- package/package.json +24 -24
- package/src/Element/component.tsx +14 -14
- package/src/Element/constants.ts +25 -25
- package/src/Element/index.ts +2 -2
- package/src/Element/types.ts +3 -3
- package/src/Element/utils.ts +1 -1
- package/src/List/component.tsx +7 -7
- package/src/List/index.ts +2 -2
- package/src/Overlay/component.tsx +22 -22
- package/src/Overlay/context.tsx +2 -2
- package/src/Overlay/index.ts +3 -3
- package/src/Overlay/useOverlay.tsx +97 -97
- package/src/Portal/component.tsx +6 -6
- package/src/Portal/index.ts +2 -2
- package/src/Text/component.tsx +6 -6
- package/src/Text/index.ts +2 -2
- package/src/Text/styled.ts +4 -4
- package/src/Util/component.tsx +5 -5
- package/src/Util/index.ts +2 -2
- package/src/__tests__/Content.test.tsx +46 -46
- package/src/__tests__/Element.test.ts +251 -251
- package/src/__tests__/Iterator.test.ts +142 -142
- package/src/__tests__/List.test.ts +61 -61
- package/src/__tests__/Overlay.test.ts +125 -125
- package/src/__tests__/Portal.test.ts +33 -33
- package/src/__tests__/Text.test.ts +128 -128
- package/src/__tests__/Util.test.ts +31 -31
- package/src/__tests__/Wrapper.test.tsx +60 -60
- package/src/__tests__/equalBeforeAfter.test.ts +41 -41
- package/src/__tests__/helpers.test.ts +29 -29
- package/src/__tests__/overlayContext.test.tsx +14 -14
- package/src/__tests__/responsiveProps.test.ts +116 -116
- package/src/__tests__/useOverlay.test.ts +283 -283
- package/src/__tests__/utils.test.ts +43 -43
- package/src/constants.ts +1 -1
- package/src/helpers/Content/component.tsx +5 -5
- package/src/helpers/Content/index.ts +1 -1
- package/src/helpers/Content/styled.ts +16 -16
- package/src/helpers/Content/types.ts +7 -7
- package/src/helpers/Iterator/component.tsx +28 -28
- package/src/helpers/Iterator/index.ts +2 -2
- package/src/helpers/Iterator/types.ts +3 -3
- package/src/helpers/Wrapper/component.tsx +6 -6
- package/src/helpers/Wrapper/index.ts +1 -1
- package/src/helpers/Wrapper/styled.ts +8 -8
- package/src/helpers/Wrapper/types.ts +3 -3
- package/src/helpers/Wrapper/utils.ts +1 -1
- package/src/helpers/index.ts +2 -2
- package/src/index.ts +16 -16
- package/src/types.ts +7 -7
- package/src/utils.ts +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { VNode } from
|
|
2
|
-
import { h } from
|
|
3
|
-
import { describe, expect, it } from
|
|
4
|
-
import { Element } from
|
|
5
|
-
import Content from
|
|
6
|
-
import Wrapper from
|
|
1
|
+
import type { VNode } from '@pyreon/core'
|
|
2
|
+
import { h } from '@pyreon/core'
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
|
+
import { Element } from '../Element'
|
|
5
|
+
import Content from '../helpers/Content/component'
|
|
6
|
+
import Wrapper from '../helpers/Wrapper/component'
|
|
7
7
|
|
|
8
8
|
const asVNode = (v: unknown) => v as VNode
|
|
9
9
|
|
|
@@ -12,166 +12,166 @@ const getContentSlots = (result: VNode): VNode[] => {
|
|
|
12
12
|
if (!Array.isArray(children)) return []
|
|
13
13
|
return children.filter(
|
|
14
14
|
(c: unknown) =>
|
|
15
|
-
c != null && typeof c ===
|
|
15
|
+
c != null && typeof c === 'object' && 'type' in (c as VNode) && (c as VNode).type === Content,
|
|
16
16
|
) as VNode[]
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
describe(
|
|
20
|
-
describe(
|
|
21
|
-
it(
|
|
22
|
-
const result = asVNode(Element({ alignX:
|
|
19
|
+
describe('Element responsive props', () => {
|
|
20
|
+
describe('single values', () => {
|
|
21
|
+
it('renders with alignX as string', () => {
|
|
22
|
+
const result = asVNode(Element({ alignX: 'center', children: 'content' }))
|
|
23
23
|
expect(result.type).toBe(Wrapper)
|
|
24
24
|
})
|
|
25
25
|
|
|
26
|
-
it(
|
|
27
|
-
const result = asVNode(Element({ alignY:
|
|
26
|
+
it('renders with alignY as string', () => {
|
|
27
|
+
const result = asVNode(Element({ alignY: 'top', children: 'content' }))
|
|
28
28
|
expect(result.type).toBe(Wrapper)
|
|
29
29
|
})
|
|
30
30
|
|
|
31
|
-
it(
|
|
32
|
-
const result = asVNode(Element({ direction:
|
|
31
|
+
it('renders with direction as string', () => {
|
|
32
|
+
const result = asVNode(Element({ direction: 'rows', children: 'content' }))
|
|
33
33
|
expect(result.type).toBe(Wrapper)
|
|
34
34
|
})
|
|
35
35
|
|
|
36
|
-
it(
|
|
36
|
+
it('renders with gap as number', () => {
|
|
37
37
|
const result = asVNode(
|
|
38
38
|
Element({
|
|
39
39
|
gap: 16,
|
|
40
|
-
beforeContent: h(
|
|
41
|
-
afterContent: h(
|
|
42
|
-
children:
|
|
40
|
+
beforeContent: h('span', null, 'Before'),
|
|
41
|
+
afterContent: h('span', null, 'After'),
|
|
42
|
+
children: 'content',
|
|
43
43
|
}),
|
|
44
44
|
)
|
|
45
45
|
expect(result.type).toBe(Wrapper)
|
|
46
46
|
})
|
|
47
47
|
|
|
48
|
-
it(
|
|
49
|
-
const result = asVNode(Element({ block: true, children:
|
|
48
|
+
it('renders with block as boolean', () => {
|
|
49
|
+
const result = asVNode(Element({ block: true, children: 'content' }))
|
|
50
50
|
expect(result.type).toBe(Wrapper)
|
|
51
51
|
expect(result.props.block).toBe(true)
|
|
52
52
|
})
|
|
53
53
|
|
|
54
|
-
it(
|
|
54
|
+
it('renders with equalCols as boolean', () => {
|
|
55
55
|
const result = asVNode(
|
|
56
56
|
Element({
|
|
57
57
|
equalCols: true,
|
|
58
|
-
beforeContent: h(
|
|
59
|
-
afterContent: h(
|
|
60
|
-
children:
|
|
58
|
+
beforeContent: h('span', null, 'Before'),
|
|
59
|
+
afterContent: h('span', null, 'After'),
|
|
60
|
+
children: 'content',
|
|
61
61
|
}),
|
|
62
62
|
)
|
|
63
63
|
expect(result.type).toBe(Wrapper)
|
|
64
64
|
})
|
|
65
65
|
})
|
|
66
66
|
|
|
67
|
-
describe(
|
|
68
|
-
it(
|
|
67
|
+
describe('array values (positional breakpoints)', () => {
|
|
68
|
+
it('renders with alignX as array', () => {
|
|
69
69
|
const result = asVNode(
|
|
70
|
-
Element({ alignX: [
|
|
70
|
+
Element({ alignX: ['left', 'center', 'right'] as any, children: 'content' }),
|
|
71
71
|
)
|
|
72
72
|
expect(result.type).toBe(Wrapper)
|
|
73
73
|
})
|
|
74
74
|
|
|
75
|
-
it(
|
|
75
|
+
it('renders with alignY as array', () => {
|
|
76
76
|
const result = asVNode(
|
|
77
|
-
Element({ alignY: [
|
|
77
|
+
Element({ alignY: ['top', 'center', 'bottom'] as any, children: 'content' }),
|
|
78
78
|
)
|
|
79
79
|
expect(result.type).toBe(Wrapper)
|
|
80
80
|
})
|
|
81
81
|
|
|
82
|
-
it(
|
|
83
|
-
const result = asVNode(Element({ direction: [
|
|
82
|
+
it('renders with direction as array', () => {
|
|
83
|
+
const result = asVNode(Element({ direction: ['rows', 'inline'] as any, children: 'content' }))
|
|
84
84
|
expect(result.type).toBe(Wrapper)
|
|
85
85
|
})
|
|
86
86
|
|
|
87
|
-
it(
|
|
87
|
+
it('renders with gap as array', () => {
|
|
88
88
|
const result = asVNode(
|
|
89
89
|
Element({
|
|
90
90
|
gap: [8, 16, 24] as any,
|
|
91
|
-
beforeContent: h(
|
|
92
|
-
children:
|
|
91
|
+
beforeContent: h('span', null, 'Before'),
|
|
92
|
+
children: 'content',
|
|
93
93
|
}),
|
|
94
94
|
)
|
|
95
95
|
expect(result.type).toBe(Wrapper)
|
|
96
96
|
})
|
|
97
97
|
|
|
98
|
-
it(
|
|
99
|
-
const result = asVNode(Element({ block: [false, true] as any, children:
|
|
98
|
+
it('renders with block as array', () => {
|
|
99
|
+
const result = asVNode(Element({ block: [false, true] as any, children: 'content' }))
|
|
100
100
|
expect(result.type).toBe(Wrapper)
|
|
101
101
|
})
|
|
102
102
|
|
|
103
|
-
it(
|
|
103
|
+
it('renders with equalCols as array', () => {
|
|
104
104
|
const result = asVNode(
|
|
105
105
|
Element({
|
|
106
106
|
equalCols: [false, true] as any,
|
|
107
|
-
beforeContent: h(
|
|
108
|
-
afterContent: h(
|
|
109
|
-
children:
|
|
107
|
+
beforeContent: h('span', null, 'Before'),
|
|
108
|
+
afterContent: h('span', null, 'After'),
|
|
109
|
+
children: 'content',
|
|
110
110
|
}),
|
|
111
111
|
)
|
|
112
112
|
expect(result.type).toBe(Wrapper)
|
|
113
113
|
})
|
|
114
114
|
})
|
|
115
115
|
|
|
116
|
-
describe(
|
|
117
|
-
it(
|
|
116
|
+
describe('breakpoint object values', () => {
|
|
117
|
+
it('renders with alignX as breakpoint object', () => {
|
|
118
118
|
const result = asVNode(
|
|
119
119
|
Element({
|
|
120
|
-
alignX: { xs:
|
|
121
|
-
children:
|
|
120
|
+
alignX: { xs: 'left', md: 'center', xl: 'right' } as any,
|
|
121
|
+
children: 'content',
|
|
122
122
|
}),
|
|
123
123
|
)
|
|
124
124
|
expect(result.type).toBe(Wrapper)
|
|
125
125
|
})
|
|
126
126
|
|
|
127
|
-
it(
|
|
127
|
+
it('renders with alignY as breakpoint object', () => {
|
|
128
128
|
const result = asVNode(
|
|
129
|
-
Element({ alignY: { xs:
|
|
129
|
+
Element({ alignY: { xs: 'top', lg: 'center' } as any, children: 'content' }),
|
|
130
130
|
)
|
|
131
131
|
expect(result.type).toBe(Wrapper)
|
|
132
132
|
})
|
|
133
133
|
|
|
134
|
-
it(
|
|
134
|
+
it('renders with direction as breakpoint object', () => {
|
|
135
135
|
const result = asVNode(
|
|
136
136
|
Element({
|
|
137
|
-
direction: { xs:
|
|
138
|
-
children:
|
|
137
|
+
direction: { xs: 'rows', md: 'inline' } as any,
|
|
138
|
+
children: 'content',
|
|
139
139
|
}),
|
|
140
140
|
)
|
|
141
141
|
expect(result.type).toBe(Wrapper)
|
|
142
142
|
})
|
|
143
143
|
|
|
144
|
-
it(
|
|
144
|
+
it('renders with gap as breakpoint object', () => {
|
|
145
145
|
const result = asVNode(
|
|
146
146
|
Element({
|
|
147
147
|
gap: { xs: 8, md: 16, lg: 24 } as any,
|
|
148
|
-
beforeContent: h(
|
|
149
|
-
children:
|
|
148
|
+
beforeContent: h('span', null, 'Before'),
|
|
149
|
+
children: 'content',
|
|
150
150
|
}),
|
|
151
151
|
)
|
|
152
152
|
expect(result.type).toBe(Wrapper)
|
|
153
153
|
})
|
|
154
154
|
|
|
155
|
-
it(
|
|
155
|
+
it('renders with block as breakpoint object', () => {
|
|
156
156
|
const result = asVNode(
|
|
157
|
-
Element({ block: { xs: false, md: true } as any, children:
|
|
157
|
+
Element({ block: { xs: false, md: true } as any, children: 'content' }),
|
|
158
158
|
)
|
|
159
159
|
expect(result.type).toBe(Wrapper)
|
|
160
160
|
})
|
|
161
161
|
})
|
|
162
162
|
|
|
163
|
-
describe(
|
|
164
|
-
it(
|
|
163
|
+
describe('combined responsive props', () => {
|
|
164
|
+
it('renders with multiple responsive props simultaneously', () => {
|
|
165
165
|
const result = asVNode(
|
|
166
166
|
Element({
|
|
167
|
-
alignX: { xs:
|
|
168
|
-
alignY: [
|
|
169
|
-
direction: { xs:
|
|
167
|
+
alignX: { xs: 'left', md: 'center' } as any,
|
|
168
|
+
alignY: ['top', 'center'] as any,
|
|
169
|
+
direction: { xs: 'rows', lg: 'inline' } as any,
|
|
170
170
|
block: [false, true] as any,
|
|
171
171
|
gap: 16,
|
|
172
|
-
beforeContent: h(
|
|
173
|
-
afterContent: h(
|
|
174
|
-
children: h(
|
|
172
|
+
beforeContent: h('span', { 'data-testid': 'before' }, 'Before'),
|
|
173
|
+
afterContent: h('span', { 'data-testid': 'after' }, 'After'),
|
|
174
|
+
children: h('span', { 'data-testid': 'main' }, 'Main'),
|
|
175
175
|
}),
|
|
176
176
|
)
|
|
177
177
|
expect(result.type).toBe(Wrapper)
|
|
@@ -179,15 +179,15 @@ describe("Element responsive props", () => {
|
|
|
179
179
|
expect(slots).toHaveLength(3)
|
|
180
180
|
})
|
|
181
181
|
|
|
182
|
-
it(
|
|
182
|
+
it('renders with responsive content directions', () => {
|
|
183
183
|
const result = asVNode(
|
|
184
184
|
Element({
|
|
185
|
-
contentDirection: { xs:
|
|
186
|
-
beforeContentDirection: { xs:
|
|
187
|
-
afterContentDirection:
|
|
188
|
-
beforeContent: h(
|
|
189
|
-
afterContent: h(
|
|
190
|
-
children: h(
|
|
185
|
+
contentDirection: { xs: 'rows', md: 'inline' } as any,
|
|
186
|
+
beforeContentDirection: { xs: 'inline', lg: 'rows' } as any,
|
|
187
|
+
afterContentDirection: 'inline',
|
|
188
|
+
beforeContent: h('span', null, 'Before'),
|
|
189
|
+
afterContent: h('span', null, 'After'),
|
|
190
|
+
children: h('span', null, 'Main'),
|
|
191
191
|
}),
|
|
192
192
|
)
|
|
193
193
|
expect(result.type).toBe(Wrapper)
|
|
@@ -195,102 +195,102 @@ describe("Element responsive props", () => {
|
|
|
195
195
|
expect(slots).toHaveLength(3)
|
|
196
196
|
})
|
|
197
197
|
|
|
198
|
-
it(
|
|
198
|
+
it('renders with responsive content alignment', () => {
|
|
199
199
|
const result = asVNode(
|
|
200
200
|
Element({
|
|
201
|
-
contentAlignX: { xs:
|
|
202
|
-
contentAlignY: [
|
|
203
|
-
beforeContentAlignX:
|
|
204
|
-
afterContentAlignX:
|
|
205
|
-
beforeContent: h(
|
|
206
|
-
afterContent: h(
|
|
207
|
-
children:
|
|
201
|
+
contentAlignX: { xs: 'left', md: 'center' } as any,
|
|
202
|
+
contentAlignY: ['top', 'center', 'bottom'] as any,
|
|
203
|
+
beforeContentAlignX: 'left',
|
|
204
|
+
afterContentAlignX: 'right',
|
|
205
|
+
beforeContent: h('span', null, 'Before'),
|
|
206
|
+
afterContent: h('span', null, 'After'),
|
|
207
|
+
children: 'content',
|
|
208
208
|
}),
|
|
209
209
|
)
|
|
210
210
|
expect(result.type).toBe(Wrapper)
|
|
211
211
|
})
|
|
212
212
|
})
|
|
213
213
|
|
|
214
|
-
describe(
|
|
215
|
-
it(
|
|
216
|
-
const result = asVNode(Element({ css:
|
|
214
|
+
describe('responsive css prop', () => {
|
|
215
|
+
it('renders with css as string', () => {
|
|
216
|
+
const result = asVNode(Element({ css: 'background: red;', children: 'content' }))
|
|
217
217
|
expect(result.type).toBe(Wrapper)
|
|
218
|
-
expect(result.props.extendCss).toBe(
|
|
218
|
+
expect(result.props.extendCss).toBe('background: red;')
|
|
219
219
|
})
|
|
220
220
|
|
|
221
|
-
it(
|
|
221
|
+
it('renders with contentCss', () => {
|
|
222
222
|
const result = asVNode(
|
|
223
223
|
Element({
|
|
224
|
-
contentCss:
|
|
225
|
-
beforeContent: h(
|
|
226
|
-
children:
|
|
224
|
+
contentCss: 'color: blue;',
|
|
225
|
+
beforeContent: h('span', null, 'Before'),
|
|
226
|
+
children: 'content',
|
|
227
227
|
}),
|
|
228
228
|
)
|
|
229
229
|
expect(result.type).toBe(Wrapper)
|
|
230
230
|
const slots = getContentSlots(result)
|
|
231
|
-
const contentSlot = slots.find((v) => v.props.contentType ===
|
|
232
|
-
expect(contentSlot?.props.extendCss).toBe(
|
|
231
|
+
const contentSlot = slots.find((v) => v.props.contentType === 'content')
|
|
232
|
+
expect(contentSlot?.props.extendCss).toBe('color: blue;')
|
|
233
233
|
})
|
|
234
234
|
|
|
235
|
-
it(
|
|
235
|
+
it('renders with beforeContentCss and afterContentCss', () => {
|
|
236
236
|
const result = asVNode(
|
|
237
237
|
Element({
|
|
238
|
-
beforeContentCss:
|
|
239
|
-
afterContentCss:
|
|
240
|
-
beforeContent: h(
|
|
241
|
-
afterContent: h(
|
|
242
|
-
children:
|
|
238
|
+
beforeContentCss: 'padding: 4px;',
|
|
239
|
+
afterContentCss: 'padding: 8px;',
|
|
240
|
+
beforeContent: h('span', null, 'Before'),
|
|
241
|
+
afterContent: h('span', null, 'After'),
|
|
242
|
+
children: 'content',
|
|
243
243
|
}),
|
|
244
244
|
)
|
|
245
245
|
expect(result.type).toBe(Wrapper)
|
|
246
246
|
const slots = getContentSlots(result)
|
|
247
|
-
const beforeSlot = slots.find((v) => v.props.contentType ===
|
|
248
|
-
const afterSlot = slots.find((v) => v.props.contentType ===
|
|
249
|
-
expect(beforeSlot?.props.extendCss).toBe(
|
|
250
|
-
expect(afterSlot?.props.extendCss).toBe(
|
|
247
|
+
const beforeSlot = slots.find((v) => v.props.contentType === 'before')
|
|
248
|
+
const afterSlot = slots.find((v) => v.props.contentType === 'after')
|
|
249
|
+
expect(beforeSlot?.props.extendCss).toBe('padding: 4px;')
|
|
250
|
+
expect(afterSlot?.props.extendCss).toBe('padding: 8px;')
|
|
251
251
|
})
|
|
252
252
|
})
|
|
253
253
|
|
|
254
|
-
describe(
|
|
254
|
+
describe('alignment values', () => {
|
|
255
255
|
const alignXValues = [
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
256
|
+
'left',
|
|
257
|
+
'center',
|
|
258
|
+
'right',
|
|
259
|
+
'spaceBetween',
|
|
260
|
+
'spaceAround',
|
|
261
|
+
'block',
|
|
262
262
|
] as const
|
|
263
263
|
|
|
264
264
|
const alignYValues = [
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
265
|
+
'top',
|
|
266
|
+
'center',
|
|
267
|
+
'bottom',
|
|
268
|
+
'spaceBetween',
|
|
269
|
+
'spaceAround',
|
|
270
|
+
'block',
|
|
271
271
|
] as const
|
|
272
272
|
|
|
273
273
|
for (const value of alignXValues) {
|
|
274
274
|
it(`renders with alignX="${value}"`, () => {
|
|
275
|
-
const result = asVNode(Element({ alignX: value, children:
|
|
275
|
+
const result = asVNode(Element({ alignX: value, children: 'content' }))
|
|
276
276
|
expect(result.type).toBe(Wrapper)
|
|
277
277
|
})
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
for (const value of alignYValues) {
|
|
281
281
|
it(`renders with alignY="${value}"`, () => {
|
|
282
|
-
const result = asVNode(Element({ alignY: value, children:
|
|
282
|
+
const result = asVNode(Element({ alignY: value, children: 'content' }))
|
|
283
283
|
expect(result.type).toBe(Wrapper)
|
|
284
284
|
})
|
|
285
285
|
}
|
|
286
286
|
})
|
|
287
287
|
|
|
288
|
-
describe(
|
|
289
|
-
const directionValues = [
|
|
288
|
+
describe('direction values', () => {
|
|
289
|
+
const directionValues = ['inline', 'rows', 'reverseInline', 'reverseRows'] as const
|
|
290
290
|
|
|
291
291
|
for (const value of directionValues) {
|
|
292
292
|
it(`renders with direction="${value}"`, () => {
|
|
293
|
-
const result = asVNode(Element({ direction: value, children:
|
|
293
|
+
const result = asVNode(Element({ direction: value, children: 'content' }))
|
|
294
294
|
expect(result.type).toBe(Wrapper)
|
|
295
295
|
})
|
|
296
296
|
}
|