@pyreon/elements 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.
Files changed (53) hide show
  1. package/README.md +38 -35
  2. package/lib/index.d.ts +15 -15
  3. package/package.json +24 -24
  4. package/src/Element/component.tsx +14 -14
  5. package/src/Element/constants.ts +25 -25
  6. package/src/Element/index.ts +2 -2
  7. package/src/Element/types.ts +3 -3
  8. package/src/Element/utils.ts +1 -1
  9. package/src/List/component.tsx +7 -7
  10. package/src/List/index.ts +2 -2
  11. package/src/Overlay/component.tsx +22 -22
  12. package/src/Overlay/context.tsx +2 -2
  13. package/src/Overlay/index.ts +3 -3
  14. package/src/Overlay/useOverlay.tsx +97 -97
  15. package/src/Portal/component.tsx +6 -6
  16. package/src/Portal/index.ts +2 -2
  17. package/src/Text/component.tsx +6 -6
  18. package/src/Text/index.ts +2 -2
  19. package/src/Text/styled.ts +4 -4
  20. package/src/Util/component.tsx +5 -5
  21. package/src/Util/index.ts +2 -2
  22. package/src/__tests__/Content.test.tsx +46 -46
  23. package/src/__tests__/Element.test.ts +251 -251
  24. package/src/__tests__/Iterator.test.ts +142 -142
  25. package/src/__tests__/List.test.ts +61 -61
  26. package/src/__tests__/Overlay.test.ts +125 -125
  27. package/src/__tests__/Portal.test.ts +33 -33
  28. package/src/__tests__/Text.test.ts +128 -128
  29. package/src/__tests__/Util.test.ts +31 -31
  30. package/src/__tests__/Wrapper.test.tsx +60 -60
  31. package/src/__tests__/equalBeforeAfter.test.ts +41 -41
  32. package/src/__tests__/helpers.test.ts +29 -29
  33. package/src/__tests__/overlayContext.test.tsx +14 -14
  34. package/src/__tests__/responsiveProps.test.ts +116 -116
  35. package/src/__tests__/useOverlay.test.ts +283 -283
  36. package/src/__tests__/utils.test.ts +43 -43
  37. package/src/constants.ts +1 -1
  38. package/src/helpers/Content/component.tsx +5 -5
  39. package/src/helpers/Content/index.ts +1 -1
  40. package/src/helpers/Content/styled.ts +16 -16
  41. package/src/helpers/Content/types.ts +7 -7
  42. package/src/helpers/Iterator/component.tsx +28 -28
  43. package/src/helpers/Iterator/index.ts +2 -2
  44. package/src/helpers/Iterator/types.ts +3 -3
  45. package/src/helpers/Wrapper/component.tsx +6 -6
  46. package/src/helpers/Wrapper/index.ts +1 -1
  47. package/src/helpers/Wrapper/styled.ts +8 -8
  48. package/src/helpers/Wrapper/types.ts +3 -3
  49. package/src/helpers/Wrapper/utils.ts +1 -1
  50. package/src/helpers/index.ts +2 -2
  51. package/src/index.ts +16 -16
  52. package/src/types.ts +7 -7
  53. package/src/utils.ts +1 -1
