@codeleap/mobile 3.25.0 → 3.25.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/package.json +4 -6
  2. package/src/components/ActionIcon/index.tsx +37 -55
  3. package/src/components/ActionIcon/styles.ts +4 -2
  4. package/src/components/ActivityIndicator/index.tsx +64 -42
  5. package/src/components/ActivityIndicator/styles.ts +10 -1
  6. package/src/components/Autocomplete/index.tsx +54 -46
  7. package/src/components/Autocomplete/styles.ts +5 -2
  8. package/src/components/Autocomplete/types.ts +23 -13
  9. package/src/components/Avatar/index.tsx +71 -59
  10. package/src/components/Avatar/styles.ts +9 -1
  11. package/src/components/AvatarGroup/index.tsx +44 -30
  12. package/src/components/AvatarGroup/styles.ts +6 -0
  13. package/src/components/Backdrop/index.tsx +34 -51
  14. package/src/components/Backdrop/styles.ts +10 -5
  15. package/src/components/Badge/index.tsx +62 -36
  16. package/src/components/Badge/styles.ts +11 -3
  17. package/src/components/Button/index.tsx +82 -55
  18. package/src/components/Button/styles.ts +14 -13
  19. package/src/components/Calendar/index.tsx +29 -35
  20. package/src/components/Calendar/style.ts +6 -0
  21. package/src/components/Checkbox/index.tsx +64 -43
  22. package/src/components/Checkbox/styles.ts +6 -1
  23. package/src/components/ContentView/index.tsx +63 -0
  24. package/src/components/ContentView/styles.ts +8 -0
  25. package/src/components/DatePickerModal/index.tsx +65 -50
  26. package/src/components/DatePickerModal/styles.ts +10 -9
  27. package/src/components/DatePickerModal/types.ts +54 -36
  28. package/src/components/Drawer/index.tsx +28 -0
  29. package/src/components/Drawer/styles.ts +8 -0
  30. package/src/components/EmptyPlaceholder/index.tsx +63 -40
  31. package/src/components/EmptyPlaceholder/styles.ts +5 -0
  32. package/src/components/FileInput/index.tsx +49 -11
  33. package/src/components/FileInput/styles.ts +8 -0
  34. package/src/components/Grid/index.tsx +116 -84
  35. package/src/components/Grid/styles.ts +5 -0
  36. package/src/components/Icon/index.tsx +79 -44
  37. package/src/components/Icon/styles.ts +6 -0
  38. package/src/components/Image/index.tsx +78 -58
  39. package/src/components/Image/styles.ts +6 -1
  40. package/src/components/ImageView/Spotlight.tsx +4 -1
  41. package/src/components/ImageView/component.tsx +2 -1
  42. package/src/components/InputBase/index.tsx +24 -33
  43. package/src/components/InputBase/styles.ts +75 -66
  44. package/src/components/InputBase/types.ts +4 -3
  45. package/src/components/InputBase/utils.ts +4 -6
  46. package/src/components/InputLabel/index.tsx +38 -0
  47. package/src/components/InputLabel/styles.ts +7 -0
  48. package/src/components/List/PaginationIndicator.tsx +54 -0
  49. package/src/components/List/index.tsx +151 -99
  50. package/src/components/List/styles.ts +6 -0
  51. package/src/components/LoadingOverlay/index.tsx +29 -42
  52. package/src/components/LoadingOverlay/styles.ts +7 -7
  53. package/src/components/Modal/index.tsx +127 -80
  54. package/src/components/Modal/styles.ts +8 -0
  55. package/src/components/Navigation/Navigation.tsx +0 -1
  56. package/src/components/Navigation/types.ts +9 -2
  57. package/src/components/NumberIncrement/index.tsx +60 -50
  58. package/src/components/NumberIncrement/styles.ts +5 -0
  59. package/src/components/NumberIncrement/types.ts +39 -32
  60. package/src/components/Pager/index.tsx +94 -42
  61. package/src/components/Pager/styles.ts +13 -1
  62. package/src/components/RadioInput/index.tsx +57 -32
  63. package/src/components/RadioInput/styles.ts +7 -5
  64. package/src/components/RefreshControl/index.tsx +19 -39
  65. package/src/components/RefreshControl/styles.ts +6 -1
  66. package/src/components/Scroll/index.tsx +105 -89
  67. package/src/components/Scroll/styles.ts +5 -0
  68. package/src/components/Sections/index.tsx +161 -111
  69. package/src/components/Sections/styles.ts +5 -0
  70. package/src/components/SegmentedControl/Option.tsx +31 -46
  71. package/src/components/SegmentedControl/index.tsx +121 -86
  72. package/src/components/SegmentedControl/styles.ts +22 -15
  73. package/src/components/Select/index.tsx +82 -71
  74. package/src/components/Select/styles.ts +5 -3
  75. package/src/components/Select/types.ts +25 -20
  76. package/src/components/Slider/index.tsx +43 -58
  77. package/src/components/Slider/styles.ts +6 -15
  78. package/src/components/Slider/types.ts +14 -9
  79. package/src/components/Switch/index.tsx +56 -43
  80. package/src/components/Switch/styles.ts +7 -1
  81. package/src/components/Text/index.tsx +52 -56
  82. package/src/components/Text/styles.ts +7 -1
  83. package/src/components/TextInput/index.tsx +162 -49
  84. package/src/components/TextInput/styles.ts +8 -2
  85. package/src/components/Touchable/index.tsx +87 -44
  86. package/src/components/Touchable/styles.ts +9 -0
  87. package/src/components/View/index.tsx +92 -23
  88. package/src/components/View/styles.ts +6 -0
  89. package/src/components/components.ts +6 -2
  90. package/src/components/defaultStyles.ts +77 -0
  91. package/src/index.ts +0 -2
  92. package/src/modules/PressableRipple/type.ts +0 -1
  93. package/src/utils/KeyboardAware/context.tsx +2 -0
  94. package/src/utils/KeyboardAware/keyboardHooks.ts +2 -1
  95. package/src/utils/ModalManager/components.tsx +30 -1
  96. package/src/utils/ModalManager/context.tsx +4 -4
  97. package/src/utils/ModalManager/index.ts +4 -1
  98. package/src/utils/hooks.ts +1 -12
  99. package/src/Registry.ts +0 -52
  100. package/src/components/ActionIcon/types.ts +0 -15
  101. package/src/components/ActivityIndicator/types.ts +0 -9
  102. package/src/components/Avatar/types.ts +0 -23
  103. package/src/components/AvatarGroup/types.ts +0 -10
  104. package/src/components/Backdrop/types.ts +0 -14
  105. package/src/components/Badge/types.ts +0 -27
  106. package/src/components/Button/types.ts +0 -20
  107. package/src/components/Checkbox/types.ts +0 -13
  108. package/src/components/EmptyPlaceholder/types.ts +0 -21
  109. package/src/components/FileInput/types.ts +0 -27
  110. package/src/components/Grid/types.ts +0 -20
  111. package/src/components/Icon/types.ts +0 -15
  112. package/src/components/Image/types.ts +0 -18
  113. package/src/components/List/types.ts +0 -41
  114. package/src/components/LoadingOverlay/types.ts +0 -9
  115. package/src/components/Modal/types.ts +0 -41
  116. package/src/components/Pager/types.ts +0 -37
  117. package/src/components/PaginationIndicator/index.tsx +0 -51
  118. package/src/components/PaginationIndicator/styles.ts +0 -3
  119. package/src/components/PaginationIndicator/types.ts +0 -10
  120. package/src/components/RadioInput/types.ts +0 -31
  121. package/src/components/RefreshControl/types.ts +0 -9
  122. package/src/components/Scroll/types.ts +0 -21
  123. package/src/components/SearchInput/index.tsx +0 -90
  124. package/src/components/Sections/types.ts +0 -39
  125. package/src/components/SegmentedControl/types.ts +0 -31
  126. package/src/components/Switch/types.ts +0 -12
  127. package/src/components/Text/types.ts +0 -18
  128. package/src/components/TextInput/types.ts +0 -23
  129. package/src/components/Touchable/types.ts +0 -27
  130. package/src/components/View/types.ts +0 -13
  131. package/src/hooks/index.ts +0 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/mobile",
