@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.
- package/package.json +6 -4
- package/src/Registry.ts +52 -0
- package/src/components/ActionIcon/index.tsx +55 -37
- package/src/components/ActionIcon/styles.ts +2 -4
- package/src/components/ActionIcon/types.ts +15 -0
- package/src/components/ActivityIndicator/index.tsx +42 -64
- package/src/components/ActivityIndicator/styles.ts +1 -10
- package/src/components/ActivityIndicator/types.ts +9 -0
- package/src/components/Autocomplete/index.tsx +46 -54
- package/src/components/Autocomplete/styles.ts +2 -5
- package/src/components/Autocomplete/types.ts +13 -23
- package/src/components/Avatar/index.tsx +59 -71
- package/src/components/Avatar/styles.ts +1 -9
- package/src/components/Avatar/types.ts +23 -0
- package/src/components/AvatarGroup/index.tsx +30 -44
- package/src/components/AvatarGroup/styles.ts +0 -6
- package/src/components/AvatarGroup/types.ts +10 -0
- package/src/components/Backdrop/index.tsx +51 -34
- package/src/components/Backdrop/styles.ts +5 -10
- package/src/components/Backdrop/types.ts +14 -0
- package/src/components/Badge/index.tsx +36 -62
- package/src/components/Badge/styles.ts +3 -11
- package/src/components/Badge/types.ts +27 -0
- package/src/components/Button/index.tsx +55 -82
- package/src/components/Button/styles.ts +13 -14
- package/src/components/Button/types.ts +20 -0
- package/src/components/Calendar/index.tsx +35 -29
- package/src/components/Checkbox/index.tsx +43 -64
- package/src/components/Checkbox/styles.ts +1 -6
- package/src/components/Checkbox/types.ts +13 -0
- package/src/components/DatePickerModal/index.tsx +50 -65
- package/src/components/DatePickerModal/styles.ts +9 -10
- package/src/components/DatePickerModal/types.ts +36 -54
- package/src/components/EmptyPlaceholder/index.tsx +40 -63
- package/src/components/EmptyPlaceholder/styles.ts +0 -5
- package/src/components/EmptyPlaceholder/types.ts +21 -0
- package/src/components/FileInput/index.tsx +11 -49
- package/src/components/FileInput/types.ts +27 -0
- package/src/components/Grid/index.tsx +84 -116
- package/src/components/Grid/styles.ts +0 -5
- package/src/components/Grid/types.ts +20 -0
- package/src/components/Icon/index.tsx +44 -79
- package/src/components/Icon/styles.ts +0 -6
- package/src/components/Icon/types.ts +15 -0
- package/src/components/Image/index.tsx +58 -78
- package/src/components/Image/styles.ts +1 -6
- package/src/components/Image/types.ts +18 -0
- package/src/components/ImageView/Spotlight.tsx +1 -4
- package/src/components/ImageView/component.tsx +1 -2
- package/src/components/InputBase/index.tsx +33 -24
- package/src/components/InputBase/styles.ts +66 -75
- package/src/components/InputBase/types.ts +3 -4
- package/src/components/InputBase/utils.ts +6 -4
- package/src/components/List/index.tsx +99 -151
- package/src/components/List/styles.ts +0 -6
- package/src/components/List/types.ts +41 -0
- package/src/components/LoadingOverlay/index.tsx +42 -29
- package/src/components/LoadingOverlay/styles.ts +7 -7
- package/src/components/LoadingOverlay/types.ts +9 -0
- package/src/components/Modal/index.tsx +80 -127
- package/src/components/Modal/styles.ts +0 -8
- package/src/components/Modal/types.ts +41 -0
- package/src/components/Navigation/Navigation.tsx +1 -0
- package/src/components/Navigation/types.ts +2 -9
- package/src/components/NumberIncrement/index.tsx +50 -60
- package/src/components/NumberIncrement/styles.ts +0 -5
- package/src/components/NumberIncrement/types.ts +32 -39
- package/src/components/Pager/index.tsx +42 -94
- package/src/components/Pager/styles.ts +1 -13
- package/src/components/Pager/types.ts +37 -0
- package/src/components/PaginationIndicator/index.tsx +51 -0
- package/src/components/PaginationIndicator/styles.ts +3 -0
- package/src/components/PaginationIndicator/types.ts +10 -0
- package/src/components/RadioInput/index.tsx +32 -57
- package/src/components/RadioInput/styles.ts +5 -7
- package/src/components/RadioInput/types.ts +31 -0
- package/src/components/RefreshControl/index.tsx +39 -19
- package/src/components/RefreshControl/styles.ts +1 -6
- package/src/components/RefreshControl/types.ts +9 -0
- package/src/components/Scroll/index.tsx +89 -105
- package/src/components/Scroll/styles.ts +0 -5
- package/src/components/Scroll/types.ts +21 -0
- package/src/components/SearchInput/index.tsx +90 -0
- package/src/components/Sections/index.tsx +111 -161
- package/src/components/Sections/styles.ts +0 -5
- package/src/components/Sections/types.ts +39 -0
- package/src/components/SegmentedControl/Option.tsx +46 -31
- package/src/components/SegmentedControl/index.tsx +86 -121
- package/src/components/SegmentedControl/styles.ts +15 -22
- package/src/components/SegmentedControl/types.ts +31 -0
- package/src/components/Select/index.tsx +71 -82
- package/src/components/Select/styles.ts +3 -5
- package/src/components/Select/types.ts +20 -25
- package/src/components/Slider/index.tsx +58 -43
- package/src/components/Slider/styles.ts +15 -6
- package/src/components/Slider/types.ts +9 -14
- package/src/components/Switch/index.tsx +43 -56
- package/src/components/Switch/styles.ts +1 -7
- package/src/components/Switch/types.ts +12 -0
- package/src/components/Text/index.tsx +56 -52
- package/src/components/Text/styles.ts +1 -7
- package/src/components/Text/types.ts +18 -0
- package/src/components/TextInput/index.tsx +49 -162
- package/src/components/TextInput/styles.ts +2 -8
- package/src/components/TextInput/types.ts +23 -0
- package/src/components/Touchable/index.tsx +44 -87
- package/src/components/Touchable/styles.ts +0 -9
- package/src/components/Touchable/types.ts +27 -0
- package/src/components/View/index.tsx +23 -92
- package/src/components/View/styles.ts +0 -6
- package/src/components/View/types.ts +13 -0
- package/src/components/components.ts +2 -6
- package/src/hooks/index.ts +13 -0
- package/src/index.ts +2 -0
- package/src/modules/PressableRipple/type.ts +1 -0
- package/src/utils/KeyboardAware/context.tsx +0 -2
- package/src/utils/KeyboardAware/keyboardHooks.ts +1 -2
- package/src/utils/ModalManager/components.tsx +1 -30
- package/src/utils/ModalManager/context.tsx +4 -4
- package/src/utils/ModalManager/index.ts +1 -4
- package/src/utils/hooks.ts +12 -1
- package/src/components/Calendar/style.ts +0 -6
- package/src/components/ContentView/index.tsx +0 -63
- package/src/components/ContentView/styles.ts +0 -8
- package/src/components/Drawer/index.tsx +0 -28
- package/src/components/Drawer/styles.ts +0 -8
- package/src/components/FileInput/styles.ts +0 -8
- package/src/components/InputLabel/index.tsx +0 -38
- package/src/components/InputLabel/styles.ts +0 -7
- package/src/components/List/PaginationIndicator.tsx +0 -54
- package/src/components/defaultStyles.ts +0 -77
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/mobile",
|
|
3
|
-
"version": "3.
|
|
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": "
|
|
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": "
|
|
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": "
|
|
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
|
}
|
package/src/Registry.ts
ADDED
|
@@ -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 {
|
|
4
|
-
import {
|
|
5
|
-
import { Badge
|
|
6
|
-
import { Icon
|
|
7
|
-
import { Touchable
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export
|
|
12
|
-
|
|
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 {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
50
|
-
|
|
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 {
|
|
2
|
+
import { TypeGuards, FormTypes, onMount, useSearch } from '@codeleap/common'
|
|
11
3
|
import { List } from '../List'
|
|
12
|
-
import { SearchInput } from '../
|
|
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
|
|
30
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
48
|
+
placeholder,
|
|
64
49
|
itemProps = {},
|
|
65
|
-
searchable
|
|
50
|
+
searchable,
|
|
66
51
|
loadOptions,
|
|
67
|
-
multiple
|
|
52
|
+
multiple,
|
|
68
53
|
limit = null,
|
|
69
54
|
defaultOptions = options,
|
|
70
55
|
onLoadOptionsError,
|
|
71
56
|
selectedIcon,
|
|
72
57
|
loadOptionsOnMount = defaultOptions.length === 0,
|
|
73
|
-
selectable
|
|
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
|
|
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
|
|
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
|
-
|
|
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={
|
|
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
|
|
196
|
+
<List
|
|
221
197
|
data={searchable ? filteredOptions : options}
|
|
222
198
|
scrollEnabled={false}
|
|
223
199
|
showsHorizontalScrollIndicator={false}
|
|
224
|
-
|
|
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
|
-
|
|
237
|
-
|
|
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
|
|
231
|
+
MobileStyleRegistry.registerComponent(Autocomplete)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ButtonComposition
|
|
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
|
|
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
|
-
|
|
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?:
|
|
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'|'
|
|
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
|
-
|