@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.
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/mobile",
3
- "version": "3.24.2",
3
+ "version": "3.25.0",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -18,6 +18,7 @@
18
18
  },
19
19
  "peerDependencies": {
20
20
  "@codeleap/common": "*",
21
+ "@codeleap/styles": "*",
21
22
  "@react-native-community/async-storage": "1.12.1",
22
23
  "@react-native-firebase/messaging": "14.4.0",
23
24
  "@react-navigation/bottom-tabs": "6.5.3",
@@ -28,7 +29,7 @@
28
29
  "react": "18.1.0",
29
30
  "react-native": "0.73.8",
30
31
  "react-native-calendars": "1.1293.0",
31
- "react-native-date-picker": "^4.2.13",
32
+ "react-native-date-picker": "4.2.13",
32
33
  "react-native-device-info": "10.3.0",
33
34
  "react-native-fast-image": "8.6.3",
34
35
  "react-native-gesture-handler": "2.9.0",
@@ -37,12 +38,13 @@
37
38
  "react-native-image-viewing": "0.2.2",
38
39
  "react-native-keyboard-aware-scroll-view": "0.9.5",
39
40
  "typescript": "5.0.4",
40
- "react-native-avoid-softinput": "^3.1.5"
41
+ "react-native-avoid-softinput": "3.1.5",
42
+ "react-native-mmkv": "2.12.2"
41
43
  },
42
44
  "dependencies": {
43
45
  "@gorhom/portal": "1.0.14",
44
46
  "@miblanchard/react-native-slider": "2.3.1",
45
- "date-fns": "^2.29.3",
47
+ "date-fns": "2.29.3",
46
48
  "react-native-masked-text": "1.13.0",
47
49
  "react-native-uuid": "2.0.1"
48
50
  }
@@ -0,0 +1,52 @@
1
+ import { AnyStyledComponent, CodeleapStyleRegistry, ICSS, StylePersistor } from '@codeleap/styles'
2
+ import { StyleSheet } from 'react-native'
3
+ import { MMKV } from 'react-native-mmkv'
4
+
5
+ const mmkvStorage = new MMKV()
6
+
7
+ const persistor = new StylePersistor({
8
+ set(key, value) {
9
+ return mmkvStorage?.set(key, value)
10
+ },
11
+ get(key) {
12
+ return mmkvStorage?.getString(key)
13
+ },
14
+ del(key) {
15
+ return mmkvStorage?.delete(key)
16
+ },
17
+ })
18
+
19
+ let instance: MobileStyleRegistry
20
+
21
+ const components: CodeleapStyleRegistry['components'][string][] = []
22
+
23
+ export class MobileStyleRegistry extends CodeleapStyleRegistry {
24
+ constructor() {
25
+ super(persistor)
26
+
27
+ components.forEach((component) => {
28
+ this.registerComponent(component)
29
+ })
30
+
31
+ if (!instance) {
32
+ instance = this
33
+ }
34
+
35
+ return instance
36
+ }
37
+
38
+ createStyle(css: ICSS): ICSS {
39
+ return StyleSheet.create({ s: css }).s
40
+ }
41
+
42
+ static get current() {
43
+ return instance
44
+ }
45
+
46
+ static registerComponent(component: AnyStyledComponent) {
47
+ components.push(component)
48
+ if (instance) {
49
+ instance.registerComponent(component)
50
+ }
51
+ }
52
+ }
@@ -1,45 +1,63 @@
1
- import { ComponentVariants, getNestedStylesByKey, useDefaultComponentStyle } from '@codeleap/common'
2
1
  import React from 'react'
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
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'
19
12
 
20
13
  export const ActionIcon = (props: ActionIconProps) => {
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>
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
39
56
  }
40
57
 
41
58
  ActionIcon.defaultProps = {
42
59
  hitSlop: 10,
43
- }
60
+ badge: false,
61
+ } as Partial<ActionIconProps>
44
62
 
45
- export * from './styles'
63
+ MobileStyleRegistry.registerComponent(ActionIcon)
@@ -1,10 +1,8 @@
1
- import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
1
  import { BadgeComposition } from '../Badge'
3
2
  import { TouchableComposition } from '../Touchable'
4
3
 
5
4
  export type ActionIconParts = 'icon' | `touchable${Capitalize<TouchableComposition>}` | `badge${Capitalize<BadgeComposition>}`
5
+
6
6
  export type ActionIconStates = ':disabled' | ''