3
- "version": "3.25.0",
3
+ "version": "3.25.3",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -18,7 +18,6 @@
18
18
  },
19
19
  "peerDependencies": {
20
20
  "@codeleap/common": "*",
21
- "@codeleap/styles": "*",
22
21
  "@react-native-community/async-storage": "1.12.1",
23
22
  "@react-native-firebase/messaging": "14.4.0",
24
23
  "@react-navigation/bottom-tabs": "6.5.3",
@@ -29,7 +28,7 @@
29
28
  "react": "18.1.0",
30
29
  "react-native": "0.73.8",
31
30
  "react-native-calendars": "1.1293.0",
32
- "react-native-date-picker": "4.2.13",
31
+ "react-native-date-picker": "^4.2.13",
33
32
  "react-native-device-info": "10.3.0",
34
33
  "react-native-fast-image": "8.6.3",
35
34
  "react-native-gesture-handler": "2.9.0",
@@ -38,13 +37,12 @@
38
37
  "react-native-image-viewing": "0.2.2",
39
38
  "react-native-keyboard-aware-scroll-view": "0.9.5",
40
39
  "typescript": "5.0.4",
41
- "react-native-avoid-softinput": "3.1.5",
42
- "react-native-mmkv": "2.12.2"
40
+ "react-native-avoid-softinput": "^3.1.5"
43
41
  },
