@codeleap/web 3.24.3 → 4.0.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,90 +1,45 @@
|
|
|
1
|
-
/** @jsx jsx */
|
|
2
|
-
import { jsx, CSSObject } from '@emotion/react'
|
|
3
1
|
import * as React from 'react'
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
yup,
|
|
7
|
-
useDefaultComponentStyle,
|
|
8
|
-
StylesOf,
|
|
9
|
-
PropsOf,
|
|
10
|
-
TypeGuards,
|
|
11
|
-
onUpdate,
|
|
12
|
-
useState,
|
|
13
|
-
useRef,
|
|
14
|
-
useValidate,
|
|
15
|
-
FormTypes,
|
|
16
|
-
IconPlaceholder,
|
|
17
|
-
} from '@codeleap/common'
|
|
18
|
-
import { View } from '../View'
|
|
19
|
-
import { NumberIncrementPresets, NumberIncrementComposition } from './styles'
|
|
20
|
-
import { InputBase, InputBaseProps, selectInputBaseProps } from '../InputBase'
|
|
2
|
+
import { TypeGuards, onUpdate, useState, useRef, useValidate } from '@codeleap/common'
|
|
3
|
+
import { InputBase, selectInputBaseProps } from '../InputBase'
|
|
21
4
|
import { Text } from '../Text'
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
NumberFormatBase,
|
|
28
|
-
} from 'react-number-format'
|
|
29
|
-
import { FormatInputValueFunction } from 'react-number-format/types/types'
|
|
5
|
+
import { PatternFormat, NumericFormat, NumericFormatProps as NFProps, NumberFormatBase } from 'react-number-format'
|
|
6
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
7
|
+
import { NumberIncrementProps } from './types'
|
|
8
|
+
import { AnyRecord, AppIcon, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
9
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
30
10
|
|
|
11
|
+
export * from './types'
|
|
31
12
|
export * from './styles'
|
|
32
13
|
|
|
33
|
-
export type NumberIncrementProps = Pick<
|
|
34
|
-
InputBaseProps,
|
|
35
|
-
'debugName' | 'disabled' | 'label'
|
|
36
|
-
> & {
|
|
37
|
-
styles?: StylesOf<NumberIncrementComposition>
|
|
38
|
-
value: number
|
|
39
|
-
onValueChange: (value: number) => void
|
|
40
|
-
onChangeText?: (value: number) => void
|
|
41
|
-
validate?: FormTypes.ValidatorWithoutForm<string> | yup.SchemaOf<string>
|
|
42
|
-
style?: PropsOf<typeof View>['style']
|
|
43
|
-
max?: number
|
|
44
|
-
min?: number
|
|
45
|
-
step?: number
|
|
46
|
-
editable?: boolean
|
|
47
|
-
prefix?: NFProps['prefix']
|
|
48
|
-
suffix?: NFProps['suffix']
|
|
49
|
-
separator?: NFProps['thousandSeparator']
|
|
50
|
-
format?: PFProps['format']
|
|
51
|
-
mask?: PFProps['mask']
|
|
52
|
-
hasSeparator?: boolean
|
|
53
|
-
_error?: string
|
|
54
|
-
formatter?: FormatInputValueFunction
|
|
55
|
-
placeholder?: string
|
|
56
|
-
} & ComponentVariants<typeof NumberIncrementPresets>
|
|
57
|
-
|
|
58
14
|
export const NumberIncrement = (props: NumberIncrementProps) => {
|
|
59
15
|
const {
|
|
60
16
|
inputBaseProps,
|
|
61
|
-
others,
|
|
62
|
-
} = selectInputBaseProps(props)
|
|
17
|
+
others: numberIncrementProps,
|
|
18
|
+
} = selectInputBaseProps({ ...NumberIncrement.defaultProps, ...props })
|
|
63
19
|
|
|
64
20
|
const {
|
|
65
|
-
|
|
66
|
-
variants = [],
|
|
67
|
-
style = {},
|
|
68
|
-
styles = {},
|
|
21
|
+
style,
|
|
69
22
|
value,
|
|
70
23
|
disabled,
|
|
71
24
|
onValueChange,
|
|
72
25
|
onChangeText,
|
|
73
|
-
max
|
|
74
|
-
min
|
|
75
|
-
step
|
|
76
|
-
editable
|
|
77
|
-
hasSeparator
|
|
78
|
-
format
|
|
79
|
-
mask
|
|
26
|
+
max,
|
|
27
|
+
min,
|
|
28
|
+
step,
|
|
29
|
+
editable,
|
|
30
|
+
hasSeparator,
|
|
31
|
+
format,
|
|
32
|
+
mask,
|
|
80
33
|
suffix,
|
|
81
|
-
separator
|
|
34
|
+
separator,
|
|
82
35
|
prefix,
|
|
83
36
|
validate,
|
|
84
37
|
_error,
|
|
85
|
-
formatter
|
|
38
|
+
formatter,
|
|
86
39
|
placeholder,
|
|
87
|
-
} =
|
|
40
|
+
} = numberIncrementProps
|
|
41
|
+
|
|
42
|
+
const styles = useStylesFor(NumberIncrement.styleRegistryName, style)
|
|
88
43
|
|
|
89
44
|
const [isFocused, setIsFocused] = useState(false)
|
|
90
45
|
|
|
@@ -110,16 +65,6 @@ export const NumberIncrement = (props: NumberIncrementProps) => {
|
|
|
110
65
|
return false
|
|
111
66
|
}, [value])
|
|
112
67
|
|
|
113
|
-
const variantStyles = useDefaultComponentStyle<'u:NumberIncrement', typeof NumberIncrementPresets>(
|
|
114
|
-
'u:NumberIncrement',
|
|
115
|
-
{
|
|
116
|
-
responsiveVariants,
|
|
117
|
-
variants,
|
|
118
|
-
styles,
|
|
119
|
-
rootElement: 'wrapper',
|
|
120
|
-
},
|
|
121
|
-
)
|
|
122
|
-
|
|
123
68
|
const onChange = (newValue: number) => {
|
|
124
69
|
if (onValueChange) onValueChange?.(newValue)
|
|
125
70
|
if (onChangeText) onChangeText?.(newValue)
|
|
@@ -143,19 +88,19 @@ export const NumberIncrement = (props: NumberIncrementProps) => {
|
|
|
143
88
|
|
|
144
89
|
const inputTextStyle = React.useMemo(() => {
|
|
145
90
|
return [
|
|
146
|
-
|
|
147
|
-
isFocused
|
|
148
|
-
hasError
|
|
149
|
-
disabled
|
|
150
|
-
]
|
|
91
|
+
styles.input,
|
|
92
|
+
isFocused ? styles['input:focus'] : null,
|
|
93
|
+
hasError ? styles['input:error'] : null,
|
|
94
|
+
disabled ? styles['input:disabled'] : null,
|
|
95
|
+
].filter(Boolean)
|
|
151
96
|
}, [disabled, isFocused, hasError])
|
|
152
97
|
|
|
153
98
|
const placeholderStyles = [
|
|
154
|
-
|
|
155
|
-
isFocused
|
|
156
|
-
hasError
|
|
157
|
-
disabled
|
|
158
|
-
]
|
|
99
|
+
styles.placeholder,
|
|
100
|
+
isFocused ? styles['placeholder:focus'] : null,
|
|
101
|
+
hasError ? styles['placeholder:error'] : null,
|
|
102
|
+
disabled ? styles['placeholder:disabled'] : null,
|
|
103
|
+
].filter(Boolean)
|
|
159
104
|
|
|
160
105
|
const handleBlur = React.useCallback(() => {
|
|
161
106
|
if (TypeGuards.isNumber(max) && (value >= max)) {
|
|
@@ -224,28 +169,27 @@ export const NumberIncrement = (props: NumberIncrementProps) => {
|
|
|
224
169
|
<InputBase
|
|
225
170
|
{...inputBaseProps}
|
|
226
171
|
error={hasError ? errorMessage : null}
|
|
227
|
-
|
|
228
|
-
...
|
|
229
|
-
innerWrapper:
|
|
230
|
-
|
|
231
|
-
editable
|
|
232
|
-
|
|
172
|
+
style={{
|
|
173
|
+
...styles,
|
|
174
|
+
innerWrapper: {
|
|
175
|
+
...styles.innerWrapper,
|
|
176
|
+
...(editable ? styles['innerWrapper:cursor'] : {}),
|
|
177
|
+
},
|
|
233
178
|
}}
|
|
234
179
|
rightIcon={{
|
|
235
|
-
name: 'plus' as
|
|
180
|
+
name: 'plus' as AppIcon,
|
|
236
181
|
disabled: disabled || incrementDisabled,
|
|
237
182
|
onPress: () => handleChange('increment'),
|
|
238
183
|
component: 'button',
|
|
239
184
|
...inputBaseProps.rightIcon,
|
|
240
185
|
}}
|
|
241
186
|
leftIcon={{
|
|
242
|
-
name: 'minus' as
|
|
187
|
+
name: 'minus' as AppIcon,
|
|
243
188
|
disabled: disabled || decrementDisabled,
|
|
244
189
|
onPress: () => handleChange('decrement'),
|
|
245
190
|
component: 'button',
|
|
246
191
|
...inputBaseProps.leftIcon,
|
|
247
192
|
}}
|
|
248
|
-
style={style}
|
|
249
193
|
disabled={disabled}
|
|
250
194
|
focused={isFocused}
|
|
251
195
|
innerWrapperProps={{
|
|
@@ -261,10 +205,13 @@ export const NumberIncrement = (props: NumberIncrementProps) => {
|
|
|
261
205
|
<Input
|
|
262
206
|
displayType='input'
|
|
263
207
|
css={[
|
|
208
|
+
// @ts-expect-error
|
|
264
209
|
...inputTextStyle,
|
|
210
|
+
// @ts-expect-error
|
|
265
211
|
{
|
|
266
212
|
'&::placeholder': placeholderStyles,
|
|
267
213
|
},
|
|
214
|
+
// @ts-expect-error
|
|
268
215
|
{
|
|
269
216
|
'&:focus': [
|
|
270
217
|
{
|
|
@@ -289,7 +236,29 @@ export const NumberIncrement = (props: NumberIncrementProps) => {
|
|
|
289
236
|
placeholder={placeholder}
|
|
290
237
|
getInputRef={innerInputRef}
|
|
291
238
|
/>
|
|
292
|
-
) : <Text text={String(value)}
|
|
239
|
+
) : <Text text={String(value)} style={inputTextStyle} />}
|
|
293
240
|
</InputBase>
|
|
294
241
|
)
|
|
295
242
|
}
|
|
243
|
+
|
|
244
|
+
NumberIncrement.styleRegistryName = 'NumberIncrement'
|
|
245
|
+
NumberIncrement.elements = [...InputBase.elements, 'input', 'placeholder']
|
|
246
|
+
NumberIncrement.rootElement = 'wrapper'
|
|
247
|
+
|
|
248
|
+
NumberIncrement.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
249
|
+
return NumberIncrement as (props: StyledComponentProps<NumberIncrementProps, typeof styles>) => IJSX
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
NumberIncrement.defaultProps = {
|
|
253
|
+
max: 1000000000,
|
|
254
|
+
min: 0,
|
|
255
|
+
step: 1,
|
|
256
|
+
editable: true,
|
|
257
|
+
hasSeparator: false,
|
|
258
|
+
mask: undefined,
|
|
259
|
+
separator: null,
|
|
260
|
+
format: null,
|
|
261
|
+
formatter: null,
|
|
262
|
+
} as Partial<NumberIncrementProps>
|
|
263
|
+
|
|
264
|
+
WebStyleRegistry.registerComponent(NumberIncrement)
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
1
|
import { InputBaseParts } from '../InputBase'
|
|
3
2
|
|
|
4
3
|
export type NumberIncrementParts = InputBaseParts | 'input' | 'placeholder'
|
|
@@ -9,7 +8,3 @@ export type NumberIncrementComposition =
|
|
|
9
8
|
| NumberIncrementParts
|
|
10
9
|
| `${NumberIncrementParts}:${NumberIncrementStates}`
|
|
11
10
|
| `innerWrapper:cursor`
|
|
12
|
-
|
|
13
|
-
const createNumberIncrementStyle = createDefaultVariantFactory<NumberIncrementComposition>()
|
|
14
|
-
|
|
15
|
-
export const NumberIncrementPresets = includePresets((styles) => createNumberIncrementStyle(() => ({ wrapper: styles })))
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { yup, FormTypes } from '@codeleap/common'
|
|
2
|
+
import { NumberIncrementComposition } from './styles'
|
|
3
|
+
import { InputBaseProps } from '../InputBase'
|
|
4
|
+
import { PatternFormatProps as PFProps, NumericFormatProps as NFProps } from 'react-number-format'
|
|
5
|
+
import { FormatInputValueFunction } from 'react-number-format/types/types'
|
|
6
|
+
import { StyledProp } from '@codeleap/styles'
|
|
7
|
+
|
|
8
|
+
export type NumberIncrementProps =
|
|
9
|
+
Pick<InputBaseProps, 'debugName' | 'disabled' | 'label'> &
|
|
10
|
+
{
|
|
11
|
+
value: number
|
|
12
|
+
onValueChange: (value: number) => void
|
|
13
|
+
onChangeText?: (value: number) => void
|
|
14
|
+
validate?: FormTypes.ValidatorWithoutForm<string> | yup.SchemaOf<string>
|
|
15
|
+
style?: StyledProp<NumberIncrementComposition>
|
|
16
|
+
max?: number
|
|
17
|
+
min?: number
|
|
18
|
+
step?: number
|
|
19
|
+
editable?: boolean
|
|
20
|
+
prefix?: NFProps['prefix']
|
|
21
|
+
suffix?: NFProps['suffix']
|
|
22
|
+
separator?: NFProps['thousandSeparator']
|
|
23
|
+
format?: PFProps['format']
|
|
24
|
+
mask?: PFProps['mask']
|
|
25
|
+
hasSeparator?: boolean
|
|
26
|
+
_error?: string
|
|
27
|
+
formatter?: FormatInputValueFunction
|
|
28
|
+
placeholder?: string
|
|
29
|
+
}
|
|
@@ -1,51 +1,53 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
StylesOf,
|
|
5
|
-
useDefaultComponentStyle,
|
|
6
|
-
} from '@codeleap/common'
|
|
7
|
-
import { Touchable, TouchableProps } from '../Touchable'
|
|
8
|
-
import { View, ViewProps } from '../View'
|
|
9
|
-
import { OverlayComposition, OverlayPresets } from './styles'
|
|
10
|
-
import { NativeHTMLElement } from '../../types'
|
|
2
|
+
import { Touchable } from '../Touchable'
|
|
3
|
+
import { View } from '../View'
|
|
11
4
|
import { usePopState } from '../../lib'
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
onPress?: TouchableProps<'div'>['onClick']
|
|
17
|
-
} & ComponentVariants<typeof OverlayPresets> & Omit<ViewProps<T>, 'variants' | 'responsiveVariants'>
|
|
5
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
6
|
+
import { OverlayProps } from './types'
|
|
7
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
8
|
+
import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
18
9
|
|
|
19
10
|
export * from './styles'
|
|
11
|
+
export * from './types'
|
|
20
12
|
|
|
21
|
-
export const Overlay =
|
|
22
|
-
const {
|
|
23
|
-
visible,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
...
|
|
28
|
-
|
|
13
|
+
export const Overlay = (overlayProps: OverlayProps) => {
|
|
14
|
+
const {
|
|
15
|
+
visible,
|
|
16
|
+
style,
|
|
17
|
+
...props
|
|
18
|
+
} = {
|
|
19
|
+
...Overlay.defaultProps,
|
|
20
|
+
...overlayProps,
|
|
21
|
+
}
|
|
29
22
|
|
|
30
|
-
const
|
|
31
|
-
variants,
|
|
32
|
-
responsiveVariants,
|
|
33
|
-
styles,
|
|
34
|
-
})
|
|
23
|
+
const styles = useStylesFor(Overlay.styleRegistryName, style)
|
|
35
24
|
|
|
36
|
-
usePopState(visible, props
|
|
25
|
+
usePopState(visible, props?.onPress)
|
|
37
26
|
|
|
38
|
-
const
|
|
27
|
+
const isPressable = !!props?.onClick || !!props?.onPress
|
|
28
|
+
const Component = isPressable ? Touchable : View
|
|
39
29
|
|
|
40
30
|
return (
|
|
41
|
-
// @ts-
|
|
31
|
+
// @ts-expect-error
|
|
42
32
|
<Component
|
|
43
|
-
|
|
33
|
+
{...props}
|
|
34
|
+
style={[
|
|
44
35
|
{ transition: 'opacity 0.2s ease' },
|
|
45
|
-
|
|
46
|
-
visible ?
|
|
36
|
+
styles.wrapper,
|
|
37
|
+
visible ? styles['wrapper:visible'] : null,
|
|
47
38
|
]}
|
|
48
|
-
{...props}
|
|
49
39
|
/>
|
|
50
40
|
)
|
|
51
41
|
}
|
|
42
|
+
|
|
43
|
+
Overlay.styleRegistryName = 'Overlay'
|
|
44
|
+
Overlay.elements = ['wrapper']
|
|
45
|
+
Overlay.rootElement = 'wrapper'
|
|
46
|
+
|
|
47
|
+
Overlay.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
48
|
+
return Overlay as (props: StyledComponentProps<OverlayProps, typeof styles>) => IJSX
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
Overlay.defaultProps = {} as Partial<OverlayProps>
|
|
52
|
+
|
|
53
|
+
WebStyleRegistry.registerComponent(Overlay)
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from "@codeleap/common";
|
|
2
|
-
import { ViewComposition } from "../View";
|
|
3
1
|
|
|
4
|
-
|
|
2
|
+
type OverlayState = 'visible'
|
|
5
3
|
|
|
6
|
-
|
|
4
|
+
type OverlayParts = 'wrapper'
|
|
7
5
|
|
|
8
|
-
export
|
|
6
|
+
export type OverlayComposition = OverlayParts | `${OverlayParts}:${OverlayState}`
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { StyledProp } from '@codeleap/styles'
|
|
2
|
+
import { ViewProps } from '../View'
|
|
3
|
+
import { OverlayComposition } from './styles'
|
|
4
|
+
import { AnyFunction } from '@codeleap/common'
|
|
5
|
+
|
|
6
|
+
export type OverlayProps =
|
|
7
|
+
Omit<ViewProps, 'style'> &
|
|
8
|
+
{
|
|
9
|
+
debugName: string
|
|
10
|
+
visible?: boolean
|
|
11
|
+
style?: StyledProp<OverlayComposition>
|
|
12
|
+
onPress?: AnyFunction
|
|
13
|
+
}
|
|
@@ -1,68 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from '
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
forwardRef,
|
|
11
|
-
useCallback,
|
|
12
|
-
useImperativeHandle,
|
|
13
|
-
useRef,
|
|
14
|
-
ReactNode,
|
|
15
|
-
ReactElement,
|
|
16
|
-
CSSProperties,
|
|
17
|
-
} from 'react'
|
|
1
|
+
import { onUpdate } from '@codeleap/common'
|
|
2
|
+
import Slider from 'react-slick'
|
|
3
|
+
import React, { forwardRef, useCallback, useImperativeHandle, useRef } from 'react'
|
|
4
|
+
import { View } from '../View'
|
|
5
|
+
import { Touchable } from '../Touchable'
|
|
6
|
+
import { DotsProps, PagerProps, PagerRef } from './types'
|
|
7
|
+
import { AnyRecord, IJSX, StyledComponentProps, StyledComponentWithProps } from '@codeleap/styles'
|
|
8
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
9
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
18
10
|
|
|
19
11
|
import 'slick-carousel/slick/slick.css'
|
|
20
12
|
import 'slick-carousel/slick/slick-theme.css'
|
|
21
|
-
import { View, ViewProps } from '../View'
|
|
22
|
-
import { Touchable } from '../Touchable'
|
|
23
|
-
import { ComponentCommonProps } from '../../types'
|
|
24
13
|
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
}
|
|
14
|
+
export * from './styles'
|
|
15
|
+
export * from './types'
|
|
28
16
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
styles?: StylesOf<PagerComposition>
|
|
32
|
-
page?: number
|
|
33
|
-
style?: CSSProperties
|
|
34
|
-
children: ReactNode
|
|
35
|
-
onChange?: (page: number) => void
|
|
36
|
-
renderPageWrapper?: React.FC
|
|
37
|
-
footer?: ReactElement
|
|
38
|
-
dotsProps?: DotsProps
|
|
39
|
-
pageWrapperProps?: ViewProps<'div'>
|
|
40
|
-
dotsDisabled?:boolean
|
|
41
|
-
disableSwipe?: boolean
|
|
42
|
-
} & ComponentCommonProps
|
|
43
|
-
|
|
44
|
-
type DotsProps = Pick<PagerProps, 'page' | 'dotsDisabled'> & {
|
|
45
|
-
childArray: ReactNode[]
|
|
46
|
-
onPress?: (index: number) => void
|
|
47
|
-
variantStyles: StylesOf<PagerComposition>
|
|
48
|
-
}
|
|
17
|
+
const Dots = (params: DotsProps) => {
|
|
18
|
+
const { page, childArray, onPress, styles, dotsDisabled } = params
|
|
49
19
|
|
|
50
|
-
const Dots = ({ page, childArray, onPress, variantStyles, dotsDisabled }: DotsProps) => {
|
|
51
20
|
return (
|
|
52
|
-
<View style={
|
|
21
|
+
<View style={styles.dots}>
|
|
53
22
|
{childArray.map((_, index) => {
|
|
54
23
|
const isSelected = index === page
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
24
|
+
|
|
25
|
+
const style = [
|
|
26
|
+
styles.dot,
|
|
27
|
+
isSelected && styles['dot:selected'],
|
|
28
|
+
dotsDisabled && styles['dot:disabled'],
|
|
58
29
|
]
|
|
59
30
|
|
|
60
31
|
return (
|
|
61
32
|
<Touchable
|
|
62
33
|
key={index}
|
|
63
34
|
onPress={() => onPress?.(index)}
|
|
64
|
-
|
|
35
|
+
style={style}
|
|
65
36
|
disabled={dotsDisabled}
|
|
37
|
+
debugName='dots'
|
|
66
38
|
/>
|
|
67
39
|
)
|
|
68
40
|
})}
|
|
@@ -70,42 +42,31 @@ const Dots = ({ page, childArray, onPress, variantStyles, dotsDisabled }: DotsPr
|
|
|
70
42
|
)
|
|
71
43
|
}
|
|
72
44
|
|
|
73
|
-
const
|
|
74
|
-
props: PagerProps,
|
|
75
|
-
ref: React.ForwardedRef<PagerRef>,
|
|
76
|
-
) => {
|
|
45
|
+
export const Pager = forwardRef<PagerRef, PagerProps>((props, ref) => {
|
|
77
46
|
const sliderRef = useRef<Slider>()
|
|
47
|
+
|
|
78
48
|
const {
|
|
79
|
-
styles,
|
|
80
49
|
style,
|
|
81
|
-
variants,
|
|
82
50
|
children,
|
|
83
|
-
renderPageWrapper,
|
|
84
|
-
responsiveVariants,
|
|
51
|
+
renderPageWrapper: PageWrapper,
|
|
85
52
|
page,
|
|
86
|
-
dots
|
|
87
|
-
dotsDisabled
|
|
88
|
-
infinite
|
|
89
|
-
disableSwipe
|
|
53
|
+
dots,
|
|
54
|
+
dotsDisabled,
|
|
55
|
+
infinite,
|
|
56
|
+
disableSwipe,
|
|
90
57
|
onChange,
|
|
91
58
|
footer,
|
|
92
59
|
dotsProps,
|
|
93
60
|
pageWrapperProps,
|
|
94
61
|
...rest
|
|
95
|
-
} =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
variants,
|
|
102
|
-
responsiveVariants,
|
|
103
|
-
styles,
|
|
104
|
-
rootElement: 'wrapper',
|
|
105
|
-
})
|
|
62
|
+
} = {
|
|
63
|
+
...Pager.defaultProps,
|
|
64
|
+
...props,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const styles = useStylesFor(Pager.styleRegistryName, style)
|
|
106
68
|
|
|
107
69
|
const childArray = React.Children.toArray(children)
|
|
108
|
-
const PageWrapper = renderPageWrapper || View
|
|
109
70
|
|
|
110
71
|
const goTo = useCallback(
|
|
111
72
|
(page: number) => {
|
|
@@ -124,7 +85,7 @@ const PagerComponent = (
|
|
|
124
85
|
}, [page])
|
|
125
86
|
|
|
126
87
|
return (
|
|
127
|
-
<View
|
|
88
|
+
<View style={styles.wrapper}>
|
|
128
89
|
<Slider
|
|
129
90
|
adaptiveHeight={true}
|
|
130
91
|
{...rest}
|
|
@@ -138,9 +99,10 @@ const PagerComponent = (
|
|
|
138
99
|
>
|
|
139
100
|
{childArray.map((child, index) => {
|
|
140
101
|
return (
|
|
102
|
+
// @ts-expect-error @verify
|
|
141
103
|
<PageWrapper
|
|
142
104
|
key={index}
|
|
143
|
-
|
|
105
|
+
style={styles.pageWrapper}
|
|
144
106
|
{...pageWrapperProps}
|
|
145
107
|
>
|
|
146
108
|
{child}
|
|
@@ -149,24 +111,46 @@ const PagerComponent = (
|
|
|
149
111
|
})}
|
|
150
112
|
</Slider>
|
|
151
113
|
|
|
152
|
-
<View
|
|
114
|
+
<View style={styles.footerWrapper}>
|
|
153
115
|
{footer}
|
|
154
116
|
|
|
155
|
-
{dots
|
|
117
|
+
{dots ? (
|
|
156
118
|
<Dots
|
|
157
119
|
page={page}
|
|
158
120
|
onPress={onChange}
|
|
159
121
|
childArray={childArray}
|
|
160
|
-
|
|
122
|
+
styles={styles}
|
|
161
123
|
dotsDisabled={dotsDisabled}
|
|
162
124
|
{...dotsProps}
|
|
163
125
|
/>
|
|
164
|
-
)}
|
|
126
|
+
) : null}
|
|
165
127
|
</View>
|
|
166
128
|
</View>
|
|
167
129
|
)
|
|
130
|
+
}) as StyledComponentWithProps<PagerProps>
|
|
131
|
+
|
|
132
|
+
Pager.styleRegistryName = 'Pager'
|
|
133
|
+
|
|
134
|
+
Pager.elements = [
|
|
135
|
+
'wrapper',
|
|
136
|
+
'dot',
|
|
137
|
+
'dots',
|
|
138
|
+
'pageWrapper',
|
|
139
|
+
'footerWrapper',
|
|
140
|
+
]
|
|
141
|
+
|
|
142
|
+
Pager.rootElement = 'wrapper'
|
|
143
|
+
|
|
144
|
+
Pager.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
145
|
+
return Pager as (props: StyledComponentProps<PagerProps, typeof styles>) => IJSX
|
|
168
146
|
}
|
|
169
147
|
|
|
170
|
-
|
|
148
|
+
Pager.defaultProps = {
|
|
149
|
+
dots: false,
|
|
150
|
+
dotsDisabled: false,
|
|
151
|
+
infinite: false,
|
|
152
|
+
disableSwipe: false,
|
|
153
|
+
renderPageWrapper: View,
|
|
154
|
+
} as Partial<PagerProps>
|
|
171
155
|
|
|
172
|
-
|
|
156
|
+
WebStyleRegistry.registerComponent(Pager)
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
type Dots = 'dot' | 'dot:selected' | 'dot:disabled' | 'dots'
|
|
2
3
|
|
|
3
4
|
export type PagerComposition =
|
|
4
5
|
| 'wrapper'
|
|
5
|
-
| 'dot'
|
|
6
|
-
| 'dot:selected'
|
|
7
|
-
| 'dots'
|
|
8
6
|
| 'pageWrapper'
|
|
9
7
|
| 'footerWrapper'
|
|
10
|
-
|
|
11
|
-
const createPagerStyle = createDefaultVariantFactory<PagerComposition>()
|
|
12
|
-
|
|
13
|
-
export const PagerPresets = includePresets((styles) => createPagerStyle(() => ({ wrapper: styles })),
|
|
14
|
-
)
|
|
8
|
+
| Dots
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { StylesOf } from '@codeleap/common'
|
|
2
|
+
import { Settings } from 'react-slick'
|
|
3
|
+
import { PagerComposition } from './styles'
|
|
4
|
+
import React, { ReactNode, ReactElement } from 'react'
|
|
5
|
+
import { ViewProps } from '../View'
|
|
6
|
+
import { ComponentCommonProps } from '../../types'
|
|
7
|
+
import { StyledProp } from '@codeleap/styles'
|
|
8
|
+
|
|
9
|
+
export type PagerRef = {
|
|
10
|
+
goTo: (page: number) => void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type PagerProps =
|
|
14
|
+
Omit<Settings, 'style'> &
|
|
15
|
+
ComponentCommonProps &
|
|
16
|
+
{
|
|
17
|
+
style?: StyledProp<PagerComposition>
|
|
18
|
+
page?: number
|
|
19
|
+
children: ReactNode
|
|
20
|
+
onChange?: (page: number) => void
|
|
21
|
+
renderPageWrapper?: React.FC
|
|
22
|
+
footer?: ReactElement
|
|
23
|
+
dotsProps?: DotsProps
|
|
24
|
+
pageWrapperProps?: ViewProps
|
|
25
|
+
dotsDisabled?: boolean
|
|
26
|
+
disableSwipe?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type DotsProps =
|
|
30
|
+
Pick<PagerProps, 'page' | 'dotsDisabled'> &
|
|
31
|
+
{
|
|
32
|
+
childArray: ReactNode[]
|
|
33
|
+
onPress?: (index: number) => void
|
|
34
|
+
styles: StylesOf<PagerComposition>
|
|
35
|
+
}
|