@codeleap/web 3.13.3 → 3.13.5
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/package.json
CHANGED
|
@@ -8,7 +8,7 @@ import { Touchable, TouchableProps } from '../Touchable'
|
|
|
8
8
|
import { View, ViewProps } from '../View'
|
|
9
9
|
import { OverlayComposition, OverlayPresets } from './styles'
|
|
10
10
|
import { NativeHTMLElement } from '../../types'
|
|
11
|
-
import {
|
|
11
|
+
import { usePopState } from '../../lib'
|
|
12
12
|
|
|
13
13
|
export type OverlayProps<T extends NativeHTMLElement = 'div'> = {
|
|
14
14
|
visible?: boolean
|
|
@@ -37,8 +37,6 @@ export const Overlay = <T extends NativeHTMLElement>(overlayProps:OverlayProps<T
|
|
|
37
37
|
|
|
38
38
|
usePopState(visible, props.onPress, scrollLocked)
|
|
39
39
|
|
|
40
|
-
useLockScroll(visible)
|
|
41
|
-
|
|
42
40
|
const Component = props.onClick || props.onPress ? Touchable : View
|
|
43
41
|
|
|
44
42
|
return (
|
|
@@ -21,30 +21,53 @@ export type TouchableProps<T extends ElementType = 'button'> = ComponentPropsWit
|
|
|
21
21
|
debounce?: number
|
|
22
22
|
leadingDebounce?: boolean
|
|
23
23
|
setPressed?: (pressed: boolean) => void
|
|
24
|
+
analyticsEnabled?: boolean
|
|
25
|
+
analyticsName?: string
|
|
26
|
+
analyticsData?: Record<string, any>
|
|
24
27
|
} & ComponentVariants<typeof TouchablePresets>
|
|
25
28
|
|
|
29
|
+
const defaultProps: TouchableProps<'button'> = {
|
|
30
|
+
propagate: true,
|
|
31
|
+
debounce: null,
|
|
32
|
+
component: View,
|
|
33
|
+
style: {},
|
|
34
|
+
styles: {},
|
|
35
|
+
responsiveVariants: {},
|
|
36
|
+
variants: [],
|
|
37
|
+
css: [],
|
|
38
|
+
analyticsEnabled: false,
|
|
39
|
+
analyticsName: null,
|
|
40
|
+
analyticsData: {},
|
|
41
|
+
}
|
|
26
42
|
export const TouchableCP = <T extends NativeHTMLElement = 'button'>(
|
|
27
43
|
touchableProps: TouchableProps<T>,
|
|
28
44
|
ref,
|
|
29
45
|
) => {
|
|
46
|
+
const mergedProps: TouchableProps = {
|
|
47
|
+
...(defaultProps),
|
|
48
|
+
...(touchableProps),
|
|
49
|
+
}
|
|
30
50
|
const {
|
|
31
|
-
propagate
|
|
32
|
-
debounce
|
|
51
|
+
propagate,
|
|
52
|
+
debounce,
|
|
33
53
|
leadingDebounce,
|
|
34
54
|
setPressed,
|
|
35
|
-
component: Component
|
|
55
|
+
component: Component,
|
|
36
56
|
disabled,
|
|
37
57
|
onPress,
|
|
38
58
|
onClick,
|
|
39
59
|
debugName,
|
|
40
60
|
debugComponent,
|
|
41
|
-
style
|
|
42
|
-
styles
|
|
43
|
-
responsiveVariants
|
|
44
|
-
variants
|
|
45
|
-
css
|
|
61
|
+
style,
|
|
62
|
+
styles,
|
|
63
|
+
responsiveVariants,
|
|
64
|
+
variants,
|
|
65
|
+
css,
|
|
66
|
+
analyticsEnabled,
|
|
67
|
+
analyticsName,
|
|
68
|
+
analyticsData,
|
|
46
69
|
...props
|
|
47
|
-
} =
|
|
70
|
+
} = mergedProps
|
|
48
71
|
|
|
49
72
|
const pressed = React.useRef(!!leadingDebounce)
|
|
50
73
|
|
|
@@ -60,7 +83,7 @@ export const TouchableCP = <T extends NativeHTMLElement = 'button'>(
|
|
|
60
83
|
responsiveVariants,
|
|
61
84
|
variants,
|
|
62
85
|
styles,
|
|
63
|
-
rootElement: 'wrapper'
|
|
86
|
+
rootElement: 'wrapper',
|
|
64
87
|
})
|
|
65
88
|
|
|
66
89
|
const { logger } = useCodeleapContext()
|
|
@@ -76,7 +99,7 @@ export const TouchableCP = <T extends NativeHTMLElement = 'button'>(
|
|
|
76
99
|
logger.warn(
|
|
77
100
|
'No onPress passed to touchable',
|
|
78
101
|
touchableProps,
|
|
79
|
-
'User interaction'
|
|
102
|
+
'User interaction',
|
|
80
103
|
)
|
|
81
104
|
return
|
|
82
105
|
}
|
|
@@ -85,8 +108,14 @@ export const TouchableCP = <T extends NativeHTMLElement = 'button'>(
|
|
|
85
108
|
logger.log(
|
|
86
109
|
`<${debugComponent || 'Touchable'}/> pressed`,
|
|
87
110
|
{ debugName, debugComponent },
|
|
88
|
-
'User interaction'
|
|
111
|
+
'User interaction',
|
|
89
112
|
)
|
|
113
|
+
if (analyticsEnabled) {
|
|
114
|
+
const name = analyticsName || debugName
|
|
115
|
+
if (!!name?.trim?.()) {
|
|
116
|
+
logger.analytics?.interaction(name, analyticsData)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
90
119
|
|
|
91
120
|
if (TypeGuards.isFunction(onClick)) onClick?.(event)
|
|
92
121
|
onPress?.()
|
|
@@ -127,6 +156,10 @@ export const TouchableCP = <T extends NativeHTMLElement = 'button'>(
|
|
|
127
156
|
)
|
|
128
157
|
}
|
|
129
158
|
|
|
130
|
-
export const Touchable = forwardRef(TouchableCP) as <T extends NativeHTMLElement = 'button'>(
|
|
159
|
+
export const Touchable = forwardRef(TouchableCP) as (<T extends NativeHTMLElement = 'button'>(
|
|
131
160
|
touchableProps: TouchableProps<T>
|
|
132
|
-
) => JSX.Element
|
|
161
|
+
) => JSX.Element) & {
|
|
162
|
+
defaultProps: Partial<TouchableProps<'button'>>
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
Touchable.defaultProps = defaultProps
|
package/src/lib/hooks.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyFunction, onMount, onUpdate, range,
|
|
1
|
+
import { AnyFunction, onMount, onUpdate, range, useUncontrolled } from '@codeleap/common'
|
|
2
2
|
import { useCallback, useMemo, useRef, useState } from 'react'
|
|
3
3
|
import { v4 } from 'uuid'
|
|
4
4
|
import { easeInOut, EasingFunction, AnimationProps, useAnimate, useAnimation, animate } from 'framer-motion'
|
|
@@ -352,23 +352,3 @@ export function useAnimatedVariantStyles<T extends Record<string|number|symbol,
|
|
|
352
352
|
|
|
353
353
|
return animated
|
|
354
354
|
}
|
|
355
|
-
|
|
356
|
-
export function useLockScroll(isLock: boolean) {
|
|
357
|
-
useIsomorphicEffect(() => {
|
|
358
|
-
const htmlStyle = document?.documentElement?.style
|
|
359
|
-
|
|
360
|
-
if (!!htmlStyle) {
|
|
361
|
-
if (htmlStyle.overflowX !== 'hidden') {
|
|
362
|
-
htmlStyle.overflowX = 'hidden'
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
console.log({ isLock, flow: htmlStyle.overflowY })
|
|
366
|
-
|
|
367
|
-
if (isLock) {
|
|
368
|
-
htmlStyle.overflowY = 'hidden'
|
|
369
|
-
} else if (!isLock && htmlStyle.overflowY === 'hidden') {
|
|
370
|
-
htmlStyle.overflowY = 'auto'
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}, [isLock])
|
|
374
|
-
}
|