44
42
  "dependencies": {
45
43
  "@gorhom/portal": "1.0.14",
46
44
  "@miblanchard/react-native-slider": "2.3.1",
47
- "date-fns": "2.29.3",
45
+ "date-fns": "^2.29.3",
48
46
  "react-native-masked-text": "1.13.0",
49
47
  "react-native-uuid": "2.0.1"
50
48
  }
@@ -1,63 +1,45 @@
1
+ import { ComponentVariants, getNestedStylesByKey, useDefaultComponentStyle } from '@codeleap/common'
1
2
  import React from 'react'
2
- import { AnyRecord, IJSX, StyledComponentProps, useCompositionStyles } from '@codeleap/styles'
3
- import { MobileStyleRegistry } from '../../Registry'
4
- import { Badge } from '../Badge'
5
- import { Icon } from '../Icon'
6
- import { Touchable } from '../Touchable'
7
- import { ActionIconProps } from './types'
8
- import { useStylesFor } from '../../hooks'
9
-
10
- export * from './styles'
11
- export * from './types'
3
+ import { StyleSheet } from 'react-native'
4
+ import { StylesOf } from '../../types'
5
+ import { Badge, BadgeComponentProps } from '../Badge'
6
+ import { Icon, IconProps } from '../Icon'
7
+ import { Touchable, TouchableProps } from '../Touchable'
8
+ import { ActionIconComposition, ActionIconPresets } from './styles'
9
+
10
+ /** * IconButton */
11
+ export type ActionIconProps= {
12
+ iconProps?: Partial<IconProps>
13
+ /** prop */
14
+ icon?: IconProps['name']
15
+ /** prop */
16
+ name?: IconProps['name']
17
+ styles?: StylesOf<ActionIconComposition> | StylesOf<ActionIconComposition>[]
18
+ } & Omit<TouchableProps, 'styles' | 'variants'> & ComponentVariants<typeof ActionIconPresets> & BadgeComponentProps
12
19
 