7
- export type ActionIconComposition = `${ActionIconParts}${ActionIconStates}`
8
- const createActionIconStyle = createDefaultVariantFactory<ActionIconComposition>()
9
7
 
10
- export const ActionIconPresets = includePresets((style) => createActionIconStyle(() => ({ touchableWrapper: style })))
8
+ export type ActionIconComposition = `${ActionIconParts}${ActionIconStates}`
@@ -0,0 +1,15 @@
1
+ import { AppIcon, StyledProp } from '@codeleap/styles'
2
+ import { BadgeComponentProps } from '../Badge'
3
+ import { IconProps } from '../Icon'
4
+ import { TouchableProps } from '../Touchable'
5
+ import { ActionIconComposition } from './styles'
6
+
7
+ export type ActionIconProps =
8
+ Omit<TouchableProps, 'style'> &
9
+ BadgeComponentProps &
10
+ {
11
+ iconProps?: Partial<IconProps>
12
+ icon?: AppIcon
13
+ name?: AppIcon
14
+ style?: StyledProp<ActionIconComposition>
15
+ }
@@ -1,70 +1,48 @@
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'
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'
15
8
 
16
9
  export * from './styles'
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
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
+ )
23
37
  }
24
38
 
25
- type TActivityIndicator = ComponentWithDefaultProps<ActivityIndicatorProps>
26
-
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()
39
+ ActivityIndicator.styleRegistryName = 'ActivityIndicator'
40
+ ActivityIndicator.elements = ['wrapper']
41
+ ActivityIndicator.rootElement = 'wrapper'
42
+ ActivityIndicator.defaultProps = {} as Partial<ActionIconProps>
48
43
 
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}/>),
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)
70
46
  }
47
+
48
+ MobileStyleRegistry.registerComponent(ActivityIndicator)
@@ -1,11 +1,2 @@
1
- import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
1
 
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 })))
2
+ export type ActivityIndicatorComposition = 'wrapper'
@@ -0,0 +1,9 @@
1
+ import { PropsOf } from '@codeleap/common'
2
+ import { StyledProp } from '@codeleap/styles'
3
+ import { ActivityIndicator as RNActivityIndicator } from 'react-native'
4
+ import { ActivityIndicatorComposition } from './styles'
5
+
6
+ export type ActivityIndicatorProps<T extends React.ComponentType = typeof RNActivityIndicator> = {
7
+ style?: StyledProp<ActivityIndicatorComposition>
8
+ component?: T
9
+ } & PropsOf<T>
@@ -1,20 +1,16 @@
1
- import {
2
- useDefaultComponentStyle,
3
- TypeGuards,
4
- useNestedStylesByKey,
5
- FormTypes,
6
- onMount,
7
- useSearch,
8
- } from '@codeleap/common'
9
1
  import React, { useCallback } from 'react'
10
- import { StyleSheet } from 'react-native'
2
+ import { TypeGuards, FormTypes, onMount, useSearch } from '@codeleap/common'
11
3
  import { List } from '../List'
12
- import { SearchInput } from '../TextInput'
13
- import { AutocompletePresets } from './styles'
4
+ import { SearchInput } from '../SearchInput'
14
5
  import { AutocompleteProps } from './types'
15
6
  import { Button } from '../Button'
16
7
  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
+
17
12
  export * from './styles'
13
+ export * from './types'
18
14
 
19
15
  const defaultFilterFunction = (search: string, options: FormTypes.Options<any>) => {
20
16
  return options.filter((option) => {
@@ -26,51 +22,40 @@ const defaultFilterFunction = (search: string, options: FormTypes.Options<any>)
26
22
  })
27
23
  }
28
24
 
