@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,50 +1,19 @@
1
- import * as React from 'react'
2
- import {
3
- ComponentVariants,
4
- FormTypes,
5
- PropsOf,
6
- TypeGuards,
7
- useDefaultComponentStyle,
8
- useValidate,
9
- yup,
10
- useState,
11
- useBooleanToggle,
12
- IconPlaceholder,
13
- } from '@codeleap/common'
1
+ import React, { useState } from 'react'
2
+ import { TypeGuards, useValidate, useBooleanToggle } from '@codeleap/common'
14
3
  import { forwardRef, useImperativeHandle } from 'react'
15
- import { ComponentWithDefaultProps, StylesOf } from '../../types'
16
- import { StyleSheet, TextInput as NativeTextInput, TextInputProps as NativeTextInputProps, NativeSyntheticEvent, TextInputFocusEventData } from 'react-native'
17
- import { InputBase, InputBaseProps, selectInputBaseProps } from '../InputBase'
18
- import { TextInputComposition, TextInputPresets } from './styles'
4
+ import { TextInput as NativeTextInput, NativeSyntheticEvent, TextInputFocusEventData } from 'react-native'
5
+ import { InputBase, selectInputBaseProps } from '../InputBase'
19
6
  import { Touchable } from '../Touchable'
20
- import { MaskedTextInput, TextInputMaskProps } from '../../modules/textInputMask'
7
+ import { MaskedTextInput } from '../../modules/textInputMask'
8
+ import { AnyRecord, AppIcon, IJSX, StyledComponentProps, StyledComponentWithProps } from '@codeleap/styles'
9
+ import { TextInputProps } from './types'
10
+ import { MobileStyleRegistry } from '../../Registry'
11
+ import { useStylesFor } from '../../hooks'
21
12
 
22
13
  export * from './styles'
14
+ export * from './types'
23
15
 