13
20
  export const ActionIcon = (props: ActionIconProps) => {
14
- const {
15
- name,
16
- icon,
17
- iconProps,
18
- children,
19
- badge,
20
- badgeProps = {},
21
- style,
22
- ...touchableProps
23
- } = {
24
- ...ActionIcon.defaultProps,
25
- ...props,
26
- }
27
-
28
- const styles = useStylesFor(ActionIcon.styleRegistryName, style)
29
-
30
- const compositionStyles = useCompositionStyles(['badge', 'touchable'], styles)
31
-
32
- return (
33
- <Touchable {...touchableProps} style={compositionStyles?.touchable}>
34
- <Icon
35
- name={icon ?? name}
36
- {...iconProps}
37
- style={[
38
- styles.icon,
39
- touchableProps?.disabled && styles['icon:disabled'],
40
- ]}
41
- />
42
-
43
- {children}
44
-
45
- <Badge badge={badge} {...badgeProps} style={compositionStyles?.badge} />
46
- </Touchable>
47
- )
48
- }
49
-
50
- ActionIcon.styleRegistryName = 'ActionIcon'
51
- ActionIcon.elements = ['icon', 'touchable', 'badge']
52
- ActionIcon.rootElement = 'touchableWrapper'
53
-
54
- ActionIcon.withVariantTypes = <S extends AnyRecord>(styles: S) => {
55
- return ActionIcon as (props: StyledComponentProps<ActionIconProps, typeof styles>) => IJSX
21
+ const { name, icon, iconProps, variants, styles, children, badge = false, badgeProps = {}, ...touchableProps } = props
22
+ const variantStyles = useDefaultComponentStyle<'u:ActionIcon', typeof ActionIconPresets>('u:ActionIcon', {
23
+ variants, styles, transform: StyleSheet.flatten,
24
+ })
25
+ const touchableStyles = getNestedStylesByKey('touchable', variantStyles)
26
+
27
+ const badgeStyles = getNestedStylesByKey('badge', variantStyles)
28
+
29
+ return <Touchable styles={touchableStyles} {...touchableProps}>
30
+ <Icon name={icon ?? name} style={
31
+ [
32
+ variantStyles.icon,
33
+ touchableProps?.disabled && variantStyles['icon:disabled'],
34
+ ]} {...iconProps}/>
35
+ {children}
36
+
37
+ <Badge badge={badge} style={badgeStyles} {...badgeProps} />
38
+ </Touchable>
56
39
  }
57
40
 
58
41
  ActionIcon.defaultProps = {
59
42
  hitSlop: 10,
60
- badge: false,
61
- } as Partial<ActionIconProps>
43
+ }
62
44
 
63
- MobileStyleRegistry.registerComponent(ActionIcon)
45
+ export * from './styles'
@@ -1,8 +1,10 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
1
2
  import { BadgeComposition } from '../Badge'
2
3
  import { TouchableComposition } from '../Touchable'
3
4
 
4
5
  export type ActionIconParts = 'icon' | `touchable${Capitalize<TouchableComposition>}` | `badge${Capitalize<BadgeComposition>}`
5
-
6
6
  export type ActionIconStates = ':disabled' | ''
7
-
8
7
  export type ActionIconComposition = `${ActionIconParts}${ActionIconStates}`
8
+ const createActionIconStyle = createDefaultVariantFactory<ActionIconComposition>()
9
+
10
+ export const ActionIconPresets = includePresets((style) => createActionIconStyle(() => ({ touchableWrapper: style })))
@@ -1,48 +1,70 @@
1
- import React, { CSSProperties } from 'react'
2
- import { ActivityIndicator as RNActivityIndicator } from 'react-native'
3
- import { ActivityIndicatorProps } from './types'
4
- import { MobileStyleRegistry } from '../../Registry'
5
- import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
6
- import { useStylesFor } from '../../hooks'
7
- import { ActionIconProps } from '../ActionIcon'
1
+ import * as React from 'react'
2
+ import { forwardRef } from 'react'
3
+ import { ActivityIndicator as Indicator, ActivityIndicatorProps as IndicatorProps, StyleSheet } from 'react-native'
4
+ import {
5
+
6
+ useDefaultComponentStyle,
7
+ ComponentVariants,
8
+ useCodeleapContext,
9
+ } from '@codeleap/common'
10
+ import { ComponentWithDefaultProps, StylesOf } from '../../types'
11
+ import {
12
+ ActivityIndicatorComposition,
13
+ ActivityIndicatorPresets,
14
+ } from './styles'
8
15
 
9
16
  export * from './styles'
