@codeleap/mobile 3.24.3 → 3.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/package.json +6 -4
  2. package/src/Registry.ts +52 -0
  3. package/src/components/ActionIcon/index.tsx +55 -37
  4. package/src/components/ActionIcon/styles.ts +2 -4
  5. package/src/components/ActionIcon/types.ts +15 -0
  6. package/src/components/ActivityIndicator/index.tsx +42 -64
  7. package/src/components/ActivityIndicator/styles.ts +1 -10
  8. package/src/components/ActivityIndicator/types.ts +9 -0
  9. package/src/components/Autocomplete/index.tsx +46 -54
  10. package/src/components/Autocomplete/styles.ts +2 -5
  11. package/src/components/Autocomplete/types.ts +13 -23
  12. package/src/components/Avatar/index.tsx +59 -71
  13. package/src/components/Avatar/styles.ts +1 -9
  14. package/src/components/Avatar/types.ts +23 -0
  15. package/src/components/AvatarGroup/index.tsx +30 -44
  16. package/src/components/AvatarGroup/styles.ts +0 -6
  17. package/src/components/AvatarGroup/types.ts +10 -0
  18. package/src/components/Backdrop/index.tsx +51 -34
  19. package/src/components/Backdrop/styles.ts +5 -10
  20. package/src/components/Backdrop/types.ts +14 -0
  21. package/src/components/Badge/index.tsx +36 -62
  22. package/src/components/Badge/styles.ts +3 -11
  23. package/src/components/Badge/types.ts +27 -0
  24. package/src/components/Button/index.tsx +55 -82
  25. package/src/components/Button/styles.ts +13 -14
  26. package/src/components/Button/types.ts +20 -0
  27. package/src/components/Calendar/index.tsx +35 -29
  28. package/src/components/Checkbox/index.tsx +43 -64
  29. package/src/components/Checkbox/styles.ts +1 -6
  30. package/src/components/Checkbox/types.ts +13 -0
  31. package/src/components/DatePickerModal/index.tsx +50 -65
  32. package/src/components/DatePickerModal/styles.ts +9 -10
  33. package/src/components/DatePickerModal/types.ts +36 -54
  34. package/src/components/EmptyPlaceholder/index.tsx +40 -63
  35. package/src/components/EmptyPlaceholder/styles.ts +0 -5
  36. package/src/components/EmptyPlaceholder/types.ts +21 -0
  37. package/src/components/FileInput/index.tsx +11 -49
  38. package/src/components/FileInput/types.ts +27 -0
  39. package/src/components/Grid/index.tsx +84 -116
  40. package/src/components/Grid/styles.ts +0 -5
  41. package/src/components/Grid/types.ts +20 -0
  42. package/src/components/Icon/index.tsx +44 -79
  43. package/src/components/Icon/styles.ts +0 -6
  44. package/src/components/Icon/types.ts +15 -0
  45. package/src/components/Image/index.tsx +58 -78
  46. package/src/components/Image/styles.ts +1 -6
  47. package/src/components/Image/types.ts +18 -0
  48. package/src/components/ImageView/Spotlight.tsx +1 -4
  49. package/src/components/ImageView/component.tsx +1 -2
  50. package/src/components/InputBase/index.tsx +33 -24
  51. package/src/components/InputBase/styles.ts +66 -75
  52. package/src/components/InputBase/types.ts +3 -4
  53. package/src/components/InputBase/utils.ts +6 -4
  54. package/src/components/List/index.tsx +99 -151
  55. package/src/components/List/styles.ts +0 -6
  56. package/src/components/List/types.ts +41 -0
  57. package/src/components/LoadingOverlay/index.tsx +42 -29
  58. package/src/components/LoadingOverlay/styles.ts +7 -7
  59. package/src/components/LoadingOverlay/types.ts +9 -0
  60. package/src/components/Modal/index.tsx +80 -127
  61. package/src/components/Modal/styles.ts +0 -8
  62. package/src/components/Modal/types.ts +41 -0
  63. package/src/components/Navigation/Navigation.tsx +1 -0
  64. package/src/components/Navigation/types.ts +2 -9
  65. package/src/components/NumberIncrement/index.tsx +50 -60
  66. package/src/components/NumberIncrement/styles.ts +0 -5
  67. package/src/components/NumberIncrement/types.ts +32 -39
  68. package/src/components/Pager/index.tsx +42 -94
  69. package/src/components/Pager/styles.ts +1 -13
  70. package/src/components/Pager/types.ts +37 -0
  71. package/src/components/PaginationIndicator/index.tsx +51 -0
  72. package/src/components/PaginationIndicator/styles.ts +3 -0
  73. package/src/components/PaginationIndicator/types.ts +10 -0
  74. package/src/components/RadioInput/index.tsx +32 -57
  75. package/src/components/RadioInput/styles.ts +5 -7
  76. package/src/components/RadioInput/types.ts +31 -0
  77. package/src/components/RefreshControl/index.tsx +39 -19
  78. package/src/components/RefreshControl/styles.ts +1 -6
  79. package/src/components/RefreshControl/types.ts +9 -0
  80. package/src/components/Scroll/index.tsx +89 -105
  81. package/src/components/Scroll/styles.ts +0 -5
  82. package/src/components/Scroll/types.ts +21 -0
  83. package/src/components/SearchInput/index.tsx +90 -0
  84. package/src/components/Sections/index.tsx +111 -161
  85. package/src/components/Sections/styles.ts +0 -5
  86. package/src/components/Sections/types.ts +39 -0
  87. package/src/components/SegmentedControl/Option.tsx +46 -31
  88. package/src/components/SegmentedControl/index.tsx +86 -121
  89. package/src/components/SegmentedControl/styles.ts +15 -22
  90. package/src/components/SegmentedControl/types.ts +31 -0
  91. package/src/components/Select/index.tsx +71 -82
  92. package/src/components/Select/styles.ts +3 -5
  93. package/src/components/Select/types.ts +20 -25
  94. package/src/components/Slider/index.tsx +58 -43
  95. package/src/components/Slider/styles.ts +15 -6
  96. package/src/components/Slider/types.ts +9 -14
  97. package/src/components/Switch/index.tsx +43 -56
  98. package/src/components/Switch/styles.ts +1 -7
  99. package/src/components/Switch/types.ts +12 -0
  100. package/src/components/Text/index.tsx +56 -52
  101. package/src/components/Text/styles.ts +1 -7
  102. package/src/components/Text/types.ts +18 -0
  103. package/src/components/TextInput/index.tsx +49 -162
  104. package/src/components/TextInput/styles.ts +2 -8
  105. package/src/components/TextInput/types.ts +23 -0
  106. package/src/components/Touchable/index.tsx +44 -87
  107. package/src/components/Touchable/styles.ts +0 -9
  108. package/src/components/Touchable/types.ts +27 -0
  109. package/src/components/View/index.tsx +23 -92
  110. package/src/components/View/styles.ts +0 -6
  111. package/src/components/View/types.ts +13 -0
  112. package/src/components/components.ts +2 -6
  113. package/src/hooks/index.ts +13 -0
  114. package/src/index.ts +2 -0
  115. package/src/modules/PressableRipple/type.ts +1 -0
  116. package/src/utils/KeyboardAware/context.tsx +0 -2
  117. package/src/utils/KeyboardAware/keyboardHooks.ts +1 -2
  118. package/src/utils/ModalManager/components.tsx +1 -30
  119. package/src/utils/ModalManager/context.tsx +4 -4
  120. package/src/utils/ModalManager/index.ts +1 -4
  121. package/src/utils/hooks.ts +12 -1
  122. package/src/components/Calendar/style.ts +0 -6
  123. package/src/components/ContentView/index.tsx +0 -63
  124. package/src/components/ContentView/styles.ts +0 -8
  125. package/src/components/Drawer/index.tsx +0 -28
  126. package/src/components/Drawer/styles.ts +0 -8
  127. package/src/components/FileInput/styles.ts +0 -8
  128. package/src/components/InputLabel/index.tsx +0 -38
  129. package/src/components/InputLabel/styles.ts +0 -7
  130. package/src/components/List/PaginationIndicator.tsx +0 -54
  131. package/src/components/defaultStyles.ts +0 -77