24
- export type TextInputProps =
25
- Omit<InputBaseProps, 'styles' | 'variants'> &
26
- NativeTextInputProps &
27
- {
28
- styles?: StylesOf<TextInputComposition>
29
- password?: boolean
30
- validate?: FormTypes.ValidatorFunctionWithoutForm | yup.SchemaOf<string>
31
- debugName: string
32
- visibilityToggle?: boolean
33
- masking?: FormTypes.TextField['masking']
34
- variants?: ComponentVariants<typeof TextInputPresets>['variants']
35
- onChangeMask?: TextInputMaskProps['onChangeText']
36
- visibleIcon?: IconPlaceholder
37
- hiddenIcon?: IconPlaceholder
38
- _error?: string
39
- } & Pick<PropsOf<typeof Touchable>, 'onPress'>
40
-
41
- const defaultProps: Partial<TextInputProps> = {
42
- hiddenIcon: 'input-visiblity:hidden' as IconPlaceholder,
43
- visibleIcon: 'input-visiblity:visible' as IconPlaceholder,
44
- }
45
-
46
- const TextInputComponent = forwardRef<NativeTextInput, TextInputProps>((props, inputRef) => {
47
-
16
+ export const TextInput = forwardRef<NativeTextInput, TextInputProps>((props, inputRef) => {
48
17
  const innerInputRef = React.useRef<NativeTextInput>(null)
49
18
 
50
19
  const [isFocused, setIsFocused] = useState(false)
@@ -58,18 +27,17 @@ const TextInputComponent = forwardRef<NativeTextInput, TextInputProps>((props, i
58
27
  })
59
28
 
60
29
  const {
61
- variants,
62
- styles,
63
30
  value,
64
31
  validate,
65
32
  debugName,
66
- visibilityToggle = false,
33
+ visibilityToggle,
67
34
  masking,
68
35
  password,
69
36
  onChangeMask,
70
37
  onPress,
71
38
  visibleIcon,
72
39
  hiddenIcon,
40
+ style,
73
41
  _error = null,
74
42
  ...textInputProps
75
43
  } = others
@@ -80,11 +48,7 @@ const TextInputComponent = forwardRef<NativeTextInput, TextInputProps>((props, i
80
48
 
81
49
  const InputElement = isMasked ? MaskedTextInput : NativeTextInput
82
50
 
83
- const variantStyles = useDefaultComponentStyle<'u:TextInput', typeof TextInputPresets>('u:TextInput', {
84
- variants,
85
- styles,
86
- transform: StyleSheet.flatten,
87
- })
51
+ const styles = useStylesFor(TextInput.styleRegistryName, style)
88
52
 
89
53
  // @ts-expect-error - React's ref type system is weird
90
54
  useImperativeHandle(inputRef, () => {
@@ -114,7 +78,6 @@ const TextInputComponent = forwardRef<NativeTextInput, TextInputProps>((props, i
114
78
  }, [validation.onInputFocused, props.onFocus])
115
79
 
116
80
  const handleMaskChange = (masked, unmasked) => {
117
-
118
81
  if (textInputProps.onChangeText) textInputProps.onChangeText(masking?.saveFormatted ? masked : masked)
119
82
  if (onChangeMask) onChangeMask(masked, unmasked)
120
83
  }
@@ -123,22 +86,24 @@ const TextInputComponent = forwardRef<NativeTextInput, TextInputProps>((props, i
123
86
  const isDisabled = !!inputBaseProps.disabled
124
87
 
125
88
  const placeholderTextColor = [
126
- [isDisabled, variantStyles['placeholder:disabled']],
127
- [!validation.isValid, variantStyles['placeholder:error']],
128
- [isFocused, variantStyles['placeholder:focus']],
129
- [true, variantStyles.placeholder],
89
+ [isDisabled, styles['placeholder:disabled']],
90
+ [!validation.isValid, styles['placeholder:error']],
91
+ [isFocused, styles['placeholder:focus']],
92
+ [true, styles?.placeholder],
93
+ // @ts-expect-error
130
94
  ].find(([x]) => x)?.[1]?.color
131
95
 
132
96
  const selectionColor = [
133
- [isDisabled, variantStyles['selection:disabled']],
134
- [!validation.isValid, variantStyles['selection:error']],
135
- [isFocused, variantStyles['selection:focus']],
136
- [true, variantStyles.selection],
97
+ [isDisabled, styles['selection:disabled']],
98
+ [!validation.isValid, styles['selection:error']],
99
+ [isFocused, styles['selection:focus']],
100
+ [true, styles?.selection],
101
+ // @ts-expect-error
137
102
  ].find(([x]) => x)?.[1]?.color
138
103
 
139
104
  const visibilityToggleProps = visibilityToggle ? {
140
105
  onPress: toggleSecureTextEntry,
141
- icon: (secureTextEntry ? hiddenIcon : visibleIcon) as IconPlaceholder,
106
+ icon: (secureTextEntry ? hiddenIcon : visibleIcon) as AppIcon,
142
107
  debugName: `${debugName} toggle visibility`,
143
108
  } : null
144
109
 
@@ -147,35 +112,32 @@ const TextInputComponent = forwardRef<NativeTextInput, TextInputProps>((props, i
147
112
  const maskingExtraProps = isMasked ? {
148
113
  onChangeText: handleMaskChange,
149
114
  ref: null,
150
-
151
115
  refInput: (inputRef) => {
152
- // console.log(inputRef)
153
116
  if (!!inputRef) {
154
117
  innerInputRef.current = inputRef
155
-
156
118
  }
157
119
  },
158
120
  ...masking,
159
121
  } : {}
160
122
 
161
123
  const buttonModeProps = isPressable ? {
162
- // pointerEvents: 'none',
163
124
  editable: false,
164
125
  caretHidden: true,
165
126
  } : {}
166
127
 
167
128
  const hasMultipleLines = isMultiline && value?.includes('\n')
129
+
168
130
  return <InputBase
169
131
  {...inputBaseProps}
170
132
  innerWrapper={isPressable ? Touchable : undefined}
171
133
  debugName={debugName}
172
134
  error={(validation.isValid && !_error) ? null : _error || validation.message}
173
- styles={{
174
- ...variantStyles,
135
+ style={{
136
+ ...styles,
175
137
  innerWrapper: [
176
- variantStyles.innerWrapper,
177
- isMultiline && variantStyles['innerWrapper:multiline'],
178
- hasMultipleLines && variantStyles['innerWrapper:hasMultipleLines'],
138
+ styles?.innerWrapper,
139
+ isMultiline && styles['innerWrapper:multiline'],
140
+ hasMultipleLines && styles['innerWrapper:hasMultipleLines'],
179
141
  ],
180
142
  }}
181
143
  innerWrapperProps={{
@@ -188,7 +150,6 @@ const TextInputComponent = forwardRef<NativeTextInput, TextInputProps>((props, i
188
150
  focused={isFocused}
189
151
  >
190
152
  <InputElement
191
-
192
153
  allowFontScaling={false}
193
154
  editable={!isPressable && !isDisabled}
194
155
  {...buttonModeProps}
@@ -201,106 +162,32 @@ const TextInputComponent = forwardRef<NativeTextInput, TextInputProps>((props, i
201
162
  onBlur={handleBlur}
202
163
  onFocus={handleFocus}
203
164
  style={[
204
- variantStyles.input,
205
- isMultiline && variantStyles['input:multiline'],
206
- isFocused && variantStyles['input:focused'],
207
- !validation.isValid && variantStyles['input:error'],
208
- isDisabled && variantStyles['input:disabled'],
209
- hasMultipleLines && variantStyles['input:hasMultipleLines'],
165
+ styles?.input,
166
+ isMultiline && styles['input:multiline'],
167
+ isFocused && styles['input:focused'],
168
+ !validation.isValid && styles['input:error'],
169
+ isDisabled && styles['input:disabled'],
170
+ hasMultipleLines && styles['input:hasMultipleLines'],
210
171
  ]}
211
172
  ref={innerInputRef}
212
173
  pointerEvents={isPressable ? 'none' : undefined}
213
174
  {...maskingExtraProps}
214
175
  />
215
176
  </InputBase>
216
- })
177
+ }) as StyledComponentWithProps<TextInputProps>
217
178
 
218
- export type SearchInputProps = {
219
- onTypingChange: (isTyping: boolean) => void
220
- onSearchChange: (search: string) => void
221
- onValueChange?: (search: string) => void
222
- onClear?: () => void
223
- debugName: string
224
- debounce?: number
225
- clearIcon?: IconPlaceholder
226
- searchIcon?: IconPlaceholder
227
- placeholder: string
228
- } & Partial<TextInputProps>
229
-
230
- export const SearchInput: ComponentWithDefaultProps<SearchInputProps> = (props) => {
231
- const {
232
- debugName,
233
- onClear,
234
- onSearchChange,
235
- onTypingChange,
236
- clearIcon,
237
- searchIcon,
238
- debounce,
239
- placeholder,
240
- value,
241
- onValueChange,
242
- ...others
243
- } = {
244
- ...SearchInput.defaultProps,
245
- ...props,
246
- }
179
+ TextInput.styleRegistryName = 'TextInput'
180
+ TextInput.elements = [...InputBase.elements, 'input', 'placeholder', 'selection']
181
+ TextInput.rootElement = 'wrapper'
247
182
 
248
- const [search, setSearch] = !TypeGuards.isNil(value) && !!onValueChange ? [value, onValueChange] : useState('')
249
-
250
- const setSearchTimeout = React.useRef<NodeJS.Timeout | null>(null)
251
-
252
- const handleChangeSearch = (value: string) => {
253
- setSearch(value)
254
-
255
- if (TypeGuards.isNil(debounce)) {
256
- onSearchChange?.(value)
257
- } else {
258
- if (setSearchTimeout.current) {
259
- clearTimeout(setSearchTimeout.current)
260
- }
261
-
262
- setSearchTimeout.current = setTimeout(() => {
263
-
264
- onSearchChange(value)
265
- onTypingChange?.(false)
266
- }, debounce ?? 0)
267
- }
268
-
269
- }
270
-
271
- const handleClear = () => {
272
- setSearch('')
273
- onSearchChange?.('')
274
- onClear?.()
275
- }
276
-
277
- return (
278
- <TextInput
279
- value={search}
280
- onChangeText={(value) => {
281
- onTypingChange?.(true)
282
- handleChangeSearch(value)
283
- }}
284
- placeholder={placeholder}
285
- debugName={`Search ${debugName}`}
286
- rightIcon={!!search.trim() && {
287
- name: clearIcon,
288
- onPress: handleClear,
289
- }}
290
- leftIcon={{
291
- name: searchIcon,
292
- }}
293
- {...others}
294
- />
295
- )
183
+ TextInput.withVariantTypes = <S extends AnyRecord>(styles: S) => {
184
+ return TextInput as (props: StyledComponentProps<TextInputProps, typeof styles>) => IJSX
296
185
  }
297
186
 
298
- export const TextInput = TextInputComponent as ComponentWithDefaultProps<TextInputProps>
299
-
300
- TextInput.defaultProps = defaultProps
187
+ TextInput.defaultProps = {
188
+ hiddenIcon: 'input-visiblity:hidden' as AppIcon,
189
+ visibleIcon: 'input-visiblity:visible' as AppIcon,
190
+ visibilityToggle: false,
191
+ } as Partial<TextInputProps>
301
192
 
302
- SearchInput.defaultProps = {
303
- debounce: null,
304
- clearIcon: 'x' as IconPlaceholder,
305
- searchIcon: 'search' as IconPlaceholder,
306
- }
193
+ MobileStyleRegistry.registerComponent(TextInput)
@@ -1,13 +1,7 @@
1
- import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
- import { InputBaseComposition, InputBaseStates, InputBaseParts } from '../InputBase'
3
-
1
+ import { InputBaseStates, InputBaseParts } from '../InputBase'
4
2
 
5
3
  type TextInputParts = InputBaseParts | 'input' | 'placeholder' | 'selection'
4
+
6
5
  export type TextInputStates = InputBaseStates | 'multiline' | 'hasMultipleLines' | 'pressable'
7
6
 
8
7
  export type TextInputComposition = `${TextInputParts}:${TextInputStates}` | TextInputParts
9
-
10
- const createTextInputStyle =
11
- createDefaultVariantFactory<TextInputComposition>()
12
-
13
- export const TextInputPresets = includePresets((styles) => createTextInputStyle(() => ({ wrapper: styles })))
@@ -0,0 +1,23 @@
1
+ import { InputBaseProps } from '../InputBase'
2
+ import { TextInputProps as RNTextInputProps } from 'react-native'
3
+ import { AnyFunction, FormTypes, yup } from '@codeleap/common'
4
+ import { AppIcon, StyledProp } from '@codeleap/styles'
5
+ import { TextInputMaskProps } from '../../modules/textInputMask'
6
+ import { TextInputComposition } from './styles'
7
+
8
+ export type TextInputProps =
9
+ Omit<InputBaseProps, 'style'> &
10
+ Omit<RNTextInputProps, 'style'> &
11
+ {
12
+ password?: boolean
13
+ validate?: FormTypes.ValidatorFunctionWithoutForm | yup.SchemaOf<string>
14
+ debugName: string
15
+ visibilityToggle?: boolean
16
+ masking?: FormTypes.TextField['masking']
17
+ onChangeMask?: TextInputMaskProps['onChangeText']
18
+ visibleIcon?: AppIcon
19
+ hiddenIcon?: AppIcon
20
+ _error?: string
21
+ onPress?: AnyFunction
22
+ style?: StyledProp<TextInputComposition>
23
+ }
@@ -1,65 +1,20 @@
1
- import * as React from 'react'
2
- import { forwardRef } from 'react'
3
- import {
4
- ComponentVariants,
5
- useDefaultComponentStyle,
6
-
7
- useCodeleapContext,
8
- AnyFunction,
9
- TypeGuards,
10
- onMount,
11
- } from '@codeleap/common'
12
- import { Pressable, StyleSheet, View as RNView, Insets, Platform, PressableProps, ViewStyle, StyleProp } from 'react-native'
13
- import { TouchableComposition, TouchablePresets } from './styles'
14
- import { StylesOf } from '../../types'
1
+ import React, { forwardRef } from 'react'
2
+ import { TypeGuards, onMount, useGlobalContext } from '@codeleap/common'
3
+ import { Pressable, StyleSheet, View as RNView, Insets, Platform } from 'react-native'
15
4
  import { View } from '../View'
16
- import { usePressableFeedback } from '../../utils'
5
+ import { TouchableFeedbackConfig, usePressableFeedback } from '../../utils'
17
6
  import { Keyboard } from 'react-native'
18
-
19
7
  import { PressableRipple } from '../../modules/PressableRipple'
20
- export type TouchableProps =
21
- Omit<
22
- PressableProps,
23
- 'onPress' | 'children' | 'style'
24
- > & {
25
- variants?: ComponentVariants<typeof TouchablePresets>['variants']
26
- component?: any
27
- ref?: React.Ref<RNView>
28
- debugName: string
29
- activeOpacity?: number
30
- debugComponent?: string
31
- onPress?: AnyFunction
32
- noFeedback?: boolean
33
- debounce?: number
34
- leadingDebounce?: boolean
35
- styles?: StylesOf<TouchableComposition>
36
- setPressed?: (param: boolean) => void
37
- rippleDisabled?: boolean
38
- children?: React.ReactNode
39
- style?: StyleProp<ViewStyle>
40
- analyticsEnabled?: boolean
41
- analyticsName?: string
42
- analyticsData?: Record<string, any>
43
- dismissKeyboard?: boolean
44
- }
8
+ import { AnyRecord, IJSX, StyledComponentProps, StyledComponentWithProps } from '@codeleap/styles'
9
+ import { TouchableProps } from './types'
10
+ import { MobileStyleRegistry } from '../../Registry'
11
+ import { useStylesFor } from '../../hooks'
45
12
 
46
13
  export * from './styles'
47
- const defaultProps: Partial<TouchableProps> = {
48
- variants: [],
49
- debounce: 500,
50
- noFeedback: false,
51
- rippleDisabled: false,
52
- analyticsEnabled: false,
53
- analyticsName: null,
54
- analyticsData: {},
55
- dismissKeyboard: true,
56
- }
57
- const _Touchable = forwardRef<
58
- RNView,
59
- TouchableProps
60
- >((touchableProps, ref) => {
14
+ export * from './types'
15
+
16
+ export const Touchable = forwardRef<RNView, TouchableProps>((touchableProps, ref) => {
61
17
  const {
62
- variants = [],
63
18
  children,
64
19
  onPress,
65
20
  style,
@@ -68,7 +23,6 @@ const _Touchable = forwardRef<
68
23
  debounce,
69
24
  leadingDebounce,
70
25
  noFeedback,
71
- styles,
72
26
  setPressed,
73
27
  rippleDisabled,
74
28
  analyticsEnabled,
@@ -77,7 +31,7 @@ const _Touchable = forwardRef<
77
31
  dismissKeyboard,
78
32
  ...props
79
33
  } = {
80
- ...defaultProps,
34
+ ...Touchable.defaultProps,
81
35
  ...touchableProps,
82
36
  }
83
37
 
@@ -91,26 +45,17 @@ const _Touchable = forwardRef<
91
45
  }
92
46
  })
93
47
 
94
- const variantStyles = useDefaultComponentStyle<'u:Touchable', typeof TouchablePresets>('u:Touchable', {
95
- variants,
96
- transform: StyleSheet.flatten,
97
- rootElement: 'wrapper',
98
- styles,
99
- })
48
+ const styles = useStylesFor(Touchable.styleRegistryName, style)
100
49
 
101
- const { logger } = useCodeleapContext()
50
+ const { logger } = useGlobalContext()
102
51
 
103
52
  const press = () => {
104
- if (!onPress) {
105
- logger.warn('No onPress passed to touchable', {
106
- touchableProps,
107
- }, 'User Interaction')
108
- return
109
- }
53
+ if (!onPress) return
54
+
110
55
  const _onPress = () => {
111
56
  logger.log(
112
57
  `<${debugComponent || 'Touchable'}/> pressed`,
113
- debugName || variants,
58
+ debugName,
114
59
  'User interaction',
115
60
  )
116
61
  if (dismissKeyboard) {
@@ -123,8 +68,9 @@ const _Touchable = forwardRef<
123
68
  }
124
69
  }
125
70
 
126
- onPress && onPress()
71
+ onPress()
127
72
  }
73
+
128
74
  if (TypeGuards.isNumber(debounce)) {
129
75
  if (pressed.current) {
130
76
  return
@@ -139,10 +85,9 @@ const _Touchable = forwardRef<
139
85
  } else {
140
86
  _onPress()
141
87
  }
142
-
143
88
  }
144
89
 
145
- const _styles = StyleSheet.flatten([variantStyles.wrapper, props?.disabled && variantStyles['wrapper:disabled'], style])
90
+ const _styles = StyleSheet.flatten([styles?.wrapper, props?.disabled && styles?.['wrapper:disabled']])
146
91
 
147
92
  const disableFeedback = !onPress || noFeedback
148
93
 
@@ -150,7 +95,7 @@ const _Touchable = forwardRef<
150
95
  hightlightPropertyIn: 'backgroundColor',
151
96
  hightlightPropertyOut: 'backgroundColor',
152
97
  disabled: disableFeedback,
153
- feedbackConfig: variantStyles?.feedback,
98
+ feedbackConfig: styles?.feedback as TouchableFeedbackConfig,
154
99
  })
155
100
 
156
101
  const Wrapper = View
@@ -165,7 +110,6 @@ const _Touchable = forwardRef<
165
110
  'bottom!',
166
111
  'position!',
167
112
  'transform!',
168
- // 'flex!',
169
113
  ]
170
114
 
171
115
  const radiusKey = [
@@ -193,6 +137,7 @@ const _Touchable = forwardRef<
193
137
  return key.startsWith(k)
194
138
  }
195
139
  }
140
+
196
141
  Object.entries(_styles).forEach(([key, value]) => {
197
142
  if (radiusKey.some(k => match(k, key))) {
198
143
  wrapperStyle[key] = value
@@ -211,10 +156,12 @@ const _Touchable = forwardRef<
211
156
  pressableStyle[key] = value
212
157
  }
213
158
  })
159
+
214
160
  if (wrapperStyle.position === 'absolute') {
215
161
  pressableStyle.width = '100%'
216
162
  pressableStyle.height = '100%'
217
163
  }
164
+
218
165
  wrapperStyle.overflow = 'visible'
219
166
 
220
167
  return {
@@ -234,15 +181,12 @@ const _Touchable = forwardRef<
234
181
  const disableRipple = disableFeedback || rippleDisabled || Platform.OS !== 'android'
235
182
 
236
183
  return (
237
- <Wrapper style={[wrapperStyle]} hitSlop={hitSlop}>
184
+ <Wrapper style={wrapperStyle} hitSlop={hitSlop}>
238
185
  {!disableRipple ? (
239
186
  <PressableRipple
240
187
  onPress={press}
241
- style={[
242
- pressableStyle,
243
- variantStyles.pressable,
244
- ]}
245
188
  {...props}
189
+ style={[pressableStyle, styles?.pressable]}
246
190
  rippleFades={false}
247
191
  rippleDuration={350}
248
192
  rippleOpacity={0.1}
@@ -259,7 +203,7 @@ const _Touchable = forwardRef<
259
203
  style={({ pressed }) => ([
260
204
  pressableStyle,
261
205
  getFeedbackStyle(pressed),
262
- variantStyles.pressable,
206
+ styles?.pressable,
263
207
  ])}
264
208
  {...props}
265
209
  ref={ref}
@@ -269,10 +213,23 @@ const _Touchable = forwardRef<
269
213
  )}
270
214
  </Wrapper>
271
215
  )
272
- })
216
+ }) as StyledComponentWithProps<TouchableProps>
217
+
218
+ Touchable.styleRegistryName = 'Touchable'
219
+ Touchable.elements = ['wrapper', 'feedback', 'pressable']
220
+ Touchable.rootElement = 'wrapper'
273
221
 
274
- export const Touchable = _Touchable as ((props: TouchableProps) => JSX.Element) & {
275
- defaultProps: Partial<TouchableProps>
222
+ Touchable.withVariantTypes = <S extends AnyRecord>(styles: S) => {
223
+ return Touchable as (props: StyledComponentProps<TouchableProps, typeof styles>) => IJSX
276
224
  }
277
225
 
278
- Touchable.defaultProps = defaultProps
226
+ Touchable.defaultProps = {
227
+ debounce: 500,
228
+ noFeedback: false,
229
+ rippleDisabled: false,
230
+ analyticsEnabled: false,
231
+ analyticsName: null,
232
+ dismissKeyboard: true,
233
+ } as Partial<TouchableProps>
234
+
235
+ MobileStyleRegistry.registerComponent(Touchable)
@@ -1,4 +1,3 @@
1
- import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
1
  import { StylesOf } from '../../types'
3
2
  import { TouchableFeedbackConfig } from '../../utils'
4
3
 
@@ -7,11 +6,3 @@ export type TouchableComposition = 'wrapper' | 'wrapper:disabled' | 'feedback' |
7
6
  export type TouchableStylesGen<TCSS = any> = StylesOf<Exclude<TouchableComposition, 'feedback'>> & {
8
7
  feedback?: TouchableFeedbackConfig
9
8
  }
10
-
11
- const createTouchableStyle = createDefaultVariantFactory<
12
- TouchableComposition,
13
- TouchableStylesGen
14
- >()
15
-
16
- export const TouchablePresets = includePresets((styles) => createTouchableStyle(() => ({ wrapper: styles, pressable: styles })))
17
-
@@ -0,0 +1,27 @@
1
+ import { AnyFunction } from '@codeleap/common'
2
+ import { StyledProp } from '@codeleap/styles'
3
+ import { View as RNView, PressableProps } from 'react-native'
4
+ import { TouchableComposition } from './styles'
5
+
6
+ export type TouchableProps =
7
+ Omit<PressableProps, 'onPress' | 'children' | 'style'> &
8
+ {
9
+ component?: any
10
+ ref?: React.Ref<RNView>
11
+ debugName: string
12
+ activeOpacity?: number
13
+ debugComponent?: string
14
+ onPress?: AnyFunction
15
+ noFeedback?: boolean
16
+ debounce?: number
17
+ leadingDebounce?: boolean
18
+ setPressed?: (param: boolean) => void
19
+ rippleDisabled?: boolean
20
+ children?: React.ReactNode
21
+ style?: StyledProp<TouchableComposition>
22
+ analyticsEnabled?: boolean
23
+ analyticsName?: string
24
+ analyticsData?: Record<string, any>
25
+ dismissKeyboard?: boolean
26
+ disabled?: boolean
27
+ }