10
- export * from './types'
11
-
12
- export const ActivityIndicator = <T extends React.ComponentType = typeof RNActivityIndicator>(props: ActivityIndicatorProps<T>) => {
13
- const {
14
- style,
15
- component: Component = RNActivityIndicator,
16
- ...rest
17
- } = {
18
- ...ActivityIndicator.defaultProps,
19
- ...props,
20
- }
21
-
22
- const styles = useStylesFor(ActivityIndicator.styleRegistryName, style)
23
-
24
- const wrapperStyle = styles?.wrapper as CSSProperties
25
-
26
- const color = wrapperStyle?.color || '#000'
27
- const size = (wrapperStyle?.height || wrapperStyle?.width || 'large') as number
28
-
29
- return (
30
- <Component
31
- size={size}
32
- color={color}
33
- {...rest}
34
- style={styles?.wrapper}
35
- />
36
- )
17
+ export type ActivityIndicatorProps =
18
+ IndicatorProps
19
+ & {
20
+ variants?: ComponentVariants<typeof ActivityIndicatorPresets>['variants']
21
+ styles?: StylesOf<ActivityIndicatorComposition>
22
+ component?: (props: Omit<ActivityIndicatorProps & {ref?: React.Ref<Indicator>}, 'component'>) => JSX.Element
37
23
  }
38
24
 
39
- ActivityIndicator.styleRegistryName = 'ActivityIndicator'
40
- ActivityIndicator.elements = ['wrapper']
41
- ActivityIndicator.rootElement = 'wrapper'
42
- ActivityIndicator.defaultProps = {} as Partial<ActionIconProps>
25
+ type TActivityIndicator = ComponentWithDefaultProps<ActivityIndicatorProps>
43
26
 
44
- ActivityIndicator.withVariantTypes = <S extends AnyRecord>(styles: S) => {
45
- return ActivityIndicator as (<T extends React.ComponentType = typeof RNActivityIndicator>(props: StyledComponentProps<ActivityIndicatorProps<T>, typeof styles>) => IJSX)
46
- }
27
+ export const ActivityIndicator = forwardRef<Indicator, ActivityIndicatorProps>(
28
+ (activityIndicatorProps, ref) => {
29
+ const {
30
+ variants = [],
31
+ style = {},
32
+ styles: propStyles = {},
33
+ component = Indicator,
34
+ ...props
35
+ } = {
36
+ ...ActivityIndicator.defaultProps,
37
+ ...activityIndicatorProps,
38
+
39
+ }
40
+
41
+ const variantStyles = useDefaultComponentStyle('ActivityIndicator', {
42
+ variants,
43
+ transform: StyleSheet.flatten,
44
+ styles: propStyles,
45
+ })
46
+
47
+ const { Theme } = useCodeleapContext()
47
48
 
48
- MobileStyleRegistry.registerComponent(ActivityIndicator)
49
+ const styles = StyleSheet.flatten([variantStyles.wrapper, style])
50
+ const color = styles?.color || Theme.colors.gray
51
+ const size = styles?.height || styles?.width || 'large'
52
+
53
+ const Component = component
54
+
55
+ return (
56
+ <Component
57
+ size={size}
58
+ ref={ref}
59
+ color={color}
60
+ style={styles}
61
+ styles={styles}
62
+ {...props}
63
+ />
64
+ )
65
+ },
66
+ ) as TActivityIndicator
67
+
68
+ ActivityIndicator.defaultProps = {
69
+ component: forwardRef(({ size, color, style }, ref) => <Indicator size={size} color={color} style={style} ref={ref}/>),
70
+ }
@@ -1,2 +1,11 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
1
2
 
2
- export type ActivityIndicatorComposition = 'wrapper'
3
+ export type ActivityIndicatorComposition =
4
+ | 'wrapper'
5
+ | 'backCircle'
6
+ | 'frontCircle'
7
+ | 'circle'
8
+
9
+ const createActivityIndicatorStyle = createDefaultVariantFactory<ActivityIndicatorComposition>()
10
+
11
+ export const ActivityIndicatorPresets = includePresets((styles) => createActivityIndicatorStyle(() => ({ wrapper: styles })))
@@ -1,16 +1,20 @@
1
+ import {
2
+ useDefaultComponentStyle,
3
+ TypeGuards,
4
+ useNestedStylesByKey,
5
+ FormTypes,
6
+ onMount,
7
+ useSearch,
8
+ } from '@codeleap/common'
1
9
  import React, { useCallback } from 'react'
2
- import { TypeGuards, FormTypes, onMount, useSearch } from '@codeleap/common'
10
+ import { StyleSheet } from 'react-native'
3
11
  import { List } from '../List'
4
- import { SearchInput } from '../SearchInput'
12
+ import { SearchInput } from '../TextInput'
13
+ import { AutocompletePresets } from './styles'
5
14
  import { AutocompleteProps } from './types'
6
15
  import { Button } from '../Button'
7
16
  import { View } from '../View'
8
- import { AnyRecord, AppIcon, IJSX, StyledComponentProps, useCompositionStyles } from '@codeleap/styles'
9
- import { MobileStyleRegistry } from '../../Registry'
10
- import { useStylesFor } from '../../hooks'
11
-
12
17
  export * from './styles'
13
- export * from './types'
14
18
 
15
19
  const defaultFilterFunction = (search: string, options: FormTypes.Options<any>) => {
16
20
  return options.filter((option) => {
@@ -22,40 +26,51 @@ const defaultFilterFunction = (search: string, options: FormTypes.Options<any>)
22
26
  })
23
27
  }
24
28
 
25
- const defaultGetLabel = (option) => {
26
- if (TypeGuards.isArray(option)) {
27
- if (option.length === 0) return null
29
+ const defaultProps: Partial<AutocompleteProps<any, boolean>> = {
30
+ getLabel(option) {
28
31
 
29
- return option.map(o => o.label).join(', ')
30
- } else {
31
- if (!option) return null
32
- return option?.label
33
- }
32
+ if (TypeGuards.isArray(option)) {
33
+
34
+ if (option.length === 0) return null
35
+
36
+ return option.map(o => o.label).join(', ')
37
+
38
+ } else {
39
+ if (!option) return null
40
+ return option?.label
41
+ }
42
+ },
43
+ searchInputProps: {},
44
+ selectedIcon: 'check' as any,
45
+ searchComponent: SearchInput,
34
46
  }
35
47
 
36
48
  export const Autocomplete = <T extends string | number = string, Multi extends boolean = false>(autocomplete: AutocompleteProps<T, Multi>) => {
37
49
  const allProps = {
38
- ...Autocomplete.defaultProps,
50
+ ...defaultProps,
39
51
  ...autocomplete,
40
52
  }
41
53
 
42
54
  const {
43
55
  value,
44
56
  onValueChange,
57
+ styles = {},
45
58
  options = [],
59
+ variants,
46
60
  renderItem,
61
+
47
62
  debugName,
48
- placeholder,
63
+ placeholder = 'Select',
49
64
  itemProps = {},
50
- searchable,
65
+ searchable = true,
51
66
  loadOptions,
52
- multiple,
67
+ multiple = false,
53
68
  limit = null,
54
69
  defaultOptions = options,
55
70
  onLoadOptionsError,
56
71
  selectedIcon,
57
72
  loadOptionsOnMount = defaultOptions.length === 0,
58
- selectable,
73
+ selectable = false,
59
74
  searchComponent,
60
75
  filterItems = defaultFilterFunction,
61
76
  searchInputProps: searchProps = {},
@@ -93,13 +108,21 @@ export const Autocomplete = <T extends string | number = string, Multi extends b
93
108
  }
94
109
  })
95
110
 
96
- const styles = useStylesFor(Autocomplete.styleRegistryName, style)
111
+ const variantStyles = useDefaultComponentStyle<'u:Autocomplete', typeof AutocompletePresets>('u:Autocomplete', {
112
+ transform: StyleSheet.flatten,
113
+ rootElement: 'inputWrapper',
114
+ styles,
115
+ variants,
116
+ })
117
+
118
+ const itemStyles = useNestedStylesByKey('item', variantStyles)
97
119
 
98
- const compositionStyles = useCompositionStyles(['item', 'list', 'searchInput'], styles)
120
+ const listStyles = useNestedStylesByKey('list', variantStyles)
99
121
 
100
122
  const currentOptions = searchable ? filteredOptions : defaultOptions
101
123
 
102
124
  const select = (selectedValue) => {
125
+
103
126
  let newValue = null
104
127
 
105
128
  let newOption = null
@@ -140,11 +163,13 @@ export const Autocomplete = <T extends string | number = string, Multi extends b
140
163
  } else {
141
164
  setLabelOptions([newOption])
142
165
  }
166
+
143
167
  }