@@ -1,9 +1,9 @@
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"
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 === "object" && "type" in (c as VNode) && (c as VNode).type === Content,
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("Element responsive props", () => {
20
- describe("single values", () => {
21
- it("renders with alignX as string", () => {
22
- const result = asVNode(Element({ alignX: "center", children: "content" }))
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("renders with alignY as string", () => {
27
- const result = asVNode(Element({ alignY: "top", children: "content" }))
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("renders with direction as string", () => {
32
- const result = asVNode(Element({ direction: "rows", children: "content" }))
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("renders with gap as number", () => {
36
+ it('renders with gap as number', () => {
37
37
  const result = asVNode(
38
38
  Element({
39
39
  gap: 16,
40
- beforeContent: h("span", null, "Before"),
41
- afterContent: h("span", null, "After"),
42
- children: "content",
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("renders with block as boolean", () => {
49
- const result = asVNode(Element({ block: true, children: "content" }))
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("renders with equalCols as boolean", () => {
54
+ it('renders with equalCols as boolean', () => {
55
55
  const result = asVNode(
56
56
  Element({
57
57
  equalCols: true,
58
- beforeContent: h("span", null, "Before"),
59
- afterContent: h("span", null, "After"),
60
- children: "content",
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("array values (positional breakpoints)", () => {
68
- it("renders with alignX as array", () => {
67
+ describe('array values (positional breakpoints)', () => {
68
+ it('renders with alignX as array', () => {
69
69
  const result = asVNode(
70
- Element({ alignX: ["left", "center", "right"] as any, children: "content" }),
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("renders with alignY as array", () => {
75
+ it('renders with alignY as array', () => {
76
76
  const result = asVNode(
77
- Element({ alignY: ["top", "center", "bottom"] as any, children: "content" }),
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("renders with direction as array", () => {
83
- const result = asVNode(Element({ direction: ["rows", "inline"] as any, children: "content" }))
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("renders with gap as array", () => {
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("span", null, "Before"),
92
- children: "content",
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("renders with block as array", () => {
99
- const result = asVNode(Element({ block: [false, true] as any, children: "content" }))
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("renders with equalCols as array", () => {
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("span", null, "Before"),
108
- afterContent: h("span", null, "After"),
109
- children: "content",
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("breakpoint object values", () => {
117
- it("renders with alignX as breakpoint object", () => {
116
+ describe('breakpoint object values', () => {
117
+ it('renders with alignX as breakpoint object', () => {
118
118
  const result = asVNode(
119
119
  Element({
120
- alignX: { xs: "left", md: "center", xl: "right" } as any,
121
- children: "content",
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("renders with alignY as breakpoint object", () => {
127
+ it('renders with alignY as breakpoint object', () => {
128
128
  const result = asVNode(
129
- Element({ alignY: { xs: "top", lg: "center" } as any, children: "content" }),
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("renders with direction as breakpoint object", () => {
134
+ it('renders with direction as breakpoint object', () => {
135
135
  const result = asVNode(
136
136
  Element({
137
- direction: { xs: "rows", md: "inline" } as any,
138
- children: "content",
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("renders with gap as breakpoint object", () => {
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("span", null, "Before"),
149
- children: "content",
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("renders with block as breakpoint object", () => {
155
+ it('renders with block as breakpoint object', () => {
156
156
  const result = asVNode(
157
- Element({ block: { xs: false, md: true } as any, children: "content" }),
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("combined responsive props", () => {
164
- it("renders with multiple responsive props simultaneously", () => {
163
+ describe('combined responsive props', () => {
164
+ it('renders with multiple responsive props simultaneously', () => {
165
165
  const result = asVNode(
166
166
  Element({
167
- alignX: { xs: "left", md: "center" } as any,
168
- alignY: ["top", "center"] as any,
169
- direction: { xs: "rows", lg: "inline" } as any,
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("span", { "data-testid": "before" }, "Before"),
173
- afterContent: h("span", { "data-testid": "after" }, "After"),
174
- children: h("span", { "data-testid": "main" }, "Main"),
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("renders with responsive content directions", () => {
182
+ it('renders with responsive content directions', () => {
183
183
  const result = asVNode(
184
184
  Element({
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"),
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("renders with responsive content alignment", () => {
198
+ it('renders with responsive content alignment', () => {
199
199
  const result = asVNode(
200
200
  Element({
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",
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("responsive css prop", () => {
215
- it("renders with css as string", () => {
216
- const result = asVNode(Element({ css: "background: red;", children: "content" }))
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("background: red;")
218
+ expect(result.props.extendCss).toBe('background: red;')
219
219
  })
220
220
 
221
- it("renders with contentCss", () => {
221
+ it('renders with contentCss', () => {
222
222
  const result = asVNode(
223
223
  Element({
224
- contentCss: "color: blue;",
225
- beforeContent: h("span", null, "Before"),
226
- children: "content",
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 === "content")
232
- expect(contentSlot?.props.extendCss).toBe("color: blue;")
231
+ const contentSlot = slots.find((v) => v.props.contentType === 'content')
232
+ expect(contentSlot?.props.extendCss).toBe('color: blue;')
233
233
  })
234
234
 
235
- it("renders with beforeContentCss and afterContentCss", () => {
235
+ it('renders with beforeContentCss and afterContentCss', () => {
236
236
  const result = asVNode(
237
237
  Element({
238
- beforeContentCss: "padding: 4px;",
239
- afterContentCss: "padding: 8px;",
240
- beforeContent: h("span", null, "Before"),
241
- afterContent: h("span", null, "After"),
242
- children: "content",
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 === "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;")
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("alignment values", () => {
254
+ describe('alignment values', () => {
255
255
  const alignXValues = [
256
- "left",
257
- "center",
258
- "right",
259
- "spaceBetween",
260
- "spaceAround",
261
- "block",
256
+ 'left',
257
+ 'center',
258
+ 'right',
259
+ 'spaceBetween',
260
+ 'spaceAround',
261
+ 'block',
262
262
  ] as const
263
263
 
264
264
  const alignYValues = [
265
- "top",
266
- "center",
267
- "bottom",
268
- "spaceBetween",
269
- "spaceAround",
270
- "block",
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: "content" }))
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: "content" }))
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("direction values", () => {
289
- const directionValues = ["inline", "rows", "reverseInline", "reverseRows"] as const
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: "content" }))
293
+ const result = asVNode(Element({ direction: value, children: 'content' }))
294
294
  expect(result.type).toBe(Wrapper)
295
295
  })
296
296
  }