@pyreon/elements 0.11.4 → 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,33 +1,33 @@
|
|
|
1
|
-
import type { ComponentFn, VNode } from
|
|
2
|
-
import { h } from
|
|
3
|
-
import { describe, expect, it } from
|
|
4
|
-
import { Element } from
|
|
5
|
-
import Iterator from
|
|
6
|
-
import { List } from
|
|
1
|
+
import type { ComponentFn, VNode } from '@pyreon/core'
|
|
2
|
+
import { h } from '@pyreon/core'
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
|
+
import { Element } from '../Element'
|
|
5
|
+
import Iterator from '../helpers/Iterator'
|
|
6
|
+
import { List } from '../List'
|
|
7
7
|
|
|
8
8
|
const asVNode = (v: unknown) => v as VNode
|
|
9
9
|
|
|
10
|
-
describe(
|
|
11
|
-
describe(
|
|
12
|
-
it(
|
|
13
|
-
expect(List.displayName).toBe(
|
|
10
|
+
describe('List', () => {
|
|
11
|
+
describe('statics', () => {
|
|
12
|
+
it('has correct displayName', () => {
|
|
13
|
+
expect(List.displayName).toBe('@pyreon/elements/List')
|
|
14
14
|
})
|
|
15
15
|
|
|
16
|
-
it(
|
|
17
|
-
expect(List.pkgName).toBe(
|
|
16
|
+
it('has correct pkgName', () => {
|
|
17
|
+
expect(List.pkgName).toBe('@pyreon/elements')
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
-
it(
|
|
21
|
-
expect(List.PYREON__COMPONENT).toBe(
|
|
20
|
+
it('has correct PYREON__COMPONENT', () => {
|
|
21
|
+
expect(List.PYREON__COMPONENT).toBe('@pyreon/elements/List')
|
|
22
22
|
})
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
describe(
|
|
26
|
-
it(
|
|
27
|
-
const Comp: ComponentFn = (props: any) => h(
|
|
25
|
+
describe('rootElement = false (default)', () => {
|
|
26
|
+
it('returns a VNode whose type is Iterator', () => {
|
|
27
|
+
const Comp: ComponentFn = (props: any) => h('span', null, props.children)
|
|
28
28
|
const result = asVNode(
|
|
29
29
|
List({
|
|
30
|
-
data: [
|
|
30
|
+
data: ['a', 'b'],
|
|
31
31
|
component: Comp,
|
|
32
32
|
}),
|
|
33
33
|
)
|
|
@@ -35,12 +35,12 @@ describe("List", () => {
|
|
|
35
35
|
expect(result.type).toBe(Iterator)
|
|
36
36
|
})
|
|
37
37
|
|
|
38
|
-
it(
|
|
39
|
-
const Comp: ComponentFn = (props: any) => h(
|
|
40
|
-
const data = [
|
|
38
|
+
it('passes iterator-related props to the Iterator VNode', () => {
|
|
39
|
+
const Comp: ComponentFn = (props: any) => h('span', null, props.children)
|
|
40
|
+
const data = ['a', 'b', 'c']
|
|
41
41
|
const itemKeyFn = (_item: unknown, i: number) => i
|
|
42
42
|
const itemPropsFn = () => ({})
|
|
43
|
-
const WrapComp: ComponentFn = (props: any) => h(
|
|
43
|
+
const WrapComp: ComponentFn = (props: any) => h('div', null, ...props.children)
|
|
44
44
|
|
|
45
45
|
const result = asVNode(
|
|
46
46
|
List({
|
|
@@ -48,9 +48,9 @@ describe("List", () => {
|
|
|
48
48
|
component: Comp,
|
|
49
49
|
itemKey: itemKeyFn,
|
|
50
50
|
itemProps: itemPropsFn,
|
|
51
|
-
valueName:
|
|
51
|
+
valueName: 'label',
|
|
52
52
|
wrapComponent: WrapComp,
|
|
53
|
-
wrapProps: { className:
|
|
53
|
+
wrapProps: { className: 'wrap' },
|
|
54
54
|
}),
|
|
55
55
|
)
|
|
56
56
|
|
|
@@ -59,20 +59,20 @@ describe("List", () => {
|
|
|
59
59
|
expect(result.props.component).toBe(Comp)
|
|
60
60
|
expect(result.props.itemKey).toBe(itemKeyFn)
|
|
61
61
|
expect(result.props.itemProps).toBe(itemPropsFn)
|
|
62
|
-
expect(result.props.valueName).toBe(
|
|
62
|
+
expect(result.props.valueName).toBe('label')
|
|
63
63
|
expect(result.props.wrapComponent).toBe(WrapComp)
|
|
64
|
-
expect(result.props.wrapProps).toEqual({ className:
|
|
64
|
+
expect(result.props.wrapProps).toEqual({ className: 'wrap' })
|
|
65
65
|
})
|
|
66
66
|
|
|
67
|
-
it(
|
|
68
|
-
const Comp: ComponentFn = (props: any) => h(
|
|
67
|
+
it('does not pass non-iterator props to Iterator', () => {
|
|
68
|
+
const Comp: ComponentFn = (props: any) => h('span', null, props.children)
|
|
69
69
|
const result = asVNode(
|
|
70
70
|
List({
|
|
71
|
-
data: [
|
|
71
|
+
data: ['a'],
|
|
72
72
|
component: Comp,
|
|
73
73
|
block: true,
|
|
74
74
|
gap: 8,
|
|
75
|
-
direction:
|
|
75
|
+
direction: 'rows',
|
|
76
76
|
} as any),
|
|
77
77
|
)
|
|
78
78
|
|
|
@@ -82,8 +82,8 @@ describe("List", () => {
|
|
|
82
82
|
expect(result.props.direction).toBeUndefined()
|
|
83
83
|
})
|
|
84
84
|
|
|
85
|
-
it(
|
|
86
|
-
const child = h(
|
|
85
|
+
it('forwards children prop to Iterator', () => {
|
|
86
|
+
const child = h('span', null, 'hello')
|
|
87
87
|
const result = asVNode(List({ children: child }))
|
|
88
88
|
|
|
89
89
|
expect(result.type).toBe(Iterator)
|
|
@@ -91,12 +91,12 @@ describe("List", () => {
|
|
|
91
91
|
})
|
|
92
92
|
})
|
|
93
93
|
|
|
94
|
-
describe(
|
|
95
|
-
it(
|
|
96
|
-
const Comp: ComponentFn = (props: any) => h(
|
|
94
|
+
describe('rootElement = true', () => {
|
|
95
|
+
it('returns a VNode whose type is Element', () => {
|
|
96
|
+
const Comp: ComponentFn = (props: any) => h('span', null, props.children)
|
|
97
97
|
const result = asVNode(
|
|
98
98
|
List({
|
|
99
|
-
data: [
|
|
99
|
+
data: ['a'],
|
|
100
100
|
component: Comp,
|
|
101
101
|
rootElement: true,
|
|
102
102
|
}),
|
|
@@ -105,33 +105,33 @@ describe("List", () => {
|
|
|
105
105
|
expect(result.type).toBe(Element)
|
|
106
106
|
})
|
|
107
107
|
|
|
108
|
-
it(
|
|
109
|
-
const Comp: ComponentFn = (props: any) => h(
|
|
108
|
+
it('passes layout props to the Element VNode', () => {
|
|
109
|
+
const Comp: ComponentFn = (props: any) => h('span', null, props.children)
|
|
110
110
|
const result = asVNode(
|
|
111
111
|
List({
|
|
112
|
-
data: [
|
|
112
|
+
data: ['a'],
|
|
113
113
|
component: Comp,
|
|
114
114
|
rootElement: true,
|
|
115
115
|
block: true,
|
|
116
116
|
gap: 8,
|
|
117
|
-
direction:
|
|
117
|
+
direction: 'rows',
|
|
118
118
|
} as any),
|
|
119
119
|
)
|
|
120
120
|
|
|
121
121
|
expect(result.type).toBe(Element)
|
|
122
122
|
expect(result.props.block).toBe(true)
|
|
123
123
|
expect(result.props.gap).toBe(8)
|
|
124
|
-
expect(result.props.direction).toBe(
|
|
124
|
+
expect(result.props.direction).toBe('rows')
|
|
125
125
|
})
|
|
126
126
|
|
|
127
|
-
it(
|
|
128
|
-
const Comp: ComponentFn = (props: any) => h(
|
|
127
|
+
it('does not pass iterator-reserved props to Element', () => {
|
|
128
|
+
const Comp: ComponentFn = (props: any) => h('span', null, props.children)
|
|
129
129
|
const result = asVNode(
|
|
130
130
|
List({
|
|
131
|
-
data: [
|
|
131
|
+
data: ['x'],
|
|
132
132
|
component: Comp,
|
|
133
133
|
rootElement: true,
|
|
134
|
-
valueName:
|
|
134
|
+
valueName: 'label',
|
|
135
135
|
}),
|
|
136
136
|
)
|
|
137
137
|
|
|
@@ -142,9 +142,9 @@ describe("List", () => {
|
|
|
142
142
|
expect(result.props.valueName).toBeUndefined()
|
|
143
143
|
})
|
|
144
144
|
|
|
145
|
-
it(
|
|
146
|
-
const Comp: ComponentFn = (props: any) => h(
|
|
147
|
-
const data = [
|
|
145
|
+
it('nests an Iterator VNode as children of Element', () => {
|
|
146
|
+
const Comp: ComponentFn = (props: any) => h('span', null, props.children)
|
|
147
|
+
const data = ['a', 'b']
|
|
148
148
|
const result = asVNode(
|
|
149
149
|
List({
|
|
150
150
|
data,
|
|
@@ -163,14 +163,14 @@ describe("List", () => {
|
|
|
163
163
|
expect(iteratorNode.props.component).toBe(Comp)
|
|
164
164
|
})
|
|
165
165
|
|
|
166
|
-
it(
|
|
167
|
-
const Comp: ComponentFn = (props: any) => h(
|
|
166
|
+
it('forwards ref to Element', () => {
|
|
167
|
+
const Comp: ComponentFn = (props: any) => h('span', null, props.children)
|
|
168
168
|
const refFn = (_node: unknown) => {
|
|
169
169
|
/* noop */
|
|
170
170
|
}
|
|
171
171
|
const result = asVNode(
|
|
172
172
|
List({
|
|
173
|
-
data: [
|
|
173
|
+
data: ['a'],
|
|
174
174
|
component: Comp,
|
|
175
175
|
rootElement: true,
|
|
176
176
|
ref: refFn,
|
|
@@ -182,17 +182,17 @@ describe("List", () => {
|
|
|
182
182
|
})
|
|
183
183
|
})
|
|
184
184
|
|
|
185
|
-
describe(
|
|
186
|
-
it(
|
|
185
|
+
describe('Iterator.RESERVED_PROPS', () => {
|
|
186
|
+
it('contains the expected prop names', () => {
|
|
187
187
|
expect(Iterator.RESERVED_PROPS).toEqual([
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
188
|
+
'children',
|
|
189
|
+
'component',
|
|
190
|
+
'wrapComponent',
|
|
191
|
+
'data',
|
|
192
|
+
'itemKey',
|
|
193
|
+
'valueName',
|
|
194
|
+
'itemProps',
|
|
195
|
+
'wrapProps',
|
|
196
196
|
])
|
|
197
197
|
})
|
|
198
198
|
})
|