144
168
 
145
169
  const Item = renderItem || Button
146
170
 
147
171
  const renderListItem = useCallback(({ item }) => {
172
+
148
173
  let selected = false
149
174
 
150
175
  if (multiple && isValueArray) {
@@ -168,7 +193,7 @@ export const Autocomplete = <T extends string | number = string, Multi extends b
168
193
  rightIcon={selectedIcon}
169
194
  // @ts-ignore
170
195
  icon={selectedIcon}
171
- style={compositionStyles?.item}
196
+ styles={itemStyles}
172
197
  {...itemProps}
173
198
  />
174
199
  }, [value, select, multiple, selectable, isValueArray])
@@ -177,7 +202,7 @@ export const Autocomplete = <T extends string | number = string, Multi extends b
177
202
 
178
203
  const showLoading = TypeGuards.isFunction(loadingProp) ? loadingProp(loading) : (loadingProp || loading)
179
204
 
180
- return <View style={styles?.wrapper}>
205
+ return <View style={[variantStyles.wrapper, style]}>
181
206
  <Search
182
207
  placeholder={placeholder}
183
208
  debugName={debugName}
@@ -190,14 +215,13 @@ export const Autocomplete = <T extends string | number = string, Multi extends b
190
215
  onSearchChange={onChangeSearch}
191
216
  hideErrorMessage
192
217
  {...searchProps}
193
- style={compositionStyles?.searchInput}
194
218
  />
195
219
 
196
- <List
220
+ <List<any>
197
221
  data={searchable ? filteredOptions : options}
198
222
  scrollEnabled={false}
199
223
  showsHorizontalScrollIndicator={false}
200
- style={compositionStyles?.list}
224
+ styles={listStyles}
201
225
  // @ts-ignore
202
226
  keyExtractor={(i) => i.value}
203
227
  renderItem={renderListItem}
@@ -209,23 +233,7 @@ export const Autocomplete = <T extends string | number = string, Multi extends b
209
233
  </View>
210
234
  }
