@codeleap/web 3.24.3 → 3.25.0
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 +2 -1
- package/src/components/ActionIcon/index.tsx +51 -52
- package/src/components/ActionIcon/styles.ts +1 -5
- package/src/components/ActionIcon/types.ts +15 -0
- package/src/components/ActivityIndicator/index.tsx +34 -55
- package/src/components/ActivityIndicator/styles.ts +0 -6
- package/src/components/ActivityIndicator/types.ts +12 -0
- package/src/components/Badge/index.tsx +43 -80
- package/src/components/Badge/styles.ts +1 -11
- package/src/components/Badge/types.ts +28 -0
- package/src/components/Button/index.tsx +46 -89
- package/src/components/Button/styles.ts +0 -5
- package/src/components/Button/types.ts +25 -0
- package/src/components/Checkbox/index.tsx +83 -97
- package/src/components/Checkbox/styles.ts +1 -5
- package/src/components/Checkbox/types.ts +15 -0
- package/src/components/Collapse/index.tsx +41 -83
- package/src/components/Collapse/styles.ts +3 -6
- package/src/components/Collapse/types.ts +11 -0
- package/src/components/ColorPicker/index.tsx +95 -48
- package/src/components/ColorPicker/styles.ts +11 -11
- package/src/components/ColorPicker/types.ts +26 -12
- package/src/components/CropPicker/index.tsx +100 -104
- package/src/components/CropPicker/styles.ts +0 -7
- package/src/components/CropPicker/types.ts +8 -15
- package/src/components/DatePicker/{defaultComponents → components}/Header.tsx +9 -17
- package/src/components/DatePicker/{defaultComponents → components}/OuterInput.tsx +6 -7
- package/src/components/DatePicker/index.tsx +110 -124
- package/src/components/DatePicker/styles.ts +1 -12
- package/src/components/DatePicker/types.ts +16 -33
- package/src/components/Drawer/index.tsx +133 -125
- package/src/components/Drawer/styles.ts +0 -5
- package/src/components/Drawer/types.ts +23 -0
- package/src/components/Dropzone/index.tsx +87 -63
- package/src/components/Dropzone/styles.ts +0 -6
- package/src/components/Dropzone/types.ts +29 -37
- package/src/components/EmptyPlaceholder/index.tsx +63 -83
- package/src/components/EmptyPlaceholder/styles.ts +0 -5
- package/src/components/EmptyPlaceholder/types.ts +32 -0
- package/src/components/FileInput/index.tsx +72 -0
- package/src/components/FileInput/types.ts +14 -0
- package/src/components/Grid/index.tsx +40 -41
- package/src/components/Grid/styles.ts +2 -9
- package/src/components/Grid/types.ts +10 -12
- package/src/components/Icon/index.tsx +45 -47
- package/src/components/Icon/styles.ts +0 -8
- package/src/components/Icon/types.ts +15 -0
- package/src/components/InputBase/index.tsx +71 -42
- package/src/components/InputBase/styles.ts +37 -47
- package/src/components/InputBase/types.ts +19 -7
- package/src/components/InputBase/utils.ts +3 -23
- package/src/components/List/ListLayout.tsx +20 -37
- package/src/components/List/index.tsx +36 -41
- package/src/components/List/styles.ts +5 -11
- package/src/components/List/types.ts +30 -20
- package/src/components/LoadingOverlay/index.tsx +31 -33
- package/src/components/LoadingOverlay/styles.ts +3 -8
- package/src/components/LoadingOverlay/types.ts +16 -0
- package/src/components/Modal/index.tsx +98 -160
- package/src/components/Modal/styles.ts +0 -5
- package/src/components/Modal/types.ts +55 -0
- package/src/components/NumberIncrement/index.tsx +67 -98
- package/src/components/NumberIncrement/styles.ts +0 -5
- package/src/components/NumberIncrement/types.ts +29 -0
- package/src/components/Overlay/index.tsx +37 -35
- package/src/components/Overlay/styles.ts +3 -5
- package/src/components/Overlay/types.ts +13 -0
- package/src/components/Pager/index.tsx +65 -81
- package/src/components/Pager/styles.ts +3 -9
- package/src/components/Pager/types.ts +35 -0
- package/src/components/PaginationButtons/index.tsx +173 -0
- package/src/components/PaginationButtons/styles.ts +7 -0
- package/src/components/PaginationButtons/types.ts +26 -0
- package/src/components/PaginationIndicator/index.tsx +69 -0
- package/src/components/PaginationIndicator/styles.ts +3 -0
- package/src/components/PaginationIndicator/types.ts +18 -0
- package/src/components/Progress/Bar/index.tsx +45 -50
- package/src/components/Progress/Bar/styles.ts +10 -0
- package/src/components/Progress/Bar/types.ts +26 -0
- package/src/components/Progress/Circle/index.tsx +45 -48
- package/src/components/Progress/Circle/styles.ts +1 -8
- package/src/components/Progress/Circle/types.ts +10 -22
- package/src/components/RadioInput/index.tsx +78 -124
- package/src/components/RadioInput/styles.ts +0 -6
- package/src/components/RadioInput/types.ts +29 -0
- package/src/components/SearchInput/index.tsx +10 -10
- package/src/components/SectionFilters/index.tsx +47 -36
- package/src/components/SectionFilters/styles.ts +1 -5
- package/src/components/SectionFilters/types.ts +14 -13
- package/src/components/SegmentedControl/index.tsx +111 -89
- package/src/components/SegmentedControl/styles.ts +7 -21
- package/src/components/SegmentedControl/types.ts +44 -0
- package/src/components/Select/index.tsx +92 -56
- package/src/components/Select/styles.ts +19 -36
- package/src/components/Select/types.ts +15 -10
- package/src/components/Slider/index.tsx +85 -93
- package/src/components/Slider/styles.ts +13 -6
- package/src/components/Slider/types.ts +29 -0
- package/src/components/Switch/index.tsx +63 -74
- package/src/components/Switch/styles.ts +1 -6
- package/src/components/Switch/types.ts +13 -0
- package/src/components/Tag/index.tsx +39 -44
- package/src/components/Tag/styles.ts +1 -9
- package/src/components/Tag/types.ts +10 -10
- package/src/components/Text/index.tsx +37 -48
- package/src/components/Text/styles.ts +0 -8
- package/src/components/Text/types.ts +8 -8
- package/src/components/TextEditor/index.tsx +49 -28
- package/src/components/TextEditor/styles.ts +1 -8
- package/src/components/TextEditor/types.ts +11 -6
- package/src/components/TextInput/index.tsx +58 -96
- package/src/components/TextInput/mask.tsx +2 -50
- package/src/components/TextInput/styles.ts +3 -8
- package/src/components/TextInput/types.ts +85 -0
- package/src/components/Tooltip/index.tsx +61 -84
- package/src/components/Tooltip/styles.ts +3 -10
- package/src/components/Tooltip/types.ts +46 -0
- package/src/components/Touchable/index.tsx +43 -86
- package/src/components/Touchable/styles.ts +0 -6
- package/src/components/Touchable/types.ts +22 -0
- package/src/components/View/index.tsx +36 -50
- package/src/components/View/styles.ts +0 -6
- package/src/components/View/types.ts +14 -15
- package/src/components/components.ts +2 -3
- package/src/index.ts +1 -0
- package/src/lib/WebStyleRegistry.ts +51 -0
- package/src/lib/hooks/index.ts +5 -0
- package/src/lib/hooks/useBreakpointMatch.ts +8 -7
- package/src/{components/CropPicker/useCropPicker.tsx → lib/hooks/useCropPicker.ts} +66 -13
- package/src/lib/hooks/useFileInput.ts +15 -0
- package/src/lib/hooks/useInfiniteScroll.ts +77 -0
- package/src/lib/hooks/useMediaQuery.ts +4 -3
- package/src/lib/hooks/usePagination.ts +79 -63
- package/src/lib/hooks/useRefresh.ts +87 -0
- package/src/lib/hooks/useStylesFor.ts +13 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/utils/cache.ts +9 -0
- package/src/lib/utils/index.ts +1 -0
- package/src/lib/utils/test.ts +2 -2
- package/src/components/CropPicker/utils.ts +0 -51
- package/src/components/FileInput.tsx +0 -91
- package/src/components/List/PaginationIndicator.tsx +0 -102
- package/src/components/List/useInfiniteScroll.ts +0 -159
- package/src/components/Progress/Bar/styles.tsx +0 -7
- package/src/components/Progress/Bar/types.tsx +0 -30
- package/src/components/Scroll/index.tsx +0 -32
- package/src/components/Scroll/styles.ts +0 -8
- package/src/components/SegmentedControl/SegmentedControlOption.tsx +0 -84
- package/src/components/defaultStyles.ts +0 -79
- /package/src/components/DatePicker/{defaultComponents → components}/index.tsx +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react'
|
|
2
2
|
import {
|
|
3
3
|
Provider as TooltipContainer,
|
|
4
4
|
Root as TooltipWrapper,
|
|
@@ -6,72 +6,30 @@ import {
|
|
|
6
6
|
Portal as TooltipPortal,
|
|
7
7
|
Content as TooltipContent,
|
|
8
8
|
Arrow as TooltipArrow,
|
|
9
|
-
TooltipProps as PrimitiveTooltipProps,
|
|
10
|
-
TooltipContentProps,
|
|
11
|
-
TooltipPortalProps,
|
|
12
|
-
TooltipArrowProps,
|
|
13
|
-
TooltipTriggerProps,
|
|
14
|
-
TooltipProviderProps,
|
|
15
9
|
} from '@radix-ui/react-tooltip'
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
import { TooltipComposition, TooltipPresets } from './styles'
|
|
19
|
-
import { ComponentCommonProps, ComponentWithDefaultProps } from '../../types/utility'
|
|
20
|
-
import { View, ViewProps } from '../View'
|
|
10
|
+
import { TypeGuards, useConditionalState } from '@codeleap/common'
|
|
11
|
+
import { View } from '../View'
|
|
21
12
|
import { useClickOutsideElement } from '../../lib'
|
|
13
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
14
|
+
import { TooltipProps } from './types'
|
|
15
|
+
import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
16
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
portalProps?: TooltipPortalProps
|
|
26
|
-
arrowProps?: TooltipArrowProps
|
|
27
|
-
triggerProps?: TooltipTriggerProps
|
|
28
|
-
providerProps?: TooltipProviderProps
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export type TooltipProps = PrimitiveTooltipProps & TooltipComponentProps & {
|
|
32
|
-
toggle?: AnyFunction
|
|
33
|
-
visible?: boolean
|
|
34
|
-
content: React.ReactNode | ((props: TooltipProps & { variantsStyles: StylesOf<TooltipComposition> }) => JSX.Element)
|
|
35
|
-
triggerWrapper?: React.ElementType
|
|
36
|
-
triggerWrapperProps?: Partial<ViewProps<'div'>>
|
|
37
|
-
styles?: StylesOf<TooltipComposition>
|
|
38
|
-
side?: 'left' | 'right' | 'bottom' | 'top'
|
|
39
|
-
openOnPress?: boolean
|
|
40
|
-
openOnHover?: boolean
|
|
41
|
-
disabled?: boolean
|
|
42
|
-
delayDuration?: number
|
|
43
|
-
closeOnClickOutside?: boolean
|
|
44
|
-
onOpen?: AnyFunction
|
|
45
|
-
onClose?: AnyFunction
|
|
46
|
-
onValueChange?: (value: boolean) => void
|
|
47
|
-
onHover?: (hoverType: 'enter' | 'leave', value: boolean) => void
|
|
48
|
-
onPress?: (value: boolean) => void
|
|
49
|
-
children?: React.ReactNode
|
|
50
|
-
style?: React.CSSProperties
|
|
51
|
-
} & ComponentVariants<typeof TooltipPresets> & ComponentCommonProps
|
|
52
|
-
|
|
53
|
-
const defaultProps: Partial<TooltipProps> = {
|
|
54
|
-
openOnPress: true,
|
|
55
|
-
openOnHover: true,
|
|
56
|
-
disabled: false,
|
|
57
|
-
delayDuration: 0,
|
|
58
|
-
closeOnClickOutside: false,
|
|
59
|
-
side: 'bottom',
|
|
60
|
-
triggerWrapper: View as unknown as React.ElementType,
|
|
61
|
-
}
|
|
18
|
+
export * from './styles'
|
|
19
|
+
export * from './types'
|
|
62
20
|
|
|
63
|
-
export const Tooltip
|
|
21
|
+
export const Tooltip = (props: TooltipProps) => {
|
|
64
22
|
const allProps = {
|
|
65
23
|
...Tooltip.defaultProps,
|
|
66
24
|
...props,
|
|
67
25
|
}
|
|
68
26
|
|
|
69
27
|
const {
|
|
70
|
-
toggle: _toggle
|
|
71
|
-
visible: _visible
|
|
28
|
+
toggle: _toggle,
|
|
29
|
+
visible: _visible,
|
|
72
30
|
children,
|
|
73
31
|
content: Content,
|
|
74
|
-
triggerWrapperProps
|
|
32
|
+
triggerWrapperProps,
|
|
75
33
|
triggerWrapper: TriggerWrapper,
|
|
76
34
|
side,
|
|
77
35
|
disabled,
|
|
@@ -83,32 +41,23 @@ export const Tooltip: ComponentWithDefaultProps<TooltipProps> = (props: TooltipP
|
|
|
83
41
|
onValueChange,
|
|
84
42
|
onHover,
|
|
85
43
|
onPress,
|
|
86
|
-
contentProps
|
|
87
|
-
portalProps
|
|
88
|
-
arrowProps
|
|
89
|
-
triggerProps
|
|
90
|
-
providerProps
|
|
91
|
-
variants = [],
|
|
92
|
-
responsiveVariants = {},
|
|
93
|
-
styles = {},
|
|
44
|
+
contentProps,
|
|
45
|
+
portalProps,
|
|
46
|
+
arrowProps,
|
|
47
|
+
triggerProps,
|
|
48
|
+
providerProps,
|
|
94
49
|
closeOnClickOutside,
|
|
95
50
|
style,
|
|
96
51
|
...rest
|
|
97
52
|
} = allProps
|
|
98
53
|
|
|
99
|
-
const
|
|
100
|
-
responsiveVariants,
|
|
101
|
-
variants,
|
|
102
|
-
styles,
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
const hasStateProps = !TypeGuards.isNil(_visible) && TypeGuards.isFunction(_toggle)
|
|
54
|
+
const styles = useStylesFor(Tooltip.styleRegistryName, style)
|
|
106
55
|
|
|
107
|
-
const [visible, toggle] =
|
|
56
|
+
const [visible, toggle] = useConditionalState(_visible, _toggle, { initialValue: false })
|
|
108
57
|
|
|
109
58
|
const tooltipDirectionStyle = React.useMemo(() => {
|
|
110
|
-
return side ?
|
|
111
|
-
}, [side,
|
|
59
|
+
return side ? styles[`content:${side}`] : styles.content
|
|
60
|
+
}, [side, styles])
|
|
112
61
|
|
|
113
62
|
function handleToggle(_value: boolean, isToggle = true) {
|
|
114
63
|
if (disabled) return
|
|
@@ -163,8 +112,7 @@ export const Tooltip: ComponentWithDefaultProps<TooltipProps> = (props: TooltipP
|
|
|
163
112
|
open={visible}
|
|
164
113
|
onOpenChange={onOpenChange}
|
|
165
114
|
{...rest}
|
|
166
|
-
// @ts-ignore
|
|
167
|
-
css={[variantsStyles.wrapper, style]}
|
|
115
|
+
// @ts-ignore
|
|
168
116
|
>
|
|
169
117
|
<TooltipTrigger
|
|
170
118
|
onClick={_onPress}
|
|
@@ -173,29 +121,35 @@ export const Tooltip: ComponentWithDefaultProps<TooltipProps> = (props: TooltipP
|
|
|
173
121
|
asChild
|
|
174
122
|
ref={triggerRef}
|
|
175
123
|
{...triggerProps}
|
|
176
|
-
|
|
124
|
+
//@ts-expect-error
|
|
125
|
+
css={styles.triggerWrapper}
|
|
177
126
|
>
|
|
178
|
-
<TriggerWrapper
|
|
179
|
-
{...allProps as any}
|
|
127
|
+
<TriggerWrapper
|
|
128
|
+
{...allProps as any}
|
|
180
129
|
{...triggerWrapperProps}
|
|
181
|
-
|
|
130
|
+
css={styles.triggerInnerWrapper}
|
|
182
131
|
>
|
|
183
132
|
{children}
|
|
184
133
|
</TriggerWrapper>
|
|
185
134
|
</TooltipTrigger>
|
|
186
135
|
<TooltipPortal {...portalProps}>
|
|
187
|
-
|
|
136
|
+
{/* @ts-expect-error icss type */}
|
|
137
|
+
<TooltipContent ref={contentRef} css={[tooltipDirectionStyle, styles.content]} sideOffset={2} side={side} {...contentProps}>
|
|
188
138
|
{
|
|
189
139
|
TypeGuards.isFunction(Content)
|
|
190
140
|
? <Content
|
|
191
141
|
{...allProps}
|
|
192
142
|
visible={visible}
|
|
193
143
|
toggle={toggle}
|
|
194
|
-
variantsStyles={
|
|
144
|
+
variantsStyles={styles}
|
|
195
145
|
/>
|
|
196
146
|
: Content
|
|
197
147
|
}
|
|
198
|
-
<TooltipArrow
|
|
148
|
+
<TooltipArrow
|
|
149
|
+
{...arrowProps}
|
|
150
|
+
//@ts-expect-error icss type
|
|
151
|
+
css={styles.arrow}
|
|
152
|
+
/>
|
|
199
153
|
</TooltipContent>
|
|
200
154
|
</TooltipPortal>
|
|
201
155
|
</TooltipWrapper>
|
|
@@ -204,6 +158,29 @@ export const Tooltip: ComponentWithDefaultProps<TooltipProps> = (props: TooltipP
|
|
|
204
158
|
)
|
|
205
159
|
}
|
|
206
160
|
|
|
207
|
-
Tooltip.
|
|
161
|
+
Tooltip.styleRegistryName = 'Tooltip'
|
|
208
162
|
|
|
209
|
-
|
|
163
|
+
Tooltip.elements = [
|
|
164
|
+
'content',
|
|
165
|
+
'arrow',
|
|
166
|
+
'triggerWrapper',
|
|
167
|
+
'triggerInnerWrapper',
|
|
168
|
+
]
|
|
169
|
+
|
|
170
|
+
Tooltip.rootElement = 'content'
|
|
171
|
+
|
|
172
|
+
Tooltip.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
173
|
+
return Tooltip as (props: StyledComponentProps<TooltipProps, typeof styles>) => IJSX
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
Tooltip.defaultProps = {
|
|
177
|
+
openOnPress: true,
|
|
178
|
+
openOnHover: true,
|
|
179
|
+
disabled: false,
|
|
180
|
+
delayDuration: 0,
|
|
181
|
+
closeOnClickOutside: false,
|
|
182
|
+
side: 'bottom',
|
|
183
|
+
triggerWrapper: View as unknown as React.ElementType,
|
|
184
|
+
} as Partial<TooltipProps>
|
|
185
|
+
|
|
186
|
+
WebStyleRegistry.registerComponent(Tooltip)
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
|
-
|
|
3
1
|
export type TooltipSide = 'left' | 'right' | 'bottom' | 'top'
|
|
2
|
+
|
|
4
3
|
export type TooltipState = 'delayed-open' | 'closed' | 'instant-open' | 'disabled'
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
|
|
5
|
+
export type TooltipParts =
|
|
7
6
|
'arrow' |
|
|
8
7
|
'content' |
|
|
9
8
|
'triggerWrapper' |
|
|
10
9
|
'triggerInnerWrapper'
|
|
11
10
|
|
|
12
11
|
export type TooltipComposition = `content:${TooltipSide}` | TooltipParts
|
|
13
|
-
|
|
14
|
-
const createTooltipStyle = createDefaultVariantFactory<TooltipComposition>()
|
|
15
|
-
|
|
16
|
-
export const TooltipPresets = includePresets((styles) => createTooltipStyle(() => ({
|
|
17
|
-
wrapper: styles,
|
|
18
|
-
})))
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
TooltipProps as PrimitiveTooltipProps,
|
|
4
|
+
TooltipContentProps,
|
|
5
|
+
TooltipPortalProps,
|
|
6
|
+
TooltipArrowProps,
|
|
7
|
+
TooltipTriggerProps,
|
|
8
|
+
TooltipProviderProps,
|
|
9
|
+
} from '@radix-ui/react-tooltip'
|
|
10
|
+
import { AnyFunction, StylesOf } from '@codeleap/common'
|
|
11
|
+
import { TooltipComposition } from './styles'
|
|
12
|
+
import { ViewProps } from '../View'
|
|
13
|
+
import { StyledProp } from '@codeleap/styles'
|
|
14
|
+
|
|
15
|
+
type TooltipComponentProps = {
|
|
16
|
+
contentProps?: TooltipContentProps
|
|
17
|
+
portalProps?: TooltipPortalProps
|
|
18
|
+
arrowProps?: TooltipArrowProps
|
|
19
|
+
triggerProps?: TooltipTriggerProps
|
|
20
|
+
providerProps?: TooltipProviderProps
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type TooltipProps =
|
|
24
|
+
Omit<PrimitiveTooltipProps, 'style'> &
|
|
25
|
+
Omit<TooltipComponentProps, 'style'> &
|
|
26
|
+
{
|
|
27
|
+
toggle?: AnyFunction
|
|
28
|
+
visible?: boolean
|
|
29
|
+
content: React.ReactNode | ((props: TooltipProps & { variantsStyles: StylesOf<TooltipComposition> }) => JSX.Element)
|
|
30
|
+
triggerWrapper?: React.ElementType
|
|
31
|
+
triggerWrapperProps?: Partial<ViewProps>
|
|
32
|
+
style?: StyledProp<TooltipComposition>
|
|
33
|
+
side?: 'left' | 'right' | 'bottom' | 'top'
|
|
34
|
+
openOnPress?: boolean
|
|
35
|
+
openOnHover?: boolean
|
|
36
|
+
disabled?: boolean
|
|
37
|
+
delayDuration?: number
|
|
38
|
+
closeOnClickOutside?: boolean
|
|
39
|
+
onOpen?: AnyFunction
|
|
40
|
+
onClose?: AnyFunction
|
|
41
|
+
onValueChange?: (value: boolean) => void
|
|
42
|
+
onHover?: (hoverType: 'enter' | 'leave', value: boolean) => void
|
|
43
|
+
onPress?: (value: boolean) => void
|
|
44
|
+
children?: React.ReactNode
|
|
45
|
+
debugName?: string
|
|
46
|
+
}
|
|
@@ -1,77 +1,45 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import React, {
|
|
1
|
+
import { onMount, TypeGuards, useGlobalContext } from '@codeleap/common'
|
|
2
|
+
import React, { ComponentType, ElementType, forwardRef, HTMLAttributes } from 'react'
|
|
3
3
|
import { stopPropagation } from '../../lib'
|
|
4
|
-
import { View } from '../View'
|
|
5
|
-
import { TouchableComposition, TouchablePresets } from './styles'
|
|
6
|
-
import { CSSInterpolation } from '@emotion/css'
|
|
7
|
-
import { StylesOf, NativeHTMLElement } from '../../types'
|
|
8
4
|
import { getTestId } from '../../lib/utils/test'
|
|
5
|
+
import { TouchableProps } from './types'
|
|
6
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
7
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
8
|
+
import { AnyRecord, IJSX, StyledComponentProps, StyledComponentWithProps } from '@codeleap/styles'
|
|
9
|
+
|
|
9
10
|
export * from './styles'
|
|
11
|
+
export * from './types'
|
|
10
12
|
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
propagate?: boolean
|
|
16
|
-
style?: React.CSSProperties
|
|
17
|
-
onPress?: AnyFunction
|
|
18
|
-
debugName: string
|
|
19
|
-
debugComponent?: string
|
|
20
|
-
styles?: StylesOf<TouchableComposition>
|
|
21
|
-
debounce?: number
|
|
22
|
-
leadingDebounce?: boolean
|
|
23
|
-
setPressed?: (pressed: boolean) => void
|
|
24
|
-
analyticsEnabled?: boolean
|
|
25
|
-
analyticsName?: string
|
|
26
|
-
analyticsData?: Record<string, any>
|
|
27
|
-
} & ComponentVariants<typeof TouchablePresets>
|
|
28
|
-
|
|
29
|
-
const defaultProps: Partial<TouchableProps<'button'>> = {
|
|
30
|
-
propagate: true,
|
|
31
|
-
debounce: null,
|
|
32
|
-
component: View as unknown as 'button',
|
|
33
|
-
style: {},
|
|
34
|
-
styles: {},
|
|
35
|
-
responsiveVariants: {},
|
|
36
|
-
variants: [],
|
|
37
|
-
css: [],
|
|
38
|
-
analyticsEnabled: false,
|
|
39
|
-
analyticsName: null,
|
|
40
|
-
analyticsData: {},
|
|
41
|
-
tabIndex: 0,
|
|
42
|
-
}
|
|
43
|
-
export const TouchableCP = <T extends NativeHTMLElement = 'button'>(
|
|
44
|
-
touchableProps: TouchableProps<T>,
|
|
45
|
-
ref,
|
|
46
|
-
) => {
|
|
47
|
-
const mergedProps = {
|
|
48
|
-
...(defaultProps),
|
|
49
|
-
...(touchableProps),
|
|
13
|
+
export const Touchable = forwardRef<HTMLButtonElement, TouchableProps>((touchableProps: TouchableProps, ref) => {
|
|
14
|
+
const allProps = {
|
|
15
|
+
...Touchable.defaultProps,
|
|
16
|
+
...touchableProps,
|
|
50
17
|
}
|
|
18
|
+
|
|
51
19
|
const {
|
|
52
20
|
propagate,
|
|
53
21
|
debounce,
|
|
54
22
|
leadingDebounce,
|
|
55
23
|
setPressed,
|
|
56
|
-
component
|
|
24
|
+
component,
|
|
57
25
|
disabled,
|
|
58
26
|
onPress,
|
|
59
27
|
onClick,
|
|
60
28
|
debugName,
|
|
61
29
|
debugComponent,
|
|
62
30
|
style,
|
|
63
|
-
styles,
|
|
64
|
-
responsiveVariants,
|
|
65
|
-
variants,
|
|
66
|
-
css,
|
|
67
31
|
analyticsEnabled,
|
|
68
32
|
analyticsName,
|
|
69
33
|
analyticsData,
|
|
70
34
|
...props
|
|
71
|
-
} =
|
|
35
|
+
} = allProps
|
|
36
|
+
|
|
37
|
+
const styles = useStylesFor(Touchable.styleRegistryName, style)
|
|
72
38
|
|
|
73
39
|
const pressed = React.useRef(!!leadingDebounce)
|
|
74
40
|
|
|
41
|
+
const { logger } = useGlobalContext()
|
|
42
|
+
|
|
75
43
|
onMount(() => {
|
|
76
44
|
if (!!leadingDebounce && !!debounce) {
|
|
77
45
|
setTimeout(() => {
|
|
@@ -80,14 +48,7 @@ export const TouchableCP = <T extends NativeHTMLElement = 'button'>(
|
|
|
80
48
|
}
|
|
81
49
|
})
|
|
82
50
|
|
|
83
|
-
const
|
|
84
|
-
responsiveVariants,
|
|
85
|
-
variants,
|
|
86
|
-
styles,
|
|
87
|
-
rootElement: 'wrapper',
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
const { logger } = useCodeleapContext()
|
|
51
|
+
const Component = component as unknown as ComponentType<HTMLAttributes<HTMLButtonElement>>
|
|
91
52
|
|
|
92
53
|
const notPressable = !TypeGuards.isFunction(onPress) && !TypeGuards.isFunction(onClick)
|
|
93
54
|
|
|
@@ -96,14 +57,7 @@ export const TouchableCP = <T extends NativeHTMLElement = 'button'>(
|
|
|
96
57
|
|
|
97
58
|
if (!propagate) stopPropagation(event)
|
|
98
59
|
|
|
99
|
-
if (notPressable)
|
|
100
|
-
logger.warn(
|
|
101
|
-
'No onPress passed to touchable',
|
|
102
|
-
touchableProps,
|
|
103
|
-
'User interaction',
|
|
104
|
-
)
|
|
105
|
-
return
|
|
106
|
-
}
|
|
60
|
+
if (notPressable) return
|
|
107
61
|
|
|
108
62
|
const _onPress = () => {
|
|
109
63
|
if (event && (event?.type !== 'click' && event?.keyCode !== 13 && event?.key !== 'Enter')) return null
|
|
@@ -140,34 +94,37 @@ export const TouchableCP = <T extends NativeHTMLElement = 'button'>(
|
|
|
140
94
|
}
|
|
141
95
|
}
|
|
142
96
|
|
|
143
|
-
const
|
|
144
|
-
variantStyles.wrapper,
|
|
145
|
-
disabled && variantStyles['wrapper:disabled'],
|
|
146
|
-
css,
|
|
147
|
-
style,
|
|
148
|
-
]), [variantStyles, disabled, style])
|
|
149
|
-
|
|
150
|
-
const testId = getTestId(mergedProps)
|
|
97
|
+
const testId = getTestId(allProps)
|
|
151
98
|
|
|
152
99
|
return (
|
|
153
|
-
|
|
154
|
-
<View
|
|
155
|
-
component={Component || 'button'}
|
|
100
|
+
<Component
|
|
156
101
|
{...props}
|
|
157
|
-
debugName={debugName}
|
|
158
102
|
onClick={handleClick}
|
|
159
103
|
onKeyDown={handleClick}
|
|
160
104
|
ref={ref}
|
|
161
|
-
|
|
105
|
+
// @ts-expect-error icss type
|
|
106
|
+
css={[styles.wrapper, disabled && styles['wrapper:disabled']]}
|
|
162
107
|
data-testid={testId}
|
|
163
108
|
/>
|
|
164
109
|
)
|
|
165
|
-
}
|
|
110
|
+
}) as StyledComponentWithProps<TouchableProps>
|
|
111
|
+
|
|
112
|
+
Touchable.styleRegistryName = 'Touchable'
|
|
113
|
+
Touchable.elements = ['wrapper']
|
|
114
|
+
Touchable.rootElement = 'wrapper'
|
|
166
115
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
) => JSX.Element) & {
|
|
170
|
-
defaultProps: Partial<TouchableProps<'button'>>
|
|
116
|
+
Touchable.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
117
|
+
return Touchable as <T extends ElementType = 'button'>(props: StyledComponentProps<TouchableProps<T>, typeof styles>) => IJSX
|
|
171
118
|
}
|
|
172
119
|
|
|
173
|
-
Touchable.defaultProps =
|
|
120
|
+
Touchable.defaultProps = {
|
|
121
|
+
propagate: true,
|
|
122
|
+
debounce: null,
|
|
123
|
+
component: 'div',
|
|
124
|
+
analyticsEnabled: false,
|
|
125
|
+
analyticsName: null,
|
|
126
|
+
analyticsData: {},
|
|
127
|
+
tabIndex: 0,
|
|
128
|
+
} as Partial<TouchableProps>
|
|
129
|
+
|
|
130
|
+
WebStyleRegistry.registerComponent(Touchable)
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
|
-
|
|
3
1
|
export type TouchableState = 'disabled'
|
|
4
2
|
export type TouchableParts = 'wrapper'
|
|
5
3
|
export type TouchableComposition = TouchableParts | `${TouchableParts}:${TouchableState}`
|
|
6
|
-
|
|
7
|
-
const createTouchableStyle = createDefaultVariantFactory<TouchableComposition>()
|
|
8
|
-
|
|
9
|
-
export const TouchablePresets = includePresets((styles) => createTouchableStyle(() => ({ wrapper: styles })))
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AnyFunction } from '@codeleap/common'
|
|
2
|
+
import { ComponentPropsWithRef, ElementType } from 'react'
|
|
3
|
+
import { TouchableComposition } from './styles'
|
|
4
|
+
import { AnyRecord, StyledProp } from '@codeleap/styles'
|
|
5
|
+
|
|
6
|
+
export type TouchableProps<T extends ElementType = 'button'> =
|
|
7
|
+
Omit<ComponentPropsWithRef<T>, 'style'> &
|
|
8
|
+
{
|
|
9
|
+
component?: ElementType<AnyRecord>
|
|
10
|
+
disabled?: boolean
|
|
11
|
+
propagate?: boolean
|
|
12
|
+
onPress?: AnyFunction
|
|
13
|
+
debugName: string
|
|
14
|
+
debugComponent?: string
|
|
15
|
+
style?: StyledProp<TouchableComposition>
|
|
16
|
+
debounce?: number
|
|
17
|
+
leadingDebounce?: boolean
|
|
18
|
+
setPressed?: (pressed: boolean) => void
|
|
19
|
+
analyticsEnabled?: boolean
|
|
20
|
+
analyticsName?: string
|
|
21
|
+
analyticsData?: Record<string, any>
|
|
22
|
+
}
|
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { useDefaultComponentStyle, useCodeleapContext, useMemo, TypeGuards } from '@codeleap/common'
|
|
4
|
-
import React, { forwardRef, Ref } from 'react'
|
|
5
|
-
import { ViewPresets } from './styles'
|
|
1
|
+
import { useMemo, TypeGuards } from '@codeleap/common'
|
|
2
|
+
import React, { ElementType, forwardRef } from 'react'
|
|
6
3
|
import { useMediaQuery } from '../../lib/hooks'
|
|
7
|
-
import { NativeHTMLElement } from '../../types'
|
|
8
4
|
import { motion } from 'framer-motion'
|
|
9
5
|
import { ViewProps } from './types'
|
|
10
6
|
import { getTestId } from '../../lib/utils/test'
|
|
7
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
8
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
9
|
+
import { AnyRecord, IJSX, StyledComponentProps, StyledComponentWithProps, useTheme } from '@codeleap/styles'
|
|
11
10
|
|
|
12
11
|
export * from './styles'
|
|
13
12
|
export * from './types'
|
|
14
13
|
|
|
15
|
-
export const
|
|
16
|
-
viewProps: ViewProps<'div'>,
|
|
17
|
-
ref: React.Ref<any>,
|
|
18
|
-
) => {
|
|
14
|
+
export const View = forwardRef<HTMLDivElement, ViewProps>((viewProps, ref) => {
|
|
19
15
|
const {
|
|
20
|
-
|
|
21
|
-
variants = [],
|
|
22
|
-
component = 'div',
|
|
16
|
+
component,
|
|
23
17
|
children,
|
|
24
18
|
is,
|
|
25
19
|
not,
|
|
@@ -27,32 +21,28 @@ export const ViewCP = (
|
|
|
27
21
|
onHover,
|
|
28
22
|
debugName,
|
|
29
23
|
down,
|
|
30
|
-
scroll = false,
|
|
31
|
-
debug = false,
|
|
32
24
|
style,
|
|
33
|
-
animated
|
|
34
|
-
animatedProps
|
|
35
|
-
css = [],
|
|
25
|
+
animated,
|
|
26
|
+
animatedProps,
|
|
36
27
|
...props
|
|
37
|
-
} =
|
|
28
|
+
} = {
|
|
29
|
+
...View.defaultProps,
|
|
30
|
+
...viewProps,
|
|
31
|
+
}
|
|
38
32
|
|
|
39
|
-
const
|
|
33
|
+
const styles = useStylesFor(View.styleRegistryName, style)
|
|
40
34
|
|
|
41
|
-
const
|
|
42
|
-
responsiveVariants,
|
|
43
|
-
variants,
|
|
44
|
-
styles: { wrapper: style },
|
|
45
|
-
rootElement: 'wrapper',
|
|
46
|
-
})
|
|
35
|
+
const Component: ElementType = animated ? (motion?.[component as string] || motion.div) : (component || 'div')
|
|
47
36
|
|
|
48
|
-
const
|
|
37
|
+
const theme = useTheme(store => store.current)
|
|
49
38
|
|
|
50
39
|
function handleHover(isMouseOverElement: boolean) {
|
|
51
40
|
onHover?.(isMouseOverElement)
|
|
52
41
|
}
|
|
53
42
|
|
|
54
43
|
const platformMediaQuery = useMemo(() => {
|
|
55
|
-
|
|
44
|
+
// @ts-expect-error theme type
|
|
45
|
+
return theme?.media?.renderToPlatformQuery({
|
|
56
46
|
is,
|
|
57
47
|
not,
|
|
58
48
|
up,
|
|
@@ -62,42 +52,38 @@ export const ViewCP = (
|
|
|
62
52
|
|
|
63
53
|
const matches = useMediaQuery(platformMediaQuery)
|
|
64
54
|
|
|
65
|
-
const
|
|
66
|
-
return [
|
|
67
|
-
variantStyles.wrapper,
|
|
68
|
-
scroll && { overflowY: 'scroll' },
|
|
69
|
-
matches && { display: 'none' },
|
|
70
|
-
style,
|
|
71
|
-
css,
|
|
72
|
-
]
|
|
73
|
-
}, [variantStyles, scroll, matches, css])
|
|
74
|
-
|
|
75
|
-
const onHoverProps = TypeGuards.isFunction(onHover) && {
|
|
55
|
+
const hoverProps = TypeGuards.isFunction(onHover) && {
|
|
76
56
|
onMouseEnter: () => handleHover(true),
|
|
77
57
|
onMouseLeave: () => handleHover(false),
|
|
78
58
|
}
|
|
79
59
|
|
|
80
|
-
if (debug) {
|
|
81
|
-
logger.log(debugName, { componentStyles, platformMediaQuery, matches })
|
|
82
|
-
}
|
|
83
|
-
|
|
84
60
|
const testId = getTestId(viewProps)
|
|
85
61
|
|
|
86
62
|
return (
|
|
87
63
|
<Component
|
|
88
|
-
|
|
89
|
-
// @ts-expect-error
|
|
90
|
-
ref={ref}
|
|
91
|
-
{...onHoverProps}
|
|
64
|
+
{...hoverProps}
|
|
92
65
|
{...props}
|
|
93
66
|
{...animatedProps}
|
|
67
|
+
ref={ref}
|
|
94
68
|
data-testid={testId}
|
|
69
|
+
css={[styles.wrapper, matches && { display: 'none' }]}
|
|
95
70
|
>
|
|
96
71
|
{children}
|
|
97
72
|
</Component>
|
|
98
73
|
)
|
|
74
|
+
}) as StyledComponentWithProps<ViewProps>
|
|
75
|
+
|
|
76
|
+
View.styleRegistryName = 'View'
|
|
77
|
+
View.elements = ['wrapper']
|
|
78
|
+
View.rootElement = 'wrapper'
|
|
79
|
+
|
|
80
|
+
View.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
81
|
+
return View as <T extends ElementType = 'div'>(props: StyledComponentProps<ViewProps<T>, typeof styles>) => IJSX
|
|
99
82
|
}
|
|
100
83
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
84
|
+
View.defaultProps = {
|
|
85
|
+
component: 'div',
|
|
86
|
+
animated: false,
|
|
87
|
+
} as Partial<ViewProps>
|
|
88
|
+
|
|
89
|
+
WebStyleRegistry.registerComponent(View)
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
|
-
|
|
3
1
|
export type ViewComposition = 'wrapper'
|
|
4
|
-
|
|
5
|
-
const createViewStyle = createDefaultVariantFactory<ViewComposition>()
|
|
6
|
-
|
|
7
|
-
export const ViewPresets = includePresets((styles) => createViewStyle(() => ({ wrapper: styles })))
|