@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
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
* is coordinated through the overlay context.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { signal } from
|
|
11
|
-
import { throttle } from
|
|
12
|
-
import { value } from
|
|
13
|
-
import { IS_DEVELOPMENT } from
|
|
14
|
-
import Provider, { useOverlayContext } from
|
|
10
|
+
import { signal } from '@pyreon/reactivity'
|
|
11
|
+
import { throttle } from '@pyreon/ui-core'
|
|
12
|
+
import { value } from '@pyreon/unistyle'
|
|
13
|
+
import { IS_DEVELOPMENT } from '../utils'
|
|
14
|
+
import Provider, { useOverlayContext } from './context'
|
|
15
15
|
|
|
16
16
|
type OverlayPosition = Partial<{
|
|
17
17
|
top: number | string
|
|
@@ -20,16 +20,16 @@ type OverlayPosition = Partial<{
|
|
|
20
20
|
right: number | string
|
|
21
21
|
}>
|
|
22
22
|
|
|
23
|
-
type Align =
|
|
24
|
-
type AlignX =
|
|
25
|
-
type AlignY =
|
|
23
|
+
type Align = 'bottom' | 'top' | 'left' | 'right'
|
|
24
|
+
type AlignX = 'left' | 'center' | 'right'
|
|
25
|
+
type AlignY = 'bottom' | 'top' | 'center'
|
|
26
26
|
|
|
27
27
|
export type UseOverlayProps = Partial<{
|
|
28
28
|
isOpen: boolean
|
|
29
|
-
openOn:
|
|
30
|
-
closeOn:
|
|
31
|
-
type:
|
|
32
|
-
position:
|
|
29
|
+
openOn: 'click' | 'hover' | 'manual'
|
|
30
|
+
closeOn: 'click' | 'clickOnTrigger' | 'clickOutsideContent' | 'hover' | 'manual'
|
|
31
|
+
type: 'dropdown' | 'tooltip' | 'popover' | 'modal' | 'custom'
|
|
32
|
+
position: 'absolute' | 'fixed' | 'relative' | 'static'
|
|
33
33
|
align: Align
|
|
34
34
|
alignX: AlignX
|
|
35
35
|
alignY: AlignY
|
|
@@ -64,7 +64,7 @@ const devWarn = (msg: string) => {
|
|
|
64
64
|
const calcDropdownVertical = (
|
|
65
65
|
c: DOMRect,
|
|
66
66
|
t: DOMRect,
|
|
67
|
-
align:
|
|
67
|
+
align: 'top' | 'bottom',
|
|
68
68
|
alignX: AlignX,
|
|
69
69
|
offsetX: number,
|
|
70
70
|
offsetY: number,
|
|
@@ -81,30 +81,30 @@ const calcDropdownVertical = (
|
|
|
81
81
|
const fitsLeft = leftPos + c.width <= window.innerWidth
|
|
82
82
|
const fitsRight = rightPos >= 0
|
|
83
83
|
|
|
84
|
-
const useTop = sel(align ===
|
|
84
|
+
const useTop = sel(align === 'top', fitsTop, !fitsBottom)
|
|
85
85
|
pos.top = sel(useTop, topPos, bottomPos)
|
|
86
|
-
const resolvedAlignY: AlignY = sel(useTop,
|
|
86
|
+
const resolvedAlignY: AlignY = sel(useTop, 'top', 'bottom')
|
|
87
87
|
|
|
88
88
|
let resolvedAlignX: AlignX = alignX
|
|
89
|
-
if (alignX ===
|
|
89
|
+
if (alignX === 'left') {
|
|
90
90
|
pos.left = sel(fitsLeft, leftPos, rightPos)
|
|
91
|
-
resolvedAlignX = sel(fitsLeft,
|
|
92
|
-
} else if (alignX ===
|
|
91
|
+
resolvedAlignX = sel(fitsLeft, 'left', 'right')
|
|
92
|
+
} else if (alignX === 'right') {
|
|
93
93
|
pos.left = sel(fitsRight, rightPos, leftPos)
|
|
94
|
-
resolvedAlignX = sel(fitsRight,
|
|
94
|
+
resolvedAlignX = sel(fitsRight, 'right', 'left')
|
|
95
95
|
} else {
|
|
96
96
|
const center = t.left + (t.right - t.left) / 2 - c.width / 2
|
|
97
97
|
const fitsCL = center >= 0
|
|
98
98
|
const fitsCR = center + c.width <= window.innerWidth
|
|
99
99
|
|
|
100
100
|
if (fitsCL && fitsCR) {
|
|
101
|
-
resolvedAlignX =
|
|
101
|
+
resolvedAlignX = 'center'
|
|
102
102
|
pos.left = center
|
|
103
103
|
} else if (fitsCL) {
|
|
104
|
-
resolvedAlignX =
|
|
104
|
+
resolvedAlignX = 'left'
|
|
105
105
|
pos.left = leftPos
|
|
106
106
|
} else if (fitsCR) {
|
|
107
|
-
resolvedAlignX =
|
|
107
|
+
resolvedAlignX = 'right'
|
|
108
108
|
pos.left = rightPos
|
|
109
109
|
}
|
|
110
110
|
}
|
|
@@ -115,7 +115,7 @@ const calcDropdownVertical = (
|
|
|
115
115
|
const calcDropdownHorizontal = (
|
|
116
116
|
c: DOMRect,
|
|
117
117
|
t: DOMRect,
|
|
118
|
-
align:
|
|
118
|
+
align: 'left' | 'right',
|
|
119
119
|
alignY: AlignY,
|
|
120
120
|
offsetX: number,
|
|
121
121
|
offsetY: number,
|
|
@@ -132,30 +132,30 @@ const calcDropdownHorizontal = (
|
|
|
132
132
|
const fitsTop = topPos + c.height <= window.innerHeight
|
|
133
133
|
const fitsBottom = bottomPos >= 0
|
|
134
134
|
|
|
135
|
-
const useLeft = sel(align ===
|
|
135
|
+
const useLeft = sel(align === 'left', fitsLeft, !fitsRight)
|
|
136
136
|
pos.left = sel(useLeft, leftPos, rightPos)
|
|
137
|
-
const resolvedAlignX: AlignX = sel(useLeft,
|
|
137
|
+
const resolvedAlignX: AlignX = sel(useLeft, 'left', 'right')
|
|
138
138
|
|
|
139
139
|
let resolvedAlignY: AlignY = alignY
|
|
140
|
-
if (alignY ===
|
|
140
|
+
if (alignY === 'top') {
|
|
141
141
|
pos.top = sel(fitsTop, topPos, bottomPos)
|
|
142
|
-
resolvedAlignY = sel(fitsTop,
|
|
143
|
-
} else if (alignY ===
|
|
142
|
+
resolvedAlignY = sel(fitsTop, 'top', 'bottom')
|
|
143
|
+
} else if (alignY === 'bottom') {
|
|
144
144
|
pos.top = sel(fitsBottom, bottomPos, topPos)
|
|
145
|
-
resolvedAlignY = sel(fitsBottom,
|
|
145
|
+
resolvedAlignY = sel(fitsBottom, 'bottom', 'top')
|
|
146
146
|
} else {
|
|
147
147
|
const center = t.top + (t.bottom - t.top) / 2 - c.height / 2
|
|
148
148
|
const fitsCT = center >= 0
|
|
149
149
|
const fitsCB = center + c.height <= window.innerHeight
|
|
150
150
|
|
|
151
151
|
if (fitsCT && fitsCB) {
|
|
152
|
-
resolvedAlignY =
|
|
152
|
+
resolvedAlignY = 'center'
|
|
153
153
|
pos.top = center
|
|
154
154
|
} else if (fitsCT) {
|
|
155
|
-
resolvedAlignY =
|
|
155
|
+
resolvedAlignY = 'top'
|
|
156
156
|
pos.top = topPos
|
|
157
157
|
} else if (fitsCB) {
|
|
158
|
-
resolvedAlignY =
|
|
158
|
+
resolvedAlignY = 'bottom'
|
|
159
159
|
pos.top = bottomPos
|
|
160
160
|
}
|
|
161
161
|
}
|
|
@@ -173,13 +173,13 @@ const calcModalPos = (
|
|
|
173
173
|
const pos: OverlayPosition = {}
|
|
174
174
|
|
|
175
175
|
switch (alignX) {
|
|
176
|
-
case
|
|
176
|
+
case 'right':
|
|
177
177
|
pos.right = offsetX
|
|
178
178
|
break
|
|
179
|
-
case
|
|
179
|
+
case 'left':
|
|
180
180
|
pos.left = offsetX
|
|
181
181
|
break
|
|
182
|
-
case
|
|
182
|
+
case 'center':
|
|
183
183
|
pos.left = window.innerWidth / 2 - c.width / 2
|
|
184
184
|
break
|
|
185
185
|
default:
|
|
@@ -187,13 +187,13 @@ const calcModalPos = (
|
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
switch (alignY) {
|
|
190
|
-
case
|
|
190
|
+
case 'top':
|
|
191
191
|
pos.top = offsetY
|
|
192
192
|
break
|
|
193
|
-
case
|
|
193
|
+
case 'center':
|
|
194
194
|
pos.top = window.innerHeight / 2 - c.height / 2
|
|
195
195
|
break
|
|
196
|
-
case
|
|
196
|
+
case 'bottom':
|
|
197
197
|
pos.bottom = offsetY
|
|
198
198
|
break
|
|
199
199
|
default:
|
|
@@ -210,10 +210,10 @@ const adjustForAncestor = (
|
|
|
210
210
|
if (ancestor.top === 0 && ancestor.left === 0) return pos
|
|
211
211
|
|
|
212
212
|
const result = { ...pos }
|
|
213
|
-
if (typeof result.top ===
|
|
214
|
-
if (typeof result.bottom ===
|
|
215
|
-
if (typeof result.left ===
|
|
216
|
-
if (typeof result.right ===
|
|
213
|
+
if (typeof result.top === 'number') result.top -= ancestor.top
|
|
214
|
+
if (typeof result.bottom === 'number') result.bottom += ancestor.top
|
|
215
|
+
if (typeof result.left === 'number') result.left -= ancestor.left
|
|
216
|
+
if (typeof result.right === 'number') result.right += ancestor.left
|
|
217
217
|
|
|
218
218
|
return result
|
|
219
219
|
}
|
|
@@ -235,13 +235,13 @@ const computePosition = (
|
|
|
235
235
|
contentEl: HTMLElement | null,
|
|
236
236
|
ancestorOffset: { top: number; left: number },
|
|
237
237
|
): ComputeResult => {
|
|
238
|
-
const isDropdown = [
|
|
238
|
+
const isDropdown = ['dropdown', 'tooltip', 'popover'].includes(type)
|
|
239
239
|
|
|
240
240
|
if (isDropdown && (!triggerEl || !contentEl)) {
|
|
241
241
|
devWarn(
|
|
242
242
|
`[@pyreon/elements] Overlay (${type}): ` +
|
|
243
|
-
`${triggerEl ?
|
|
244
|
-
|
|
243
|
+
`${triggerEl ? 'contentRef' : 'triggerRef'} is not attached. ` +
|
|
244
|
+
'Position cannot be calculated without both refs.',
|
|
245
245
|
)
|
|
246
246
|
return { pos: {} }
|
|
247
247
|
}
|
|
@@ -250,9 +250,9 @@ const computePosition = (
|
|
|
250
250
|
const c = contentEl.getBoundingClientRect()
|
|
251
251
|
const t = triggerEl.getBoundingClientRect()
|
|
252
252
|
const result =
|
|
253
|
-
align ===
|
|
253
|
+
align === 'top' || align === 'bottom'
|
|
254
254
|
? calcDropdownVertical(c, t, align, alignX, offsetX, offsetY)
|
|
255
|
-
: calcDropdownHorizontal(c, t, align as
|
|
255
|
+
: calcDropdownHorizontal(c, t, align as 'left' | 'right', alignY, offsetX, offsetY)
|
|
256
256
|
|
|
257
257
|
return {
|
|
258
258
|
pos: adjustForAncestor(result.pos, ancestorOffset),
|
|
@@ -261,11 +261,11 @@ const computePosition = (
|
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
-
if (type ===
|
|
264
|
+
if (type === 'modal') {
|
|
265
265
|
if (!contentEl) {
|
|
266
266
|
devWarn(
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
'[@pyreon/elements] Overlay (modal): contentRef is not attached. ' +
|
|
268
|
+
'Modal position cannot be calculated without a content element.',
|
|
269
269
|
)
|
|
270
270
|
return { pos: {} }
|
|
271
271
|
}
|
|
@@ -288,38 +288,38 @@ const processVisibilityEvent = (
|
|
|
288
288
|
showContent: () => void,
|
|
289
289
|
hideContent: () => void,
|
|
290
290
|
) => {
|
|
291
|
-
if (!active && openOn ===
|
|
291
|
+
if (!active && openOn === 'click' && e.type === 'click' && isTrigger(e)) {
|
|
292
292
|
showContent()
|
|
293
293
|
return
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
if (!active) return
|
|
297
297
|
|
|
298
|
-
if (closeOn ===
|
|
298
|
+
if (closeOn === 'hover' && e.type === 'scroll') {
|
|
299
299
|
hideContent()
|
|
300
300
|
return
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
-
if (e.type !==
|
|
303
|
+
if (e.type !== 'click') return
|
|
304
304
|
|
|
305
|
-
if (closeOn ===
|
|
305
|
+
if (closeOn === 'click') {
|
|
306
306
|
hideContent()
|
|
307
|
-
} else if (closeOn ===
|
|
307
|
+
} else if (closeOn === 'clickOnTrigger' && isTrigger(e)) {
|
|
308
308
|
hideContent()
|
|
309
|
-
} else if (closeOn ===
|
|
309
|
+
} else if (closeOn === 'clickOutsideContent' && !isContent(e)) {
|
|
310
310
|
hideContent()
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
const useOverlay = ({
|
|
315
315
|
isOpen = false,
|
|
316
|
-
openOn =
|
|
317
|
-
closeOn =
|
|
318
|
-
type =
|
|
319
|
-
position =
|
|
320
|
-
align =
|
|
321
|
-
alignX: propAlignX =
|
|
322
|
-
alignY: propAlignY =
|
|
316
|
+
openOn = 'click',
|
|
317
|
+
closeOn = 'click',
|
|
318
|
+
type = 'dropdown',
|
|
319
|
+
position = 'fixed',
|
|
320
|
+
align = 'bottom',
|
|
321
|
+
alignX: propAlignX = 'left',
|
|
322
|
+
alignY: propAlignY = 'bottom',
|
|
323
323
|
offsetX = 0,
|
|
324
324
|
offsetY = 0,
|
|
325
325
|
throttleDelay = 200,
|
|
@@ -374,7 +374,7 @@ const useOverlay = ({
|
|
|
374
374
|
|
|
375
375
|
// Position calculation helpers
|
|
376
376
|
const getAncestorOffset = () => {
|
|
377
|
-
if (position !==
|
|
377
|
+
if (position !== 'absolute' || !contentEl) {
|
|
378
378
|
return { top: 0, left: 0 }
|
|
379
379
|
}
|
|
380
380
|
|
|
@@ -416,10 +416,10 @@ const useOverlay = ({
|
|
|
416
416
|
|
|
417
417
|
el.style.position = position
|
|
418
418
|
|
|
419
|
-
el.style.top = values.top != null ? setValue(values.top) :
|
|
420
|
-
el.style.bottom = values.bottom != null ? setValue(values.bottom) :
|
|
421
|
-
el.style.left = values.left != null ? setValue(values.left) :
|
|
422
|
-
el.style.right = values.right != null ? setValue(values.right) :
|
|
419
|
+
el.style.top = values.top != null ? setValue(values.top) : ''
|
|
420
|
+
el.style.bottom = values.bottom != null ? setValue(values.bottom) : ''
|
|
421
|
+
el.style.left = values.left != null ? setValue(values.left) : ''
|
|
422
|
+
el.style.right = values.right != null ? setValue(values.right) : ''
|
|
423
423
|
}
|
|
424
424
|
|
|
425
425
|
const setContentPosition = () => {
|
|
@@ -464,26 +464,26 @@ const useOverlay = ({
|
|
|
464
464
|
|
|
465
465
|
// Click-based open/close
|
|
466
466
|
const enabledClick =
|
|
467
|
-
openOn ===
|
|
467
|
+
openOn === 'click' || ['click', 'clickOnTrigger', 'clickOutsideContent'].includes(closeOn)
|
|
468
468
|
|
|
469
469
|
if (enabledClick) {
|
|
470
|
-
window.addEventListener(
|
|
471
|
-
cleanups.push(() => window.removeEventListener(
|
|
470
|
+
window.addEventListener('click', handleClick)
|
|
471
|
+
cleanups.push(() => window.removeEventListener('click', handleClick))
|
|
472
472
|
}
|
|
473
473
|
|
|
474
474
|
// ESC key
|
|
475
475
|
if (closeOnEsc) {
|
|
476
476
|
const handleEscKey = (e: KeyboardEvent) => {
|
|
477
|
-
if (e.key ===
|
|
477
|
+
if (e.key === 'Escape' && active() && !blocked()) {
|
|
478
478
|
hideContent()
|
|
479
479
|
}
|
|
480
480
|
}
|
|
481
|
-
window.addEventListener(
|
|
482
|
-
cleanups.push(() => window.removeEventListener(
|
|
481
|
+
window.addEventListener('keydown', handleEscKey)
|
|
482
|
+
cleanups.push(() => window.removeEventListener('keydown', handleEscKey))
|
|
483
483
|
}
|
|
484
484
|
|
|
485
485
|
// Hover-based open/close
|
|
486
|
-
const enabledHover = openOn ===
|
|
486
|
+
const enabledHover = openOn === 'hover' || closeOn === 'hover'
|
|
487
487
|
if (enabledHover) {
|
|
488
488
|
const clearHoverTimeout = () => {
|
|
489
489
|
if (hoverTimeout != null) {
|
|
@@ -499,11 +499,11 @@ const useOverlay = ({
|
|
|
499
499
|
|
|
500
500
|
const onTriggerEnter = () => {
|
|
501
501
|
clearHoverTimeout()
|
|
502
|
-
if (openOn ===
|
|
502
|
+
if (openOn === 'hover' && !active()) showContent()
|
|
503
503
|
}
|
|
504
504
|
|
|
505
505
|
const onTriggerLeave = () => {
|
|
506
|
-
if (closeOn ===
|
|
506
|
+
if (closeOn === 'hover' && active()) scheduleHide()
|
|
507
507
|
}
|
|
508
508
|
|
|
509
509
|
const onContentEnter = () => {
|
|
@@ -511,18 +511,18 @@ const useOverlay = ({
|
|
|
511
511
|
}
|
|
512
512
|
|
|
513
513
|
const onContentLeave = () => {
|
|
514
|
-
if (closeOn ===
|
|
514
|
+
if (closeOn === 'hover' && active()) scheduleHide()
|
|
515
515
|
}
|
|
516
516
|
|
|
517
517
|
// We need to defer listener attachment until refs are available
|
|
518
518
|
const attachHoverListeners = () => {
|
|
519
519
|
if (triggerEl) {
|
|
520
|
-
triggerEl.addEventListener(
|
|
521
|
-
triggerEl.addEventListener(
|
|
520
|
+
triggerEl.addEventListener('mouseenter', onTriggerEnter)
|
|
521
|
+
triggerEl.addEventListener('mouseleave', onTriggerLeave)
|
|
522
522
|
}
|
|
523
523
|
if (contentEl) {
|
|
524
|
-
contentEl.addEventListener(
|
|
525
|
-
contentEl.addEventListener(
|
|
524
|
+
contentEl.addEventListener('mouseenter', onContentEnter)
|
|
525
|
+
contentEl.addEventListener('mouseleave', onContentLeave)
|
|
526
526
|
}
|
|
527
527
|
}
|
|
528
528
|
|
|
@@ -531,18 +531,18 @@ const useOverlay = ({
|
|
|
531
531
|
cleanups.push(() => {
|
|
532
532
|
clearHoverTimeout()
|
|
533
533
|
if (triggerEl) {
|
|
534
|
-
triggerEl.removeEventListener(
|
|
535
|
-
triggerEl.removeEventListener(
|
|
534
|
+
triggerEl.removeEventListener('mouseenter', onTriggerEnter)
|
|
535
|
+
triggerEl.removeEventListener('mouseleave', onTriggerLeave)
|
|
536
536
|
}
|
|
537
537
|
if (contentEl) {
|
|
538
|
-
contentEl.removeEventListener(
|
|
539
|
-
contentEl.removeEventListener(
|
|
538
|
+
contentEl.removeEventListener('mouseenter', onContentEnter)
|
|
539
|
+
contentEl.removeEventListener('mouseleave', onContentLeave)
|
|
540
540
|
}
|
|
541
541
|
})
|
|
542
542
|
}
|
|
543
543
|
|
|
544
544
|
// Resize/scroll repositioning
|
|
545
|
-
const shouldSetOverflow = type ===
|
|
545
|
+
const shouldSetOverflow = type === 'modal'
|
|
546
546
|
|
|
547
547
|
const onScroll = (e: Event) => {
|
|
548
548
|
handleContentPosition()
|
|
@@ -551,37 +551,37 @@ const useOverlay = ({
|
|
|
551
551
|
|
|
552
552
|
if (shouldSetOverflow) {
|
|
553
553
|
modalOverflowCount++
|
|
554
|
-
if (modalOverflowCount === 1) document.body.style.overflow =
|
|
554
|
+
if (modalOverflowCount === 1) document.body.style.overflow = 'hidden'
|
|
555
555
|
}
|
|
556
556
|
|
|
557
|
-
window.addEventListener(
|
|
558
|
-
window.addEventListener(
|
|
557
|
+
window.addEventListener('resize', handleContentPosition)
|
|
558
|
+
window.addEventListener('scroll', onScroll, { passive: true })
|
|
559
559
|
cleanups.push(() => {
|
|
560
560
|
handleContentPosition.cancel()
|
|
561
561
|
handleVisibility.cancel()
|
|
562
562
|
if (shouldSetOverflow) {
|
|
563
563
|
modalOverflowCount--
|
|
564
|
-
if (modalOverflowCount === 0) document.body.style.overflow =
|
|
564
|
+
if (modalOverflowCount === 0) document.body.style.overflow = ''
|
|
565
565
|
}
|
|
566
|
-
window.removeEventListener(
|
|
567
|
-
window.removeEventListener(
|
|
566
|
+
window.removeEventListener('resize', handleContentPosition)
|
|
567
|
+
window.removeEventListener('scroll', onScroll)
|
|
568
568
|
})
|
|
569
569
|
|
|
570
570
|
// Parent container scroll
|
|
571
571
|
if (parentContainer) {
|
|
572
|
-
if (closeOn !==
|
|
572
|
+
if (closeOn !== 'hover') parentContainer.style.overflow = 'hidden'
|
|
573
573
|
|
|
574
574
|
const onParentScroll = (e: Event) => {
|
|
575
575
|
handleContentPosition()
|
|
576
576
|
handleVisibility(e)
|
|
577
577
|
}
|
|
578
578
|
|
|
579
|
-
parentContainer.addEventListener(
|
|
579
|
+
parentContainer.addEventListener('scroll', onParentScroll, {
|
|
580
580
|
passive: true,
|
|
581
581
|
})
|
|
582
582
|
cleanups.push(() => {
|
|
583
|
-
parentContainer.style.overflow =
|
|
584
|
-
parentContainer.removeEventListener(
|
|
583
|
+
parentContainer.style.overflow = ''
|
|
584
|
+
parentContainer.removeEventListener('scroll', onParentScroll)
|
|
585
585
|
})
|
|
586
586
|
}
|
|
587
587
|
|
package/src/Portal/component.tsx
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* compatibility with the elements package structure.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type { VNodeChild } from
|
|
8
|
-
import { Portal as CorePortal } from
|
|
9
|
-
import { PKG_NAME } from
|
|
10
|
-
import type { PyreonComponent } from
|
|
7
|
+
import type { VNodeChild } from '@pyreon/core'
|
|
8
|
+
import { Portal as CorePortal } from '@pyreon/core'
|
|
9
|
+
import { PKG_NAME } from '../constants'
|
|
10
|
+
import type { PyreonComponent } from '../types'
|
|
11
11
|
|
|
12
12
|
export interface Props {
|
|
13
13
|
/**
|
|
@@ -24,8 +24,8 @@ export interface Props {
|
|
|
24
24
|
tag?: string
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
const Component: PyreonComponent<Props> = ({ DOMLocation, tag: _tag =
|
|
28
|
-
const target = DOMLocation ?? (typeof document !==
|
|
27
|
+
const Component: PyreonComponent<Props> = ({ DOMLocation, tag: _tag = 'div', children }) => {
|
|
28
|
+
const target = DOMLocation ?? (typeof document !== 'undefined' ? document.body : undefined)
|
|
29
29
|
|
|
30
30
|
if (!target) return null
|
|
31
31
|
|
package/src/Portal/index.ts
CHANGED
package/src/Text/component.tsx
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* a static `isText` flag so other components can detect text children.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { PyreonHTMLAttributes, VNodeChild } from
|
|
9
|
-
import type { HTMLTextTags } from
|
|
10
|
-
import { PKG_NAME } from
|
|
11
|
-
import type { ExtendCss, PyreonComponent } from
|
|
12
|
-
import Styled from
|
|
8
|
+
import type { PyreonHTMLAttributes, VNodeChild } from '@pyreon/core'
|
|
9
|
+
import type { HTMLTextTags } from '@pyreon/ui-core'
|
|
10
|
+
import { PKG_NAME } from '../constants'
|
|
11
|
+
import type { ExtendCss, PyreonComponent } from '../types'
|
|
12
|
+
import Styled from './styled'
|
|
13
13
|
|
|
14
14
|
export type Props = Partial<{
|
|
15
15
|
/**
|
|
@@ -40,7 +40,7 @@ const Component: PyreonComponent<Props> & {
|
|
|
40
40
|
} = ({ paragraph, label, children, tag, css, ref, ...props }) => {
|
|
41
41
|
let finalTag: string | undefined
|
|
42
42
|
|
|
43
|
-
if (paragraph) finalTag =
|
|
43
|
+
if (paragraph) finalTag = 'p'
|
|
44
44
|
else {
|
|
45
45
|
finalTag = tag
|
|
46
46
|
}
|
package/src/Text/index.ts
CHANGED
package/src/Text/styled.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* styles can be injected via the responsive `extraStyles` prop processed
|
|
5
5
|
* through makeItResponsive.
|
|
6
6
|
*/
|
|
7
|
-
import { config } from
|
|
8
|
-
import { extendCss, makeItResponsive } from
|
|
9
|
-
import type { ResponsiveStylesCallback } from
|
|
7
|
+
import { config } from '@pyreon/ui-core'
|
|
8
|
+
import { extendCss, makeItResponsive } from '@pyreon/unistyle'
|
|
9
|
+
import type { ResponsiveStylesCallback } from '../types'
|
|
10
10
|
|
|
11
11
|
const { styled, css, textComponent } = config
|
|
12
12
|
|
|
@@ -22,7 +22,7 @@ export default styled(textComponent)`
|
|
|
22
22
|
`};
|
|
23
23
|
|
|
24
24
|
${makeItResponsive({
|
|
25
|
-
key:
|
|
25
|
+
key: '$text',
|
|
26
26
|
styles,
|
|
27
27
|
css,
|
|
28
28
|
normalize: false,
|
package/src/Util/component.tsx
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* helper to clone children with the merged props.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type { VNode, VNodeChild } from
|
|
8
|
-
import { render } from
|
|
9
|
-
import { PKG_NAME } from
|
|
10
|
-
import type { PyreonComponent } from
|
|
7
|
+
import type { VNode, VNodeChild } from '@pyreon/core'
|
|
8
|
+
import { render } from '@pyreon/ui-core'
|
|
9
|
+
import { PKG_NAME } from '../constants'
|
|
10
|
+
import type { PyreonComponent } from '../types'
|
|
11
11
|
|
|
12
12
|
export interface Props {
|
|
13
13
|
/**
|
|
@@ -25,7 +25,7 @@ export interface Props {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const Component: PyreonComponent<Props> = (({ children, className, style }: Props) => {
|
|
28
|
-
const mergedClasses = Array.isArray(className) ? className.join(
|
|
28
|
+
const mergedClasses = Array.isArray(className) ? className.join(' ') : className
|
|
29
29
|
|
|
30
30
|
const finalProps: Record<string, any> = {}
|
|
31
31
|
if (style) finalProps.style = style
|
package/src/Util/index.ts
CHANGED