211
235
 
212
- Autocomplete.styleRegistryName = 'Autocomplete'
213
- Autocomplete.elements = ['wrapper', 'list', 'item', 'searchInput']
214
- Autocomplete.rootElement = 'wrapper'
215
-
216
- Autocomplete.withVariantTypes = <S extends AnyRecord>(styles: S) => {
217
- return Autocomplete as (<T extends string | number = string, Multi extends boolean = false>(props: StyledComponentProps<AutocompleteProps<T, Multi>, typeof styles>) => IJSX)
218
- }
219
-
220
- Autocomplete.defaultProps = {
221
- getLabel: defaultGetLabel,
222
- searchInputProps: {},
223
- selectedIcon: 'check' as AppIcon,
224
- searchComponent: SearchInput,
225
- placeholder: 'Select',
226
- searchable: true,
227
- multiple: false,
228
- selectable: false,
229
- } as Partial<AutocompleteProps<any, boolean>>
236
+ export * from './styles'
237
+ export * from './types'
230
238
 
231
- MobileStyleRegistry.registerComponent(Autocomplete)
239
+ Autocomplete.defaultProps = defaultProps
@@ -1,6 +1,5 @@
1
- import { ButtonComposition } from '../Button'
1
+ import { ButtonComposition, createDefaultVariantFactory, includePresets, TextInputComposition } from '@codeleap/common'
2
2
  import { ListComposition } from '../List'
3
- import { TextInputComposition } from '../TextInput'
4
3
 
5
4
  type ItemStates = '' | ':selected'
6
5
 
@@ -13,3 +12,7 @@ export type AutocompleteComposition =
13
12
  `list${Capitalize<ListComposition>}` |
14
13
  `item${Capitalize<ItemComposition>}` |
15
14
  `searchInput${Capitalize<TextInputComposition>}`
