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