29
- const defaultProps: Partial<AutocompleteProps<any, boolean>> = {
30
- getLabel(option) {
31
-
32
- if (TypeGuards.isArray(option)) {
25
+ const defaultGetLabel = (option) => {
26
+ if (TypeGuards.isArray(option)) {
27
+ if (option.length === 0) return null
33
28
 
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,
29
+ return option.map(o => o.label).join(', ')
30
+ } else {
31
+ if (!option) return null
32
+ return option?.label
33
+ }
46
34
  }
47
35
 
48
36
  export const Autocomplete = <T extends string | number = string, Multi extends boolean = false>(autocomplete: AutocompleteProps<T, Multi>) => {
49
37
  const allProps = {
50
- ...defaultProps,
38
+ ...Autocomplete.defaultProps,
51
39
  ...autocomplete,
52
40
  }
53
41
 
54
42
  const {
55
43
  value,
56
44
  onValueChange,
57
- styles = {},
58
45
  options = [],
59
- variants,
60
46
  renderItem,
61
-
62
47
  debugName,
63
- placeholder = 'Select',
48
+ placeholder,
64
49
  itemProps = {},
65
- searchable = true,
50
+ searchable,
66
51
  loadOptions,
67
- multiple = false,
52
+ multiple,
68
53
  limit = null,
69
54
  defaultOptions = options,
70
55
  onLoadOptionsError,
71
56
  selectedIcon,
72
57
  loadOptionsOnMount = defaultOptions.length === 0,
73
- selectable = false,
58
+ selectable,
74
59
  searchComponent,
75
60
  filterItems = defaultFilterFunction,
76
61
  searchInputProps: searchProps = {},
@@ -108,21 +93,13 @@ export const Autocomplete = <T extends string | number = string, Multi extends b
108
93
  }
109
94
  })
110
95
 
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)
96
+ const styles = useStylesFor(Autocomplete.styleRegistryName, style)
119
97
 
120
- const listStyles = useNestedStylesByKey('list', variantStyles)
98
+ const compositionStyles = useCompositionStyles(['item', 'list', 'searchInput'], styles)
121
99
 
122
100
  const currentOptions = searchable ? filteredOptions : defaultOptions
123
101
 
124
102
  const select = (selectedValue) => {
125
-
126
103
  let newValue = null
127
104
 
128
105
  let newOption = null
@@ -163,13 +140,11 @@ export const Autocomplete = <T extends string | number = string, Multi extends b
163
140
  } else {
164
141
  setLabelOptions([newOption])
165
142
  }
166
-
167
143
  }
168
144
 
169
145
  const Item = renderItem || Button
170
146
 
171
147
  const renderListItem = useCallback(({ item }) => {
172
-
173
148
  let selected = false
174
149
 
175
150
  if (multiple && isValueArray) {
@@ -193,7 +168,7 @@ export const Autocomplete = <T extends string | number = string, Multi extends b
193
168
  rightIcon={selectedIcon}
194
169
  // @ts-ignore
195
170
  icon={selectedIcon}
196
- styles={itemStyles}
171
+ style={compositionStyles?.item}
197
172
  {...itemProps}
198
173
  />
199
174
  }, [value, select, multiple, selectable, isValueArray])
@@ -202,7 +177,7 @@ export const Autocomplete = <T extends string | number = string, Multi extends b
202
177
 
203
178
  const showLoading = TypeGuards.isFunction(loadingProp) ? loadingProp(loading) : (loadingProp || loading)
204
179
 
205
- return <View style={[variantStyles.wrapper, style]}>
180
+ return <View style={styles?.wrapper}>
206
181
  <Search
207
182
  placeholder={placeholder}
208
183
  debugName={debugName}
@@ -215,13 +190,14 @@ export const Autocomplete = <T extends string | number = string, Multi extends b
215
190
  onSearchChange={onChangeSearch}
216
191
  hideErrorMessage
217
192
  {...searchProps}
193
+ style={compositionStyles?.searchInput}
218
194
  />
219
195
 
220
- <List<any>
196
+ <List
221
197
  data={searchable ? filteredOptions : options}
222
198
  scrollEnabled={false}
223
199
  showsHorizontalScrollIndicator={false}
224
- styles={listStyles}
200
+ style={compositionStyles?.list}
225
201
  // @ts-ignore
226
202
  keyExtractor={(i) => i.value}
227
203
  renderItem={renderListItem}
@@ -233,7 +209,23 @@ export const Autocomplete = <T extends string | number = string, Multi extends b
233
209
  </View>
234
210
  }
235
211
 
236
- export * from './styles'
237
- export * from './types'
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>>
238
230
 
239
- Autocomplete.defaultProps = defaultProps
231
+ MobileStyleRegistry.registerComponent(Autocomplete)
@@ -1,5 +1,6 @@
1
- import { ButtonComposition, createDefaultVariantFactory, includePresets, TextInputComposition } from '@codeleap/common'
1
+ import { ButtonComposition } from '../Button'
2
2
  import { ListComposition } from '../List'
3
+ import { TextInputComposition } from '../TextInput'
3
4
 