@@ -1,86 +1,27 @@
1
- import {
2
- AnyFunction,
3
- ComponentVariants,
4
- onUpdate,
5
- TypeGuards,
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 { PagerPresets, PagerComposition } from './styles'
21
- export * from './styles'
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
- type ScrollEvent = NativeSyntheticEvent<NativeScrollEvent>
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 = true,
17
+ style,
18
+ returnEarly,
78
19
  renderPageWrapper,
79
20
  pageWrapperProps = {},
80
21
  children,
81
- windowing = false,
22
+ windowing,
82
23
  setPage,
83
- scrollEnabled = true,
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 variantStyles = useDefaultComponentStyle<'u:Pager', typeof PagerPresets>(
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
- let width = widthProp ?? variantStyles.wrapper.width
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.defaultProps = defaultProps
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,3 @@
1
+ import { ActivityIndicatorComposition } from '../ActivityIndicator'
2
+
3
+ export type PaginationIndicatorComposition = 'text' | `loader${Capitalize<ActivityIndicatorComposition>}`
@@ -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 { RadioInputComposition, RadioInputPresets } from './styles'
16
- import { InputLabel } from '../InputLabel'
17
- import { StyleSheet } from 'react-native'
18
- import { InputBase, InputBaseDefaultOrder, InputBaseProps, selectInputBaseProps } from '../InputBase'
19
- export * from './styles'
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
- type RadioOption<T> = FormTypes.Options<T>[number] & {
24
- disabled?: boolean
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: OptionProps<T>) => {
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 && <View style={styles.optionSeparator} />}
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(props)
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 variantStyles = useDefaultComponentStyle<'u:RadioInput', typeof RadioInputPresets>('u:RadioInput', {
155
- variants,
156
- styles,
157
- transform: StyleSheet.flatten,
158
- })
121
+ const styles = useStylesFor(RadioGroup.styleRegistryName, style)
159
122
 
160
- const _radioOnRight = radioOnRight ?? variantStyles.__props?.radioOnRight
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
- styles={variantStyles}
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={variantStyles}
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 = IconLessInputBaseParts | `${IconLessInputBaseParts}:disabled` | `option${Capitalize<OptionComposition>}` | '__props'
10
-
11
- const createRadioStyle =
12
- createDefaultVariantFactory<RadioInputComposition>()
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 { ComponentVariants, StylesOf, useDefaultComponentStyle } from '@codeleap/common'
2
- import { RefreshControl as RNRefreshControl, RefreshControlProps as RNRefreshControlProps } from 'react-native'
3
- import { RefreshControlComposition, RefreshControlPresets } from './styles'
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 type RefreshControlProps = {
6
- styles?: StylesOf<RefreshControlComposition>
7
- } & RNRefreshControlProps & ComponentVariants<typeof RefreshControlPresets>
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
- export const RefreshControl = (props:RefreshControlProps) => {
10
- const { variants = [], styles } = props
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={[variantStyles.loadingAnimation?.color]}
19
- tintColor={variantStyles.loadingAnimation?.color}
20
- progressBackgroundColor={variantStyles.progressBackgroundColor?.color}
21
- titleColor={variantStyles.titleColor?.color}
22
- {...props}
29
+ colors={[color]}
30
+ tintColor={color}
31
+ progressBackgroundColor={progressBackgroundColor}
32
+ titleColor={titleColor}
33
+ {...rest}
23
34
  />
24
-
25
35
  )
26
36
  }
27
37
 
28
- export * from './styles'
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
+ }