15
+
16
+ const createSelectStyle = createDefaultVariantFactory<AutocompleteComposition>()
17
+
18
+ export const AutocompletePresets = includePresets((style) => createSelectStyle(() => ({ wrapper: style })))
@@ -1,17 +1,22 @@
1
- import { FormTypes, PropsOf } from '@codeleap/common'
1
+ import {
2
+ ComponentVariants,
3
+ FormTypes,
4
+ IconPlaceholder,
5
+ PropsOf,
6
+ } from '@codeleap/common'
7
+ import { AutocompletePresets } from '.'
2
8
  import { StylesOf } from '../../types/utility'
3
9
  import { GetKeyboardAwarePropsOptions } from '../../utils'
4
10
  import { Icon } from '../Icon'
5
11
  import { FlatListProps } from '../List'
6
12
  import { Text } from '../Text'
7
- import { SearchInputProps } from '../SearchInput'
13
+ import { SearchInputProps, TextInputProps } from '../TextInput'
8
14
  import { Touchable } from '../Touchable'
9
- import { EmptyPlaceholderProps } from '../EmptyPlaceholder'
10
- import { AppIcon, StyledProp } from '@codeleap/styles'
11
15
  import { AutocompleteComposition } from './styles'
16
+ import { EmptyPlaceholderProps } from '../EmptyPlaceholder'
12
17
 
13
18
  export type AutocompleteRenderFNProps<T> = {
14
- style?: StylesOf<AutocompleteComposition>
19
+ styles: StylesOf<AutocompleteComposition>
15
20
  onPress: () => void
16
21
  isSelected?: boolean
17
22
  item: FormTypes.Options<T>[number]
@@ -43,20 +48,21 @@ export type ReplaceAutocompleteProps<Props, T, Multi extends boolean = false> =
43
48
  keyof ValueBoundAutocompleteProps<T, Multi>
44
49
  > & ValueBoundAutocompleteProps<T, Multi>
45
50
 
46
- export type AutocompleteProps<T = any, Multi extends boolean = false> =
47
- Omit<FlatListProps<T>, 'renderItem' | 'style'> &
48
- ValueBoundAutocompleteProps<T, Multi> &
49
- {
51
+ export type AutocompleteProps<T = any, Multi extends boolean = false> = {
50
52
  placeholder?: string
51
53
  label?: FormTypes.Label
54
+ styles?: StylesOf<AutocompleteComposition>
55
+ style?: TextInputProps['style']
52
56
  closeOnSelect?: boolean
53
- style?: StyledProp<AutocompleteComposition>
57
+
54
58
  keyboardAware?: GetKeyboardAwarePropsOptions
55
59
  multiple?: Multi
56
- itemProps?: Partial<Pick<AutocompleteRenderFNProps<any>, 'iconProps' | 'textProps' | 'touchableProps'>>
60
+ itemProps?: Partial<
61
+ Pick<AutocompleteRenderFNProps<any>, 'iconProps'|'textProps'|'touchableProps'
62
+ >>
57
63
  searchable?: boolean
58
64
  limit?: number
59
- selectedIcon?: AppIcon
65
+ selectedIcon?: IconPlaceholder
60
66
  loadOptionsOnMount?: boolean
61
67
  loadOptionsOnOpen?: boolean
62
68
  selectable?: boolean
@@ -64,6 +70,10 @@ export type AutocompleteProps<T = any, Multi extends boolean = false> =
64
70
  debugName: string
65
71
  searchComponent?: React.ComponentType<SearchInputProps>
66
72
  listPlaceholder?: Partial<EmptyPlaceholderProps>
67
- listProps?: Partial<Omit<FlatListProps<T>, 'renderItem' | 'style'>>
73
+ listProps?: Partial<Omit<FlatListProps<T>, 'renderItem'|'styles'|'style'>>
68
74
  loading: boolean | ((isLoading: boolean) => boolean)
69
75
  }
76
+ & Omit<FlatListProps<T>, 'renderItem'|'styles'|'style'>
77
+ & ComponentVariants<typeof AutocompletePresets>
78
+ & ValueBoundAutocompleteProps<T, Multi>
79
+