4
5
  type ItemStates = '' | ':selected'
5
6
 
@@ -12,7 +13,3 @@ export type AutocompleteComposition =
12
13
  `list${Capitalize<ListComposition>}` |
13
14
  `item${Capitalize<ItemComposition>}` |
14
15
  `searchInput${Capitalize<TextInputComposition>}`
15
-
16
- const createSelectStyle = createDefaultVariantFactory<AutocompleteComposition>()
17
-
18
- export const AutocompletePresets = includePresets((style) => createSelectStyle(() => ({ wrapper: style })))
@@ -1,22 +1,17 @@
1
- import {
2
- ComponentVariants,
3
- FormTypes,
4
- IconPlaceholder,
5
- PropsOf,
6
- } from '@codeleap/common'
7
- import { AutocompletePresets } from '.'
1
+ import { FormTypes, PropsOf } from '@codeleap/common'
8
2
  import { StylesOf } from '../../types/utility'
9
3
  import { GetKeyboardAwarePropsOptions } from '../../utils'
10
4
  import { Icon } from '../Icon'
11
5
  import { FlatListProps } from '../List'
12
6
  import { Text } from '../Text'
13
- import { SearchInputProps, TextInputProps } from '../TextInput'
7
+ import { SearchInputProps } from '../SearchInput'
14
8
  import { Touchable } from '../Touchable'
15
- import { AutocompleteComposition } from './styles'
16
9
  import { EmptyPlaceholderProps } from '../EmptyPlaceholder'
10
+ import { AppIcon, StyledProp } from '@codeleap/styles'
11
+ import { AutocompleteComposition } from './styles'
17
12
 
18
13
  export type AutocompleteRenderFNProps<T> = {
19
- styles: StylesOf<AutocompleteComposition>
14
+ style?: StylesOf<AutocompleteComposition>
20
15
  onPress: () => void
21
16
  isSelected?: boolean
22
17
  item: FormTypes.Options<T>[number]
@@ -48,21 +43,20 @@ export type ReplaceAutocompleteProps<Props, T, Multi extends boolean = false> =
48
43
  keyof ValueBoundAutocompleteProps<T, Multi>
49
44
  > & ValueBoundAutocompleteProps<T, Multi>
50
45
 
51
- export type AutocompleteProps<T = any, Multi extends boolean = false> = {
46
+ export type AutocompleteProps<T = any, Multi extends boolean = false> =
47
+ Omit<FlatListProps<T>, 'renderItem' | 'style'> &
48
+ ValueBoundAutocompleteProps<T, Multi> &
49
+ {
52
50
  placeholder?: string
53
51
  label?: FormTypes.Label
54
- styles?: StylesOf<AutocompleteComposition>
55
- style?: TextInputProps['style']
56
52
  closeOnSelect?: boolean
57
-
53
+ style?: StyledProp<AutocompleteComposition>
58
54
  keyboardAware?: GetKeyboardAwarePropsOptions
59
55
  multiple?: Multi
60
- itemProps?: Partial<
61
- Pick<AutocompleteRenderFNProps<any>, 'iconProps'|'textProps'|'touchableProps'
62
- >>
56
+ itemProps?: Partial<Pick<AutocompleteRenderFNProps<any>, 'iconProps' | 'textProps' | 'touchableProps'>>
63
57
  searchable?: boolean
64
58
  limit?: number
65
- selectedIcon?: IconPlaceholder
59
+ selectedIcon?: AppIcon
66
60
  loadOptionsOnMount?: boolean
67
61
  loadOptionsOnOpen?: boolean
68
62
  selectable?: boolean
@@ -70,10 +64,6 @@ export type AutocompleteProps<T = any, Multi extends boolean = false> = {
70
64
  debugName: string
71
65
  searchComponent?: React.ComponentType<SearchInputProps>
72
66
  listPlaceholder?: Partial<EmptyPlaceholderProps>
73
- listProps?: Partial<Omit<FlatListProps<T>, 'renderItem'|'styles'|'style'>>
67
+ listProps?: Partial<Omit<FlatListProps<T>, 'renderItem' | 'style'>>
74
68
  loading: boolean | ((isLoading: boolean) => boolean)
75
69
  }
76
- & Omit<FlatListProps<T>, 'renderItem'|'styles'|'style'>
77
- & ComponentVariants<typeof AutocompletePresets>
78
- & ValueBoundAutocompleteProps<T, Multi>
79
-