@codeleap/mobile 3.24.2 → 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 +6 -4
- package/src/Registry.ts +52 -0
- package/src/components/ActionIcon/index.tsx +55 -37
- package/src/components/ActionIcon/styles.ts +2 -4
- package/src/components/ActionIcon/types.ts +15 -0
- package/src/components/ActivityIndicator/index.tsx +42 -64
- package/src/components/ActivityIndicator/styles.ts +1 -10
- package/src/components/ActivityIndicator/types.ts +9 -0
- package/src/components/Autocomplete/index.tsx +46 -54
- package/src/components/Autocomplete/styles.ts +2 -5
- package/src/components/Autocomplete/types.ts +13 -23
- package/src/components/Avatar/index.tsx +59 -71
- package/src/components/Avatar/styles.ts +1 -9
- package/src/components/Avatar/types.ts +23 -0
- package/src/components/AvatarGroup/index.tsx +30 -44
- package/src/components/AvatarGroup/styles.ts +0 -6
- package/src/components/AvatarGroup/types.ts +10 -0
- package/src/components/Backdrop/index.tsx +51 -34
- package/src/components/Backdrop/styles.ts +5 -10
- package/src/components/Backdrop/types.ts +14 -0
- package/src/components/Badge/index.tsx +36 -62
- package/src/components/Badge/styles.ts +3 -11
- package/src/components/Badge/types.ts +27 -0
- package/src/components/Button/index.tsx +55 -82
- package/src/components/Button/styles.ts +13 -14
- package/src/components/Button/types.ts +20 -0
- package/src/components/Calendar/index.tsx +35 -29
- package/src/components/Checkbox/index.tsx +43 -64
- package/src/components/Checkbox/styles.ts +1 -6
- package/src/components/Checkbox/types.ts +13 -0
- package/src/components/DatePickerModal/index.tsx +50 -65
- package/src/components/DatePickerModal/styles.ts +9 -10
- package/src/components/DatePickerModal/types.ts +36 -54
- package/src/components/EmptyPlaceholder/index.tsx +40 -63
- package/src/components/EmptyPlaceholder/styles.ts +0 -5
- package/src/components/EmptyPlaceholder/types.ts +21 -0
- package/src/components/FileInput/index.tsx +11 -49
- package/src/components/FileInput/types.ts +27 -0
- package/src/components/Grid/index.tsx +84 -116
- package/src/components/Grid/styles.ts +0 -5
- package/src/components/Grid/types.ts +20 -0
- package/src/components/Icon/index.tsx +44 -79
- package/src/components/Icon/styles.ts +0 -6
- package/src/components/Icon/types.ts +15 -0
- package/src/components/Image/index.tsx +58 -78
- package/src/components/Image/styles.ts +1 -6
- package/src/components/Image/types.ts +18 -0
- package/src/components/ImageView/Spotlight.tsx +1 -4
- package/src/components/ImageView/component.tsx +1 -2
- package/src/components/InputBase/index.tsx +33 -24
- package/src/components/InputBase/styles.ts +66 -75
- package/src/components/InputBase/types.ts +3 -4
- package/src/components/InputBase/utils.ts +6 -4
- package/src/components/List/index.tsx +99 -151
- package/src/components/List/styles.ts +0 -6
- package/src/components/List/types.ts +41 -0
- package/src/components/LoadingOverlay/index.tsx +42 -29
- package/src/components/LoadingOverlay/styles.ts +7 -7
- package/src/components/LoadingOverlay/types.ts +9 -0
- package/src/components/Modal/index.tsx +80 -127
- package/src/components/Modal/styles.ts +0 -8
- package/src/components/Modal/types.ts +41 -0
- package/src/components/Navigation/Navigation.tsx +1 -0
- package/src/components/Navigation/types.ts +2 -9
- package/src/components/NumberIncrement/index.tsx +50 -60
- package/src/components/NumberIncrement/styles.ts +0 -5
- package/src/components/NumberIncrement/types.ts +32 -39
- package/src/components/Pager/index.tsx +42 -94
- package/src/components/Pager/styles.ts +1 -13
- package/src/components/Pager/types.ts +37 -0
- package/src/components/PaginationIndicator/index.tsx +51 -0
- package/src/components/PaginationIndicator/styles.ts +3 -0
- package/src/components/PaginationIndicator/types.ts +10 -0
- package/src/components/RadioInput/index.tsx +32 -57
- package/src/components/RadioInput/styles.ts +5 -7
- package/src/components/RadioInput/types.ts +31 -0
- package/src/components/RefreshControl/index.tsx +39 -19
- package/src/components/RefreshControl/styles.ts +1 -6
- package/src/components/RefreshControl/types.ts +9 -0
- package/src/components/Scroll/index.tsx +89 -105
- package/src/components/Scroll/styles.ts +0 -5
- package/src/components/Scroll/types.ts +21 -0
- package/src/components/SearchInput/index.tsx +90 -0
- package/src/components/Sections/index.tsx +111 -161
- package/src/components/Sections/styles.ts +0 -5
- package/src/components/Sections/types.ts +39 -0
- package/src/components/SegmentedControl/Option.tsx +46 -31
- package/src/components/SegmentedControl/index.tsx +86 -121
- package/src/components/SegmentedControl/styles.ts +15 -22
- package/src/components/SegmentedControl/types.ts +31 -0
- package/src/components/Select/index.tsx +71 -82
- package/src/components/Select/styles.ts +3 -5
- package/src/components/Select/types.ts +20 -25
- package/src/components/Slider/index.tsx +58 -43
- package/src/components/Slider/styles.ts +15 -6
- package/src/components/Slider/types.ts +9 -14
- package/src/components/Switch/index.tsx +43 -56
- package/src/components/Switch/styles.ts +1 -7
- package/src/components/Switch/types.ts +12 -0
- package/src/components/Text/index.tsx +56 -52
- package/src/components/Text/styles.ts +1 -7
- package/src/components/Text/types.ts +18 -0
- package/src/components/TextInput/index.tsx +49 -162
- package/src/components/TextInput/styles.ts +2 -8
- package/src/components/TextInput/types.ts +23 -0
- package/src/components/Touchable/index.tsx +44 -87
- package/src/components/Touchable/styles.ts +0 -9
- package/src/components/Touchable/types.ts +27 -0
- package/src/components/View/index.tsx +23 -92
- package/src/components/View/styles.ts +0 -6
- package/src/components/View/types.ts +13 -0
- package/src/components/components.ts +2 -6
- package/src/hooks/index.ts +13 -0
- package/src/index.ts +2 -0
- package/src/modules/PressableRipple/type.ts +1 -0
- package/src/utils/KeyboardAware/context.tsx +0 -2
- package/src/utils/KeyboardAware/keyboardHooks.ts +1 -2
- package/src/utils/ModalManager/components.tsx +1 -30
- package/src/utils/ModalManager/context.tsx +4 -4
- package/src/utils/ModalManager/index.ts +1 -4
- package/src/utils/hooks.ts +12 -1
- package/src/components/Calendar/style.ts +0 -6
- package/src/components/ContentView/index.tsx +0 -63
- package/src/components/ContentView/styles.ts +0 -8
- package/src/components/Drawer/index.tsx +0 -28
- package/src/components/Drawer/styles.ts +0 -8
- package/src/components/FileInput/styles.ts +0 -8
- package/src/components/InputLabel/index.tsx +0 -38
- package/src/components/InputLabel/styles.ts +0 -7
- package/src/components/List/PaginationIndicator.tsx +0 -54
- package/src/components/defaultStyles.ts +0 -77
|
@@ -1,86 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
useDefaultComponentStyle,
|
|
7
|
-
useWarning,
|
|
8
|
-
} from '@codeleap/common'
|
|
9
|
-
import React, { ReactNode, useCallback, useRef } from 'react'
|
|
10
|
-
import {
|
|
11
|
-
Dimensions,
|
|
12
|
-
NativeScrollEvent,
|
|
13
|
-
NativeSyntheticEvent,
|
|
14
|
-
ScrollView,
|
|
15
|
-
ScrollViewProps,
|
|
16
|
-
StyleSheet,
|
|
17
|
-
} from 'react-native'
|
|
18
|
-
import { StylesOf } from '../../types/utility'
|
|
1
|
+
import React, { useCallback, useRef } from 'react'
|
|
2
|
+
import { onUpdate, TypeGuards } from '@codeleap/common'
|
|
3
|
+
import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
4
|
+
import { Dimensions, ScrollView } from 'react-native'
|
|
5
|
+
import { MobileStyleRegistry } from '../../Registry'
|
|
19
6
|
import { View } from '../View'
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export type PageProps = {
|
|
24
|
-
isLast: boolean
|
|
25
|
-
isFirst: boolean
|
|
26
|
-
isActive: boolean
|
|
27
|
-
isNext: boolean
|
|
28
|
-
page: number
|
|
29
|
-
index: number
|
|
30
|
-
isPrevious: boolean
|
|
31
|
-
}
|
|
7
|
+
import { PageProps, PagerProps, ScrollEvent } from './types'
|
|
8
|
+
import { useStylesFor } from '../../hooks'
|
|
32
9
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export type PagerProps = React.PropsWithChildren<{
|
|
36
|
-
variants?: ComponentVariants<typeof PagerPresets>['variants']
|
|
37
|
-
styles?: StylesOf<PagerComposition>
|
|
38
|
-
children?: (((pageData: PageProps) => ReactNode) | ReactNode)[]
|
|
39
|
-
page?: number
|
|
40
|
-
style?: any
|
|
41
|
-
setPage?: (page: number) => void
|
|
42
|
-
returnEarly?: boolean
|
|
43
|
-
renderPageWrapper?: React.FC<PageProps>
|
|
44
|
-
pageWrapperProps?: any
|
|
45
|
-
width?: number
|
|
46
|
-
onScroll?: (event: ScrollEvent, args: { isLeft?: boolean; isRight?: boolean; x?: number }) => void
|
|
47
|
-
/** If TRUE render page, nextPage and prevPage only */
|
|
48
|
-
windowing?: boolean
|
|
49
|
-
scrollRightEnabled?: boolean
|
|
50
|
-
scrollLeftEnabled?: boolean
|
|
51
|
-
scrollDirectionThrottle?: number
|
|
52
|
-
onSwipeLastPage?: (event: ScrollEvent) => void
|
|
53
|
-
waitEventDispatchTimeout?: number
|
|
54
|
-
} & ScrollViewProps>
|
|
55
|
-
|
|
56
|
-
const defaultProps: Partial<PagerProps> = {
|
|
57
|
-
variants: [],
|
|
58
|
-
styles: {},
|
|
59
|
-
page: 0,
|
|
60
|
-
returnEarly: true,
|
|
61
|
-
windowing: false,
|
|
62
|
-
keyboardShouldPersistTaps: 'handled',
|
|
63
|
-
scrollEnabled: true,
|
|
64
|
-
scrollRightEnabled: true,
|
|
65
|
-
scrollLeftEnabled: true,
|
|
66
|
-
scrollDirectionThrottle: 650,
|
|
67
|
-
waitEventDispatchTimeout: 250,
|
|
68
|
-
}
|
|
10
|
+
export * from './styles'
|
|
11
|
+
export * from './types'
|
|
69
12
|
|
|
70
13
|
export const Pager = (pagerProps: PagerProps) => {
|
|
71
14
|
const {
|
|
72
|
-
styles,
|
|
73
|
-
variants,
|
|
74
15
|
width: widthProp,
|
|
75
16
|
page,
|
|
76
|
-
style
|
|
77
|
-
returnEarly
|
|
17
|
+
style,
|
|
18
|
+
returnEarly,
|
|
78
19
|
renderPageWrapper,
|
|
79
20
|
pageWrapperProps = {},
|
|
80
21
|
children,
|
|
81
|
-
windowing
|
|
22
|
+
windowing,
|
|
82
23
|
setPage,
|
|
83
|
-
scrollEnabled
|
|
24
|
+
scrollEnabled,
|
|
84
25
|
scrollLeftEnabled,
|
|
85
26
|
scrollRightEnabled,
|
|
86
27
|
onScroll,
|
|
@@ -88,7 +29,7 @@ export const Pager = (pagerProps: PagerProps) => {
|
|
|
88
29
|
onSwipeLastPage,
|
|
89
30
|
waitEventDispatchTimeout,
|
|
90
31
|
} = {
|
|
91
|
-
...defaultProps,
|
|
32
|
+
...Pager.defaultProps,
|
|
92
33
|
...pagerProps,
|
|
93
34
|
}
|
|
94
35
|
|
|
@@ -97,20 +38,14 @@ export const Pager = (pagerProps: PagerProps) => {
|
|
|
97
38
|
const [positionX, setPositionX] = React.useState(0)
|
|
98
39
|
const [scrollPositionX, setScrollPositionX] = React.useState(0)
|
|
99
40
|
const [_scrollEnabled, setScrollEnabled] = React.useState(true)
|
|
100
|
-
|
|
101
41
|
const waitEventDispatch = useRef(false)
|
|
102
42
|
|
|
103
|
-
const
|
|
104
|
-
'u:Pager',
|
|
105
|
-
{
|
|
106
|
-
styles,
|
|
107
|
-
transform: StyleSheet.flatten,
|
|
108
|
-
variants,
|
|
109
|
-
},
|
|
110
|
-
)
|
|
43
|
+
const styles = useStylesFor(Pager.styleRegistryName, style)
|
|
111
44
|
|
|
112
45
|
const windowWidth = Dimensions.get('window').width
|
|
113
|
-
|
|
46
|
+
|
|
47
|
+
// @ts-expect-error
|
|
48
|
+
let width = widthProp ?? styles?.wrapper?.width
|
|
114
49
|
|
|
115
50
|
const validWidth = TypeGuards.isNumber(width)
|
|
116
51
|
|
|
@@ -118,12 +53,6 @@ export const Pager = (pagerProps: PagerProps) => {
|
|
|
118
53
|
width = windowWidth
|
|
119
54
|
}
|
|
120
55
|
|
|
121
|
-
useWarning(
|
|
122
|
-
!validWidth,
|
|
123
|
-
'Pager',
|
|
124
|
-
'provided width is not a number, using default width',
|
|
125
|
-
)
|
|
126
|
-
|
|
127
56
|
const nChildren = React.Children.count(children)
|
|
128
57
|
|
|
129
58
|
const lastPage = nChildren - 1
|
|
@@ -134,7 +63,7 @@ export const Pager = (pagerProps: PagerProps) => {
|
|
|
134
63
|
|
|
135
64
|
const handleScrollEnd = useCallback((event: ScrollEvent) => {
|
|
136
65
|
if (!scrollEnabled) return null
|
|
137
|
-
|
|
66
|
+
|
|
138
67
|
if (waitEventDispatch.current === true) return null
|
|
139
68
|
|
|
140
69
|
waitEventDispatch.current = true
|
|
@@ -213,13 +142,12 @@ export const Pager = (pagerProps: PagerProps) => {
|
|
|
213
142
|
onMomentumScrollEnd={handleScrollEnd}
|
|
214
143
|
scrollEventThrottle={hasScrollDirectionDisabled ? 2000 : 300}
|
|
215
144
|
showsHorizontalScrollIndicator={false}
|
|
216
|
-
style={[variantStyles.wrapper, style]}
|
|
217
145
|
{...pagerProps}
|
|
146
|
+
style={styles?.wrapper}
|
|
218
147
|
onScroll={handleScroll}
|
|
219
148
|
scrollEnabled={childArr.length > 1 && scrollEnabled && _scrollEnabled}
|
|
220
149
|
>
|
|
221
150
|
{childArr.map((child: PagerProps['children'][number], index) => {
|
|
222
|
-
|
|
223
151
|
const isActive = index === page
|
|
224
152
|
const isLast = index === lastPage
|
|
225
153
|
const isFirst = index === 0
|
|
@@ -246,8 +174,8 @@ export const Pager = (pagerProps: PagerProps) => {
|
|
|
246
174
|
|
|
247
175
|
const wrapperProps = {
|
|
248
176
|
key: index,
|
|
249
|
-
style: [{ height: '100%', width }, variantStyles.page],
|
|
250
177
|
...pageWrapperProps,
|
|
178
|
+
style: [{ height: '100%', width }, styles?.page],
|
|
251
179
|
}
|
|
252
180
|
|
|
253
181
|
return <WrapperComponent {...wrapperProps}>{content}</WrapperComponent>
|
|
@@ -256,4 +184,24 @@ export const Pager = (pagerProps: PagerProps) => {
|
|
|
256
184
|
)
|
|
257
185
|
}
|
|
258
186
|
|
|
259
|
-
Pager.
|
|
187
|
+
Pager.styleRegistryName = 'Pager'
|
|
188
|
+
Pager.elements = ['page', 'wrapper']
|
|
189
|
+
Pager.rootElement = 'wrapper'
|
|
190
|
+
|
|
191
|
+
Pager.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
192
|
+
return Pager as (props: StyledComponentProps<PagerProps, typeof styles>) => IJSX
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
Pager.defaultProps = {
|
|
196
|
+
page: 0,
|
|
197
|
+
returnEarly: true,
|
|
198
|
+
windowing: false,
|
|
199
|
+
keyboardShouldPersistTaps: 'handled',
|
|
200
|
+
scrollEnabled: true,
|
|
201
|
+
scrollRightEnabled: true,
|
|
202
|
+
scrollLeftEnabled: true,
|
|
203
|
+
scrollDirectionThrottle: 650,
|
|
204
|
+
waitEventDispatchTimeout: 250,
|
|
205
|
+
} as Partial<PagerProps>
|
|
206
|
+
|
|
207
|
+
MobileStyleRegistry.registerComponent(Pager)
|
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createDefaultVariantFactory,
|
|
3
|
-
includePresets,
|
|
4
|
-
} from '@codeleap/common'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export type PagerComposition =
|
|
8
|
-
| 'page'
|
|
9
|
-
| 'wrapper'
|
|
10
|
-
|
|
11
|
-
const createPagerStyle = createDefaultVariantFactory<PagerComposition>()
|
|
12
|
-
|
|
13
|
-
export const PagerPresets = includePresets((style) => createPagerStyle(() => ({ wrapper: style })))
|
|
14
1
|
|
|
2
|
+
export type PagerComposition = 'page' | 'wrapper'
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { StyledProp } from '@codeleap/styles'
|
|
2
|
+
import { ReactNode } from 'react'
|
|
3
|
+
import { NativeScrollEvent, NativeSyntheticEvent, ScrollViewProps } from 'react-native'
|
|
4
|
+
import { PagerComposition } from './styles'
|
|
5
|
+
|
|
6
|
+
export type PageProps = {
|
|
7
|
+
isLast: boolean
|
|
8
|
+
isFirst: boolean
|
|
9
|
+
isActive: boolean
|
|
10
|
+
isNext: boolean
|
|
11
|
+
page: number
|
|
12
|
+
index: number
|
|
13
|
+
isPrevious: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type ScrollEvent = NativeSyntheticEvent<NativeScrollEvent>
|
|
17
|
+
|
|
18
|
+
export type PagerProps =
|
|
19
|
+
Omit<ScrollViewProps, 'style'> &
|
|
20
|
+
{
|
|
21
|
+
children?: (((pageData: PageProps) => ReactNode) | ReactNode)[]
|
|
22
|
+
page?: number
|
|
23
|
+
setPage?: (page: number) => void
|
|
24
|
+
returnEarly?: boolean
|
|
25
|
+
renderPageWrapper?: React.FC<PageProps>
|
|
26
|
+
pageWrapperProps?: any
|
|
27
|
+
width?: number
|
|
28
|
+
onScroll?: (event: ScrollEvent, args: { isLeft?: boolean; isRight?: boolean; x?: number }) => void
|
|
29
|
+
/** If TRUE render page, nextPage and prevPage only */
|
|
30
|
+
windowing?: boolean
|
|
31
|
+
scrollRightEnabled?: boolean
|
|
32
|
+
scrollLeftEnabled?: boolean
|
|
33
|
+
scrollDirectionThrottle?: number
|
|
34
|
+
onSwipeLastPage?: (event: ScrollEvent) => void
|
|
35
|
+
waitEventDispatchTimeout?: number
|
|
36
|
+
style?: StyledProp<PagerComposition>
|
|
37
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { TypeGuards } from '@codeleap/common'
|
|
3
|
+
import { ActivityIndicator } from '../ActivityIndicator'
|
|
4
|
+
import { Text } from '../Text'
|
|
5
|
+
import { AnyRecord, useNestedStylesByKey, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
6
|
+
import { MobileStyleRegistry } from '../../Registry'
|
|
7
|
+
import { useStylesFor } from '../../hooks'
|
|
8
|
+
import { PaginationIndicatorProps } from './types'
|
|
9
|
+
|
|
10
|
+
export const PaginationIndicator = (props: PaginationIndicatorProps) => {
|
|
11
|
+
const {
|
|
12
|
+
hasMore,
|
|
13
|
+
isFetching,
|
|
14
|
+
noMoreItemsText,
|
|
15
|
+
style,
|
|
16
|
+
activityIndicator,
|
|
17
|
+
} = {
|
|
18
|
+
...PaginationIndicator.defaultProps,
|
|
19
|
+
...props,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const styles = useStylesFor(PaginationIndicator.styleRegistryName, style)
|
|
23
|
+
|
|
24
|
+
const loaderStyles = useNestedStylesByKey('loader', styles)
|
|
25
|
+
|
|
26
|
+
if (isFetching) {
|
|
27
|
+
return activityIndicator || <ActivityIndicator style={loaderStyles} />
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!hasMore) {
|
|
31
|
+
if (TypeGuards.isString(noMoreItemsText) || TypeGuards.isNumber(noMoreItemsText)) {
|
|
32
|
+
return <Text style={styles.text} text={noMoreItemsText.toString()} />
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return noMoreItemsText
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
PaginationIndicator.styleRegistryName = 'PaginationIndicator'
|
|
42
|
+
PaginationIndicator.elements = ['text', 'loader']
|
|
43
|
+
PaginationIndicator.rootElement = 'text'
|
|
44
|
+
|
|
45
|
+
PaginationIndicator.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
46
|
+
return PaginationIndicator as (props: StyledComponentProps<PaginationIndicatorProps, typeof styles>) => IJSX
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
PaginationIndicator.defaultProps = {} as PaginationIndicatorProps
|
|
50
|
+
|
|
51
|
+
MobileStyleRegistry.registerComponent(PaginationIndicator)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { StyledProp } from '@codeleap/styles'
|
|
2
|
+
import { PaginationIndicatorComposition } from './styles'
|
|
3
|
+
|
|
4
|
+
export type PaginationIndicatorProps = {
|
|
5
|
+
isFetching?: boolean
|
|
6
|
+
noMoreItemsText: JSX.Element | string | number
|
|
7
|
+
hasMore?: boolean
|
|
8
|
+
activityIndicator?: JSX.Element
|
|
9
|
+
style?: StyledProp<PaginationIndicatorComposition>
|
|
10
|
+
}
|
|
@@ -1,50 +1,18 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { ReactNode, ComponentPropsWithoutRef } from 'react'
|
|
3
|
-
|
|
4
2
|
import { Text } from '../Text'
|
|
5
3
|
import { Touchable } from '../Touchable'
|
|
6
|
-
import {
|
|
7
|
-
ComponentVariants,
|
|
8
|
-
FormTypes,
|
|
9
|
-
getNestedStylesByKey,
|
|
10
|
-
StylesOf,
|
|
11
|
-
TypeGuards,
|
|
12
|
-
useDefaultComponentStyle,
|
|
13
|
-
} from '@codeleap/common'
|
|
4
|
+
import { TypeGuards } from '@codeleap/common'
|
|
14
5
|
import { View } from '../View'
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
type WrapperProps = InputBaseProps
|
|
6
|
+
import { InputBase, selectInputBaseProps } from '../InputBase'
|
|
7
|
+
import { RadioGroupProps, RadioOptionProps } from './types'
|
|
8
|
+
import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
9
|
+
import { MobileStyleRegistry } from '../../Registry'
|
|
10
|
+
import { useStylesFor } from '../../hooks'
|
|
22
11
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
export type RadioGroupProps<T extends string|number> = WrapperProps & {
|
|
27
|
-
options: RadioOption<T>[]
|
|
28
|
-
value: T
|
|
29
|
-
onValueChange(value: T): void
|
|
30
|
-
label: ReactNode
|
|
31
|
-
styles?: StylesOf<RadioInputComposition>
|
|
32
|
-
variants?: ComponentVariants<typeof RadioInputPresets>['variants']
|
|
33
|
-
radioOnRight?: boolean
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
type OptionProps<T extends string|number> = {
|
|
37
|
-
item: RadioOption<T>
|
|
38
|
-
selected: boolean
|
|
39
|
-
onSelect(): void
|
|
40
|
-
styles?: StylesOf<RadioInputComposition>
|
|
41
|
-
debugName?: string
|
|
42
|
-
disabled?: boolean
|
|
43
|
-
separator?: boolean
|
|
44
|
-
reverseOrder?: boolean
|
|
45
|
-
}
|
|
12
|
+
export * from './styles'
|
|
13
|
+
export * from './types'
|
|
46
14
|
|
|
47
|
-
const Option = <T extends string|number>(props:
|
|
15
|
+
const Option = <T extends string | number>(props: RadioOptionProps<T>) => {
|
|
48
16
|
const {
|
|
49
17
|
debugName,
|
|
50
18
|
item,
|
|
@@ -90,7 +58,6 @@ const Option = <T extends string|number>(props: OptionProps<T>) => {
|
|
|
90
58
|
onPress={onSelect}
|
|
91
59
|
disabled={isDisabled}
|
|
92
60
|
>
|
|
93
|
-
|
|
94
61
|
{reverseOrder ? (
|
|
95
62
|
<>
|
|
96
63
|
{label}
|
|
@@ -128,41 +95,38 @@ const Option = <T extends string|number>(props: OptionProps<T>) => {
|
|
|
128
95
|
)}
|
|
129
96
|
|
|
130
97
|
</Touchable>
|
|
131
|
-
{separator
|
|
98
|
+
{separator ? <View style={styles.optionSeparator} /> : null}
|
|
132
99
|
</>
|
|
133
100
|
}
|
|
134
101
|
|
|
135
|
-
export const RadioGroup = <T extends string|number>(
|
|
136
|
-
props: RadioGroupProps<T>,
|
|
137
|
-
) => {
|
|
102
|
+
export const RadioGroup = <T extends string | number>(props: RadioGroupProps<T>) => {
|
|
138
103
|
const {
|
|
139
104
|
inputBaseProps,
|
|
140
105
|
others,
|
|
141
|
-
} = selectInputBaseProps(
|
|
106
|
+
} = selectInputBaseProps({
|
|
107
|
+
...RadioGroup.defaultProps,
|
|
108
|
+
...props,
|
|
109
|
+
})
|
|
142
110
|
|
|
143
111
|
const {
|
|
144
112
|
options,
|
|
145
113
|
value,
|
|
146
114
|
onValueChange,
|
|
147
|
-
variants,
|
|
148
|
-
styles,
|
|
149
115
|
disabled,
|
|
150
116
|
debugName,
|
|
151
117
|
radioOnRight,
|
|
118
|
+
style,
|
|
152
119
|
} = others
|
|
153
120
|
|
|
154
|
-
const
|
|
155
|
-
variants,
|
|
156
|
-
styles,
|
|
157
|
-
transform: StyleSheet.flatten,
|
|
158
|
-
})
|
|
121
|
+
const styles = useStylesFor(RadioGroup.styleRegistryName, style)
|
|
159
122
|
|
|
160
|
-
|
|
123
|
+
// @ts-expect-error icss type
|
|
124
|
+
const _radioOnRight = radioOnRight ?? styles?.__props?.radioOnRight
|
|
161
125
|
|
|
162
126
|
return <InputBase
|
|
163
127
|
{...inputBaseProps}
|
|
164
128
|
disabled={disabled}
|
|
165
|
-
|
|
129
|
+
style={styles}
|
|
166
130
|
debugName={debugName}
|
|
167
131
|
>
|
|
168
132
|
{options?.map((item, idx) => (
|
|
@@ -171,7 +135,7 @@ export const RadioGroup = <T extends string|number>(
|
|
|
171
135
|
item={item}
|
|
172
136
|
key={idx}
|
|
173
137
|
disabled={disabled}
|
|
174
|
-
styles={
|
|
138
|
+
styles={styles}
|
|
175
139
|
selected={value === item.value}
|
|
176
140
|
onSelect={() => onValueChange(item.value)}
|
|
177
141
|
separator={idx < options.length - 1}
|
|
@@ -179,5 +143,16 @@ export const RadioGroup = <T extends string|number>(
|
|
|
179
143
|
/>
|
|
180
144
|
))}
|
|
181
145
|
</InputBase>
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
RadioGroup.styleRegistryName = 'RadioGroup'
|
|
149
|
+
RadioGroup.elements = [...InputBase.elements, 'option', '__props']
|
|
150
|
+
RadioGroup.rootElement = 'wrapper'
|
|
182
151
|
|
|
152
|
+
RadioGroup.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
153
|
+
return RadioGroup as (<T extends string | number>(props: StyledComponentProps<RadioGroupProps<T>, typeof styles>) => IJSX)
|
|
183
154
|
}
|
|
155
|
+
|
|
156
|
+
RadioGroup.defaultProps = {} as Partial<RadioGroupProps<string | number>>
|
|
157
|
+
|
|
158
|
+
MobileStyleRegistry.registerComponent(RadioGroup)
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
1
|
import { IconLessInputBaseParts } from '../InputBase'
|
|
3
2
|
|
|
4
3
|
type OptionParts = 'wrapper' | 'label' | 'indicator' | 'indicatorInner' | 'separator'
|
|
@@ -6,9 +5,8 @@ type OptionStates = 'selected' | 'disabled' | 'selectedDisabled'
|
|
|
6
5
|
|
|
7
6
|
type OptionComposition = `${OptionParts}:${OptionStates}` | OptionParts
|
|
8
7
|
|
|
9
|
-
export type RadioInputComposition =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export const RadioInputPresets = includePresets(style => createRadioStyle(() => ({ wrapper: style })))
|
|
8
|
+
export type RadioInputComposition =
|
|
9
|
+
IconLessInputBaseParts |
|
|
10
|
+
`${IconLessInputBaseParts}:disabled` |
|
|
11
|
+
`option${Capitalize<OptionComposition>}` |
|
|
12
|
+
'__props'
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FormTypes, StylesOf } from '@codeleap/common'
|
|
2
|
+
import { StyledProp } from '@codeleap/styles'
|
|
3
|
+
import { ReactNode } from 'react'
|
|
4
|
+
import { RadioInputComposition } from './styles'
|
|
5
|
+
import { InputBaseProps } from '../InputBase'
|
|
6
|
+
|
|
7
|
+
type RadioOption<T> = FormTypes.Options<T>[number] & {
|
|
8
|
+
disabled?: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type RadioGroupProps<T extends string | number> =
|
|
12
|
+
Omit<InputBaseProps, 'style'> &
|
|
13
|
+
{
|
|
14
|
+
options: RadioOption<T>[]
|
|
15
|
+
value: T
|
|
16
|
+
onValueChange(value: T): void
|
|
17
|
+
label: ReactNode
|
|
18
|
+
radioOnRight?: boolean
|
|
19
|
+
style?: StyledProp<RadioInputComposition>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type RadioOptionProps<T extends string | number> = {
|
|
23
|
+
item: RadioOption<T>
|
|
24
|
+
selected: boolean
|
|
25
|
+
onSelect(): void
|
|
26
|
+
debugName?: string
|
|
27
|
+
disabled?: boolean
|
|
28
|
+
separator?: boolean
|
|
29
|
+
reverseOrder?: boolean
|
|
30
|
+
styles?: StylesOf<RadioInputComposition>
|
|
31
|
+
}
|
|
@@ -1,28 +1,48 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
3
|
+
import { RefreshControl as RNRefreshControl } from 'react-native'
|
|
4
|
+
import { MobileStyleRegistry } from '../../Registry'
|
|
5
|
+
import { RefreshControlProps } from './types'
|
|
6
|
+
import { useStylesFor } from '../../hooks'
|
|
7
|
+
import { ColorValue } from 'react-native'
|
|
4
8
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
export * from './styles'
|
|
10
|
+
export * from './types'
|
|
11
|
+
|
|
12
|
+
export const RefreshControl = (props: RefreshControlProps) => {
|
|
13
|
+
const {
|
|
14
|
+
style,
|
|
15
|
+
...rest
|
|
16
|
+
} = {
|
|
17
|
+
...RefreshControl.defaultProps,
|
|
18
|
+
...props,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const styles = useStylesFor(RefreshControl.styleRegistryName, style)
|
|
8
22
|
|
|
9
|
-
|
|
10
|
-
const
|
|
23
|
+
const color: ColorValue = (styles?.loadingAnimation as AnyRecord)?.color
|
|
24
|
+
const titleColor: ColorValue = (styles?.titleColor as AnyRecord)?.color
|
|
25
|
+
const progressBackgroundColor: ColorValue = (styles?.progressBackgroundColor as AnyRecord)?.color
|
|
11
26
|
|
|
12
|
-
const variantStyles = useDefaultComponentStyle<'u:RefreshControl', typeof RefreshControlPresets>('u:RefreshControl', {
|
|
13
|
-
variants,
|
|
14
|
-
styles,
|
|
15
|
-
})
|
|
16
27
|
return (
|
|
17
28
|
<RNRefreshControl
|
|
18
|
-
colors={[
|
|
19
|
-
tintColor={
|
|
20
|
-
progressBackgroundColor={
|
|
21
|
-
titleColor={
|
|
22
|
-
{...
|
|
29
|
+
colors={[color]}
|
|
30
|
+
tintColor={color}
|
|
31
|
+
progressBackgroundColor={progressBackgroundColor}
|
|
32
|
+
titleColor={titleColor}
|
|
33
|
+
{...rest}
|
|
23
34
|
/>
|
|
24
|
-
|
|
25
35
|
)
|
|
26
36
|
}
|
|
27
37
|
|
|
28
|
-
|
|
38
|
+
RefreshControl.styleRegistryName = 'RefreshControl'
|
|
39
|
+
RefreshControl.elements = ['loadingAnimation', 'progressBackgroundColor', 'titleColor']
|
|
40
|
+
RefreshControl.rootElement = 'wrapper'
|
|
41
|
+
|
|
42
|
+
RefreshControl.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
43
|
+
return RefreshControl as (props: StyledComponentProps<RefreshControlProps, typeof styles>) => IJSX
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
RefreshControl.defaultProps = {} as Partial<RefreshControlProps>
|
|
47
|
+
|
|
48
|
+
MobileStyleRegistry.registerComponent(RefreshControl)
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
1
|
|
|
3
|
-
export type RefreshControlComposition = 'loadingAnimation' |'progressBackgroundColor' | 'titleColor'
|
|
4
|
-
|
|
5
|
-
const createRefreshControlStyle = createDefaultVariantFactory<RefreshControlComposition>()
|
|
6
|
-
|
|
7
|
-
export const RefreshControlPresets = includePresets(style => createRefreshControlStyle(() => ({ loadingAnimation: style })))
|
|
2
|
+
export type RefreshControlComposition = 'loadingAnimation' | 'progressBackgroundColor' | 'titleColor'
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { StyledProp } from '@codeleap/styles'
|
|
2
|
+
import { RefreshControlProps as RNRefreshControlProps } from 'react-native'
|
|
3
|
+
import { RefreshControlComposition } from './styles'
|
|
4
|
+
|
|
5
|
+
export type RefreshControlProps =
|
|
6
|
+
Omit<RNRefreshControlProps, 'style'> &
|
|
7
|
+
{
|
|
8
|
+
style?: StyledProp<RefreshControlComposition>
|
|
9
|
+
}
|